diff --git a/.gitignore b/.gitignore index b7a6d2a..181db24 100644 --- a/.gitignore +++ b/.gitignore @@ -10,10 +10,10 @@ !server/.rustfmt.toml !server/Cargo.lock -!server/Cargo.toml !.gitignore !*.md !*.py !*.rs +!*.toml diff --git a/rpid/main.py b/rpid/main.py new file mode 100644 index 0000000..5324fd9 --- /dev/null +++ b/rpid/main.py @@ -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) diff --git a/rpid/pyproject.toml b/rpid/pyproject.toml new file mode 100644 index 0000000..7b7bfc9 --- /dev/null +++ b/rpid/pyproject.toml @@ -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" diff --git a/rpid/rpid/main.py b/rpid/rpid/main.py deleted file mode 100644 index 7ac73d9..0000000 --- a/rpid/rpid/main.py +++ /dev/null @@ -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) diff --git a/server/src/view.rs b/server/src/view.rs index 3116460..01c6719 100644 --- a/server/src/view.rs +++ b/server/src/view.rs @@ -109,7 +109,8 @@ async fn view(data: Data) -> web::Result { 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); } }); };