Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 4 additions & 11 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/python
{
Expand All @@ -9,17 +10,9 @@
// Features to add to the dev container. More info: https://containers.dev/features.
// "features": {},
"features": {
"ghcr.io/devcontainers/features/node:1": {
"nodeGypDependencies": true,
"installYarnUsingApt": true,
"version": "lts",
"pnpmVersion": "latest",
"nvmVersion": "latest"
},
"ghcr.io/devcontainer-community/devcontainer-features/astral.sh-uv:1": {
"shellautocompletion": true,
"version": "latest"
}
"ghcr.io/devcontainers/features/node:1": {},
"ghcr.io/devcontainer-community/devcontainer-features/astral.sh-uv:1": {},
"ghcr.io/braun-daniel/devcontainer-features/asciidoc:1": {}
//"ghcr.io/hspaans/devcontainer-features/pytest:2": {}
},
// Use 'forwardPorts' to make a list of ports inside the container available locally.
Expand Down
15 changes: 15 additions & 0 deletions .devcontainer/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,18 @@ services:
- ./mosquitto/log:/mosquitto/log
command: mosquitto -c /mosquitto/config/mosquitto.conf
restart: unless-stopped

fhem:
image: ghcr.io/fhem/fhem-minimal-docker:5-bookworm
container_name: fhem-dev-server
ports:
- '38083:8083' # Expose FHEM web interface on port 38083
environment:
- CONFIGTYPE=fhem_signalduino_example.cfg
- FHEM_PERM_DIR=0777
- FHEM_PERM_FILES=0777
volumes:
- ./fhem-data:/opt/fhem
depends_on:
- mqtt
restart: unless-stopped
86 changes: 86 additions & 0 deletions .devcontainer/fhem-data/fhem_signalduino_example.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
attr global userattr cmdIcon devStateIcon:textField-long devStateStyle icon sortby webCmd webCmdLabel:textField-long widgetOverride
attr global autosave 0
attr global logfile log/fhem-%Y-%m-%d.log
attr global modpath .
attr global nofork 0
attr global pidfilename log/fhem.pid
attr global statefile ./log/fhem.save
attr global updateInBackground 1
attr global verbose 3
# FHEM Configuration for PySignalduino Dev Environment
#
# This file is loaded by the FHEM container via CONFIGTYPE environment variable.


# 1. Define FHEMWEB instance to access FHEM via Browser (Port 8083)
define WEB FHEMWEB 8083 global
setuuid WEB 695e9c21-f33f-c986-956a-7e26fc9adfc69728
attr WEB editConfig 1
attr WEB stylesheetPrefix dark

# 2. Define Telnet for command line access (Optional)
#define telnetPort telnet 7072 global

# 3. Basic Event Handling
define eventTypes eventTypes ./log/eventTypes.txt
setuuid eventTypes 695e9c21-f33f-c986-9ac3-190c47641a98acb9

# 4. Define the MQTT Client (Broker Connection)
# 'mqtt' is the hostname of the broker service in docker-compose.yml
define mqtt_broker MQTT2_CLIENT mqtt:1883
setuuid mqtt_broker 695e9c21-f33f-c986-e617-d7301881c4685bc6
attr mqtt_broker autocreate simple

# 5. Define the SignalDuino MQTT Device
define PySignalDuino MQTT2_DEVICE
setuuid PySignalDuino 695e9c21-f33f-c986-4f81-a9f0ab37b6bcedf8
attr PySignalDuino IODev mqtt_broker
attr PySignalDuino readingList signalduino/v1/state/messages:.* { json2nameValue($EVENT, 'MSG_',$JSONMAP) }\
signalduino/v1/responses:.* { json2nameValue($EVENT, 'RESP_') }\
signalduino/v1/errors:.* { json2nameValue($EVENT, 'ERR_') }
attr PySignalDuino setList raw:textField signalduino/v1/commands/set/raw $EVTPART1 \
cc1101_reg:textField signalduino/v1/commands/set/cc1101_reg $EVTPART1 \
# System GET commands (noArg) \
version:noArg signalduino/v1/commands/get/system/version \
freeram:noArg signalduino/v1/commands/get/system/freeram \
uptime:noArg signalduino/v1/commands/get/system/uptime \
# Decoder state commands \
decoder_state:noArg signalduino/v1/commands/get/config/decoder \
decoder_ms_enable:noArg signalduino/v1/commands/set/config/decoder_ms_enable \
decoder_ms_disable:noArg signalduino/v1/commands/set/config/decoder_ms_disable \
decoder_mu_enable:noArg signalduino/v1/commands/set/config/decoder_mu_enable \
decoder_mu_disable:noArg signalduino/v1/commands/set/config/decoder_mu_disable \
decoder_mc_enable:noArg signalduino/v1/commands/set/config/decoder_mc_enable \
decoder_mc_disable:noArg signalduino/v1/commands/set/config/decoder_mc_disable \
# CC1101 GET commands (noArg) \
cc_config:noArg signalduino/v1/commands/get/cc1101/config \
cc_patable_get:noArg signalduino/v1/commands/get/cc1101/patable \
cc_register:noArg signalduino/v1/commands/get/cc1101/register \
cc_freq_get:noArg signalduino/v1/commands/get/cc1101/frequency \
cc_bandwidth_get:noArg signalduino/v1/commands/get/cc1101/bandwidth \
cc_rampl_get:noArg signalduino/v1/commands/get/cc1101/rampl \
cc_sensitivity_get:noArg signalduino/v1/commands/get/cc1101/sensitivity \
cc_datarate_get:noArg signalduino/v1/commands/get/cc1101/datarate \
cc_settings_get:noArg signalduino/v1/commands/get/cc1101/settings \
cc_deviation_get:noArg signalduino/v1/commands/get/cc1101/deviation\
# CC1101 SET commands \
cc_frequency_set:textField signalduino/v1/commands/set/cc1101/frequency $EVTPART1 \
cc_rampl_set:select,24,27,30,33,36,38,40,42 signalduino/v1/commands/set/cc1101/rampl $EVTPART1 \
cc_sensitivity_set:select,4,8,12,16 signalduino/v1/commands/set/cc1101/sensitivity $EVTPART1 \
cc_patable_set:select,-30_dBm,-20_dBm,-15_dBm,-10_dBm,-5_dBm,0_dBm,5_dBm,7_dBm,10_dBm signalduino/v1/commands/set/cc1101/patable $EVTPART1 \
cc_bandwidth_set:textField signalduino/v1/commands/set/cc1101/bandwidth $EVTPART1 \
cc_datarate_set:textField signalduino/v1/commands/set/cc1101/datarate $EVTPART1 \
cc_deviation_set:textField signalduino/v1/commands/set/cc1101/deviation $EVTPART1 \
\
# Maintenance commands \
factory_reset:noArg signalduino/v1/commands/set/factory_reset
attr PySignalDuino stateFormat state
# Map JSON payload to readings
# Define setter commands

# Logfile for SignalDuino
define FileLog_PySignalDuino FileLog ./log/PySignalDuino-%Y.log PySignalDuino
setuuid FileLog_PySignalDuino 695e9c21-f33f-c986-1981-abe9a5a366b3c989
attr FileLog_PySignalDuino logtype text
define Logfile FileLog /opt/fhem/log/fhem-%Y-%m-%d.log Logfile
setuuid Logfile 695e9c21-f33f-c986-cfda-4915c3e60c145721
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,7 @@ SIGNALDuino-Firmware/
.devcontainer/.devcontainer.env
.devcontainer/mosquitto/data/
.devcontainer/mosquitto/log/
.devcontainer/fhem-data/*
!.devcontainer/fhem-data/fhem_signalduino_example.cfg

.roo/mcp.json
38 changes: 36 additions & 2 deletions docs/01_user_guide/mqtt_api.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@ GET-Befehle benötigen eine leere Payload (`{}`) oder nur eine `req_id`.
| CC1101 PA-Tabelle.

| `get/cc1101/register`
| `{"register_value": "C00 = 29"}`
| Liest den Wert eines einzelnen CC1101-Registers (Adresse 0x00). Der Befehl nimmt keinen Wert in der Payload entgegen und liest standardmäßig Register 0x00.
| `{"register_name": "IOCFG2", "address_hex": "00", "register_value": "C00 = 29"}`
| Liest den Wert eines einzelnen CC1101-Registers. *Erfordert den Registernamen* im `value`-Feld der Payload (z.B. `{"value": "IOCFG2"}`).

| `get/cc1101/frequency`
| `{"frequency": 868.3500}`
Expand Down Expand Up @@ -303,3 +303,37 @@ Dieser Befehl sendet eine vorab encodierte Nachricht an das Signalduino-Gerät,
| Nein
| Optionale Frequenz in MHz (`F<val>`).
|===

[[_fhem_integration]]
== FHEM Integration

PySignalduino lässt sich nahtlos in FHEM integrieren, indem ein MQTT-Broker als Vermittler genutzt wird. Die empfohlene Methode ist die Verwendung des FHEM-Moduls `MQTT2_CLIENT` zur Verbindung mit dem Broker und `MQTT2_DEVICE` zur Repräsentation des Signalduino.

=== Beispielkonfiguration

Eine vollständige Beispielkonfiguration finden Sie in der Datei `.devcontainer/fhem-data/fhem_signalduino_example.cfg`. Im DevContainer wird diese Datei automatisch als FHEM-Konfiguration geladen, sodass `PySignalDuino` sofort verfügbar ist.

[source,fhem]
----
# 1. Verbindung zum Broker herstellen (falls noch nicht vorhanden)
define mqtt_broker MQTT2_CLIENT mqtt:1883
attr mqtt_broker autocreate simple

# 2. PySignalduino Device definieren
define PySignalDuino MQTT2_DEVICE
attr PySignalDuino IODev mqtt_broker

# 3. Readings für empfangene Nachrichten extrahieren
# Wandelt JSON-Payload automatisch in Readings um
attr PySignalDuino readingList signalduino/v1/state/messages:.* { json2nameValue($EVENT, '', $JSONMAP) }

# 4. Senden von Befehlen ermöglichen
attr PySignalDuino setList raw:textField signalduino/v1/commands/set/raw $EVTPART1 \
cc1101_reg:textField signalduino/v1/commands/set/cc1101_reg $EVTPART1 \
version:noArg signalduino/v1/commands/get/system/version
----

=== Wichtige Hinweise

* **Topics:** Stellen Sie sicher, dass das `readingList` Attribut dem in PySignalduino konfigurierten `MQTT_TOPIC` entspricht (Standard: `signalduino/v1/state/messages`).
* **JSON Parsing:** Die Funktion `json2nameValue` in FHEM ist ideal, um die flachen JSON-Objekte von PySignalduino direkt in FHEM Readings umzuwandeln.
Loading
Loading