|
1 | | -# SignalDuino MQTT Bridge |
| 1 | +# PySignalduino – Asynchrone MQTT-Bridge für SIGNALDuino |
2 | 2 |
|
3 | | -Dieses Projekt ist eine Python-Portierung der SIGNALDuino-Protokolle aus FHEM. |
4 | | -Es stellt die Protokolle als Dictionary bereit und bietet eine objektorientierte |
5 | | -Schnittstelle (`SDProtocols`). |
| 3 | +Dieses Projekt ist eine moderne Python-Implementierung der SIGNALDuino-Protokolle mit vollständiger **asyncio**-Unterstützung und integrierter **MQTT-Bridge**. Es ermöglicht die Kommunikation mit SIGNALDuino-Hardware (über serielle Schnittstelle oder TCP) und veröffentlicht empfangene Signale sowie empfängt Steuerbefehle über MQTT. |
6 | 4 |
|
7 | | -## Struktur |
8 | | -- `sd_protocols/` – Kernmodule |
9 | | -- `examples/` – Demo-Skripte |
10 | | -- `tests/` – Unit-Tests mit pytest |
| 5 | +## Hauptmerkmale |
| 6 | + |
| 7 | +* **Vollständig asynchron** – Basierend auf `asyncio` für hohe Performance und einfache Integration in asynchrone Anwendungen. |
| 8 | +* **MQTT-Integration** – Automatisches Publizieren dekodierter Nachrichten in konfigurierbare Topics und Empfang von Steuerbefehlen (z.B. `version`, `set`, `mqtt`). |
| 9 | +* **Unterstützte Transporte** – Serielle Verbindung (über `pyserial-asyncio`) und TCP-Verbindung. |
| 10 | +* **Umfangreiche Protokollbibliothek** – Portierung der originalen FHEM‑SIGNALDuino‑Protokolle mit `SDProtocols` und `SDProtocolData`. |
| 11 | +* **Konfiguration über Umgebungsvariablen** – Einfache Einrichtung ohne Codeänderungen. |
| 12 | +* **Ausführbares Hauptprogramm** – `main.py` bietet eine sofort einsatzbereite Lösung mit Logging, Signalbehandlung und Timeout‑Steuerung. |
| 13 | +* **Komprimierte Datenübertragung** – Effiziente Payload‑Kompression für MQTT‑Nachrichten. |
| 14 | + |
| 15 | +## Installation |
| 16 | + |
| 17 | +### Voraussetzungen |
| 18 | + |
| 19 | +* Python 3.8 oder höher |
| 20 | +* pip (Python-Paketmanager) |
| 21 | + |
| 22 | +### Paketinstallation |
| 23 | + |
| 24 | +1. Repository klonen: |
| 25 | + ```bash |
| 26 | + git clone https://github.com/.../PySignalduino.git |
| 27 | + cd PySignalduino |
| 28 | + ``` |
| 29 | + |
| 30 | +2. Abhängigkeiten installieren (empfohlen in einer virtuellen Umgebung): |
| 31 | + ```bash |
| 32 | + pip install -e . |
| 33 | + ``` |
| 34 | + |
| 35 | + Dies installiert das Paket im Entwicklermodus inklusive aller Runtime‑Abhängigkeiten: |
| 36 | + * `pyserial` |
| 37 | + * `pyserial-asyncio` |
| 38 | + * `aiomqtt` (asynchrone MQTT‑Client‑Bibliothek) |
| 39 | + * `python-dotenv` |
| 40 | + * `requests` |
| 41 | + |
| 42 | +3. Für Entwicklung und Tests zusätzlich: |
| 43 | + ```bash |
| 44 | + pip install -r requirements-dev.txt |
| 45 | + ``` |
| 46 | + |
| 47 | +## Schnellstart |
| 48 | + |
| 49 | +1. **Umgebungsvariablen setzen** (optional). Erstelle eine `.env`‑Datei im Projektverzeichnis: |
| 50 | + ```bash |
| 51 | + SIGNALDUINO_SERIAL_PORT=/dev/ttyUSB0 |
| 52 | + MQTT_HOST=localhost |
| 53 | + LOG_LEVEL=INFO |
| 54 | + ``` |
| 55 | + |
| 56 | +2. **Programm starten**: |
| 57 | + ```bash |
| 58 | + python3 main.py --serial /dev/ttyUSB0 --mqtt-host localhost |
| 59 | + ``` |
| 60 | + |
| 61 | + Oder nutze die Umgebungsvariablen: |
| 62 | + ```bash |
| 63 | + python3 main.py |
| 64 | + ``` |
| 65 | + |
| 66 | +3. **Ausgabe beobachten**. Das Programm verbindet sich mit dem SIGNALDuino, initialisiert die Protokolle und beginnt mit dem Empfang. Dekodierte Nachrichten werden im Log ausgegeben und – sofern MQTT konfiguriert ist – an den Broker gesendet. |
| 67 | + |
| 68 | +## Konfiguration |
| 69 | + |
| 70 | +### Umgebungsvariablen |
| 71 | + |
| 72 | +| Variable | Beschreibung | Beispiel | |
| 73 | +|----------|--------------|----------| |
| 74 | +| `SIGNALDUINO_SERIAL_PORT` | Serieller Port (z.B. `/dev/ttyUSB0`) | `/dev/ttyACM0` | |
| 75 | +| `SIGNALDUINO_BAUD` | Baudrate (Standard: `57600`) | `115200` | |
| 76 | +| `SIGNALDUINO_TCP_HOST` | TCP‑Host (alternativ zu Serial) | `192.168.1.10` | |
| 77 | +| `SIGNALDUINO_TCP_PORT` | TCP‑Port (Standard: `23`) | `23` | |
| 78 | +| `MQTT_HOST` | MQTT‑Broker‑Host | `mqtt.eclipseprojects.io` | |
| 79 | +| `MQTT_PORT` | MQTT‑Broker‑Port (Standard: `1883`) | `1883` | |
| 80 | +| `MQTT_USERNAME` | Benutzername für MQTT‑Authentifizierung | `user` | |
| 81 | +| `MQTT_PASSWORD` | Passwort für MQTT‑Authentifizierung | `pass` | |
| 82 | +| `MQTT_TOPIC` | Basis‑Topic für Publikation/Subscription | `signalduino/` | |
| 83 | +| `LOG_LEVEL` | Logging‑Level (DEBUG, INFO, WARNING, ERROR, CRITICAL) | `DEBUG` | |
| 84 | + |
| 85 | +### Kommandozeilenargumente |
| 86 | + |
| 87 | +Alle Umgebungsvariablen können auch als Argumente übergeben werden (sie haben Vorrang). Eine vollständige Liste erhält man mit: |
11 | 88 |
|
12 | | -## Tests ausführen |
13 | 89 | ```bash |
14 | | -pip install -r requirements.txt |
15 | | -pytest |
| 90 | +python3 main.py --help |
| 91 | +``` |
| 92 | + |
| 93 | +Wichtige Optionen: |
| 94 | +* `--serial PORT` – Serieller Port |
| 95 | +* `--tcp HOST` – TCP‑Host |
| 96 | +* `--mqtt-host HOST` – MQTT‑Broker |
| 97 | +* `--mqtt-topic TOPIC` – Basis‑Topic |
| 98 | +* `--timeout SECONDS` – Automatisches Beenden nach N Sekunden |
| 99 | +* `--log-level LEVEL` – Logging‑Level |
| 100 | + |
| 101 | +## MQTT‑Integration |
| 102 | + |
| 103 | +### Publizierte Topics |
| 104 | + |
| 105 | +* `{basis_topic}/decoded` – JSON‑Nachricht jedes dekodierten Signals. |
| 106 | +* `{basis_topic}/raw` – Rohdaten (falls aktiviert). |
| 107 | +* `{basis_topic}/status` – Statusmeldungen (Verbunden/Getrennt/Fehler). |
| 108 | + |
| 109 | +### Abonnierte Topics (Befehle) |
| 110 | + |
| 111 | +* `{basis_topic}/cmd/version` – Liefert die Firmware‑Version des SIGNALDuino. |
| 112 | +* `{basis_topic}/cmd/set` – Sendet einen `set`‑Befehl an den SIGNALDuino. |
| 113 | +* `{basis_topic}/cmd/mqtt` – Steuert die MQTT‑Integration (z.B. Kompression an/aus). |
| 114 | + |
| 115 | +Die genauen Payload‑Formate und weitere Befehle sind in der [Befehlsreferenz](docs/03_protocol_reference/commands.adoc) dokumentiert. |
| 116 | + |
| 117 | +## Projektstruktur |
| 118 | + |
| 119 | +``` |
| 120 | +PySignalduino/ |
| 121 | +├── signalduino/ # Hauptpaket |
| 122 | +│ ├── controller.py # Asynchroner Controller |
| 123 | +│ ├── mqtt.py # MQTT‑Publisher/Subscriber |
| 124 | +│ ├── transport.py # Serielle/TCP‑Transporte (asyncio) |
| 125 | +│ ├── commands.py # Befehlsimplementierung |
| 126 | +│ └── ... |
| 127 | +├── sd_protocols/ # Protokollbibliothek (SDProtocols) |
| 128 | +├── tests/ # Umfangreiche Testsuite |
| 129 | +├── docs/ # Dokumentation (AsciiDoc) |
| 130 | +├── main.py # Ausführbares Hauptprogramm |
| 131 | +├── pyproject.toml # Paketkonfiguration |
| 132 | +└── requirements*.txt # Abhängigkeiten |
| 133 | +``` |
| 134 | +
|
| 135 | +## Entwicklung |
| 136 | +
|
| 137 | +### Tests ausführen |
| 138 | +
|
| 139 | +```bash |
| 140 | +pytest |
| 141 | +``` |
| 142 | + |
| 143 | +Für Tests mit Coverage‑Bericht: |
| 144 | + |
| 145 | +```bash |
| 146 | +pytest --cov=signalduino --cov=sd_protocols |
| 147 | +``` |
| 148 | + |
| 149 | +### Beitragen |
| 150 | + |
| 151 | +Beiträge sind willkommen! Bitte erstelle einen Pull‑Request oder öffne ein Issue im Repository. |
| 152 | + |
| 153 | +## Dokumentation |
| 154 | + |
| 155 | +* [Installationsanleitung](docs/01_user_guide/installation.adoc) |
| 156 | +* [Benutzerhandbuch](docs/01_user_guide/usage.adoc) |
| 157 | +* [Asyncio‑Migrationsleitfaden](docs/ASYNCIO_MIGRATION.md) |
| 158 | +* [Protokollreferenz](docs/03_protocol_reference/protocol_details.adoc) |
| 159 | +* [Befehlsreferenz](docs/01_user_guide/usage.adoc#_command_interface) |
| 160 | + |
| 161 | +## Lizenz |
| 162 | + |
| 163 | +Dieses Projekt steht unter der MIT‑Lizenz – siehe [LICENSE](LICENSE) für Details. |
| 164 | + |
| 165 | +## Danksagung |
| 166 | + |
| 167 | +Basierend auf der originalen FHEM‑SIGNALDuino‑Implementierung von [@Sidey79](https://github.com/Sidey79) und der Community. |
0 commit comments