1
Fork 0
mirror of https://github.com/RGBCube/GDUS synced 2025-07-28 05:27:45 +00:00

Return OK

This commit is contained in:
RGBCube 2023-12-20 12:33:21 +03:00
parent 60c3201ddf
commit be1bb01bdf
No known key found for this signature in database
5 changed files with 44 additions and 21 deletions

2
.gitignore vendored
View file

@ -10,10 +10,10 @@
!server/.rustfmt.toml
!server/Cargo.lock
!server/Cargo.toml
!.gitignore
!*.md
!*.py
!*.rs
!*.toml

29
rpid/main.py Normal file
View file

@ -0,0 +1,29 @@
import os
from fastapi import FastAPI
from RPi import GPIO as gpio
LED_PIN = 17
led_state = False
gipo.setmode(gpio.BCM)
gpio.output(LED_PIN, int(led_state))
app = FastAPI()
@app.get("/led/toggle")
async def toggle() -> str:
led_state = not led_state
gpio.output(LED_PIN, int(led_state))
return f"TOGGLE OK, NEW STATE: {'ON' if not led_state else 'OFF'}"
@app.get("/speak")
async def speak(text: str) -> str:
ret = os.system(f'text2speech "{text}""')
return f"TEXT {'OK' if ret == 0 else 'FAIL'}, TEXT: {text}";
if __name__ == "__main__":
import uvicorn
uvicorn.run(app, host="localhost", port=3000)

12
rpid/pyproject.toml Normal file
View file

@ -0,0 +1,12 @@
[tool.poetry]
name = "rpid"
description = "Raspbery PI Daemon"
version = "0.0.1"
authors = [ "RGBCube" ]
[tool.poetry.dependencies]
python = "^3.8"
fastapi = "0.105.0"
"RPi.GPIO" = "0.7.1"
uvicorn = "0.24.0.post1"

View file

@ -1,19 +0,0 @@
from fastapi import FastAPI
from RPi import GPIO as gpio
LED_PIN = 17
gipo.setmode(gpio.BCM)
state = False
def set(state: bool) -> None:
gpio.output(LED, int(!state))
set(state)
app = FastAPI()
@app.get("/toggle")
async def toggle() -> None:
set(!state)

View file

@ -109,7 +109,8 @@ async fn view(data: Data<SqlitePool>) -> web::Result<Markup> {
const differenceSeconds = currentTime - reminder.timestamp;
if (differenceSeconds < 1 * 60) {
fetch("http://localhost:3000/toggle").then(console.log);
fetch("http://localhost:3000/toggle-led").then(console.log);
fetch("http://localhost:3000/speak?" + new URLSearchParams({ text: reminder.content })).then(console.log);
}
});
};