You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
2.6 KiB
2.6 KiB
pySonnerie Backend
Backend Python avec API REST HTTPS authentifiee pour piloter la lecture audio a partir de triggers serie (ESP32).
Fonctions implementees
- API REST securisee par authentification HTTP Basic
- HTTPS avec generation auto d'un certificat autosigne si absent
- Gestion des triggers via
data/conf.json - Lecture audio par trigger serie (
GPIOX) ou via API de forgage manuel - Arret de la sortie audio via API
Arborescence
backend/
app/
data/
conf.json
musiques/
certs/ # cree au premier lancement
run.py
requirements.txt
Prerequis
- Python 3.11+
ffplayinstalle (paquet ffmpeg)- acces au port serie (exemple:
/dev/ttyUSB0)
Installation
cd backend
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
Si présence d'un proxy, la dernière commande sera pip install -r requirements.txt --proxy http://proxy:port.
Configuration
Le fichier data/conf.json contient:
server.host,server.port,server.tls_cert,server.tls_keyauth.username,auth.passwordserial.enabled,serial.port,serial.baudrate,serial.timeouttriggers
Exemple d'entree trigger:
"GPIO23": {
"name": "Bouton entree",
"type": "GPIO23",
"music_file": "bell.mp3",
"start_seconds": 2.5,
"end_seconds": 10.0
}
Lancement
cd backend
source .venv/bin/activate
python run.py
API dispo sur https://<host>:<port>.
Endpoints REST
Tous sauf /api/health exigent auth Basic.
GET /api/healthGET /api/configGET /api/triggersPUT /api/triggers/{trigger_id}PATCH /api/triggers/{trigger_id}DELETE /api/triggers/{trigger_id}GET /api/play/{trigger_id}GET /api/stop
Exemples cURL
curl -k -u admin:change-me https://127.0.0.1:8443/api/triggers
curl -k -u admin:change-me \
-H "Content-Type: application/json" \
-X PUT https://127.0.0.1:8443/api/triggers/GPIO23 \
-d '{
"name": "Bouton entree",
"type": "GPIO23",
"music_file": "bell.mp3",
"start_seconds": 0,
"end_seconds": null
}'
curl -k -u admin:change-me \
https://127.0.0.1:8443/api/play/GPIO23
curl -k -u admin:change-me https://127.0.0.1:8443/api/stop
Service Debian
Le fichier systemd/pysonnerie-backend.service est fourni comme base.
sudo cp backend/systemd/pysonnerie-backend.service /etc/systemd/system/
sudo systemctl daemon-reload
sudo systemctl enable --now pysonnerie-backend
Adapte les chemins WorkingDirectory et ExecStart avant activation.