RaspberryAPI e' una piattaforma REST generica in Python (FastAPI) da esporre su Raspberry Pi, con documentazione Swagger UI. L'obiettivo e' avere un singolo servizio API modulare: HevyBot e' solo un modulo, non il focus esclusivo del progetto.
GET /runtime/likes-count-> contenuto di/home/pi/HevyBot/runtime/likes_count.txtGET /runtime/hevybot-out-> contenuto di/home/pi/HevyBot/runtime/hevybot.outPOST /hevybot/stop-> eseguestop_hevybot.she restituisce output consolePOST /hevybot/start-> eseguestart_hevybot.shcon argomenti dal body e restituisce output console
GET /system/metrics-> metriche live Raspberry Pi:- percentuale CPU utilizzata
- percentuale RAM utilizzata
- percentuale disco utilizzata, spazio libero e totale
- temperatura CPU (quando disponibile)
- uptime, load average, frequenza CPU, indirizzi IPv4
Swagger UI:
http://<IP_RASPBERRY>:8000/docs
OpenAPI JSON:
http://<IP_RASPBERRY>:8000/openapi.json
- Aggiungi nuovi endpoint senza legarli a HevyBot.
- Raggruppa gli endpoint con un tag OpenAPI dedicato (es.
Camera,GPIO,Network,Storage). - Usa path coerenti per modulo (es.
/camera/...,/gpio/...,/network/...). - Mantieni documentazione Swagger aggiornata con summary e descrizioni chiare.
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
uvicorn app.main:app --host 0.0.0.0 --port 8000- Copia il repository in
/home/pi/RaspberryAPI - Crea e popola il virtualenv come nella sezione precedente
- Installa il servizio:
sudo cp deploy/raspberryapi.service /etc/systemd/system/raspberryapi.service
sudo systemctl daemon-reload
sudo systemctl enable raspberryapi.service
sudo systemctl start raspberryapi.serviceComandi utili:
sudo systemctl status raspberryapi.service
sudo journalctl -u raspberryapi.service -fcurl http://127.0.0.1:8000/runtime/likes-count
curl http://127.0.0.1:8000/runtime/hevybot-out
curl http://127.0.0.1:8000/system/metrics
curl -X POST http://127.0.0.1:8000/hevybot/stop
curl -X POST http://127.0.0.1:8000/hevybot/start \
-H "Content-Type: application/json" \
-d '{"fast-mode":true,"execution-time-minutes":180,"pause-time-minutes":60,"min-delay":1,"max-delay":3,"max-likes":20000,"long-pause-every-min-likes":8,"long-pause-every-max-likes":14,"long-pause-min-seconds":30,"long-pause-max-seconds":90}'- Gli endpoint sono
POSTperche' eseguono azioni con side-effect (avvio/arresto processo). POST /hevybot/startaccetta un body JSON key/value e lo converte in argomenti CLI.- Esempio completo:
{"fast-mode":true,"execution-time-minutes":180,"pause-time-minutes":60,"min-delay":1,"max-delay":3,"max-likes":20000,"long-pause-every-min-likes":8,"long-pause-every-max-likes":14,"long-pause-min-seconds":30,"long-pause-max-seconds":90}. - In Swagger (
/docs) trovi template tipizzato con campi noti:fast-mode,execution-time-minutes,pause-time-minutes,min-delay,max-delay,max-likes,long-pause-every-min-likes,long-pause-every-max-likes,long-pause-min-seconds,long-pause-max-seconds,args. - Supportato anche il formato legacy
{"args":["--flag","value"]}. - Risposta per entrambi:
exit_code,success,stdout,stderr,combined_output,command. - Se uno script resta bloccato, l'API interrompe l'attesa dopo
SCRIPT_TIMEOUT_SECONDS(default25) e ritornatimed_out: truecon output parziale. - La risposta include
debugcon probe shell (shell_probe_*), utente effettivo (effective_uid/gid), path script e PATH ambiente per troubleshooting.