Skip to content

Commit f7110b4

Browse files
authored
Merge pull request #12 from RFD-FHEM/feat/devWithFhem
Feature: Devcontainer now have a running fhem instance on port 38083
2 parents 188de18 + 87ddadb commit f7110b4

File tree

9 files changed

+595
-24
lines changed

9 files changed

+595
-24
lines changed

.devcontainer/devcontainer.json

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
23
// README at: https://github.com/devcontainers/templates/tree/main/src/python
34
{
@@ -9,17 +10,9 @@
910
// Features to add to the dev container. More info: https://containers.dev/features.
1011
// "features": {},
1112
"features": {
12-
"ghcr.io/devcontainers/features/node:1": {
13-
"nodeGypDependencies": true,
14-
"installYarnUsingApt": true,
15-
"version": "lts",
16-
"pnpmVersion": "latest",
17-
"nvmVersion": "latest"
18-
},
19-
"ghcr.io/devcontainer-community/devcontainer-features/astral.sh-uv:1": {
20-
"shellautocompletion": true,
21-
"version": "latest"
22-
}
13+
"ghcr.io/devcontainers/features/node:1": {},
14+
"ghcr.io/devcontainer-community/devcontainer-features/astral.sh-uv:1": {},
15+
"ghcr.io/braun-daniel/devcontainer-features/asciidoc:1": {}
2316
//"ghcr.io/hspaans/devcontainer-features/pytest:2": {}
2417
},
2518
// Use 'forwardPorts' to make a list of ports inside the container available locally.

.devcontainer/docker-compose.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,18 @@ services:
2929
- ./mosquitto/log:/mosquitto/log
3030
command: mosquitto -c /mosquitto/config/mosquitto.conf
3131
restart: unless-stopped
32+
33+
fhem:
34+
image: ghcr.io/fhem/fhem-minimal-docker:5-bookworm
35+
container_name: fhem-dev-server
36+
ports:
37+
- '38083:8083' # Expose FHEM web interface on port 38083
38+
environment:
39+
- CONFIGTYPE=fhem_signalduino_example.cfg
40+
- FHEM_PERM_DIR=0777
41+
- FHEM_PERM_FILES=0777
42+
volumes:
43+
- ./fhem-data:/opt/fhem
44+
depends_on:
45+
- mqtt
46+
restart: unless-stopped
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
attr global userattr cmdIcon devStateIcon:textField-long devStateStyle icon sortby webCmd webCmdLabel:textField-long widgetOverride
2+
attr global autosave 0
3+
attr global logfile log/fhem-%Y-%m-%d.log
4+
attr global modpath .
5+
attr global nofork 0
6+
attr global pidfilename log/fhem.pid
7+
attr global statefile ./log/fhem.save
8+
attr global updateInBackground 1
9+
attr global verbose 3
10+
# FHEM Configuration for PySignalduino Dev Environment
11+
#
12+
# This file is loaded by the FHEM container via CONFIGTYPE environment variable.
13+
14+
15+
# 1. Define FHEMWEB instance to access FHEM via Browser (Port 8083)
16+
define WEB FHEMWEB 8083 global
17+
setuuid WEB 695e9c21-f33f-c986-956a-7e26fc9adfc69728
18+
attr WEB editConfig 1
19+
attr WEB stylesheetPrefix dark
20+
21+
# 2. Define Telnet for command line access (Optional)
22+
#define telnetPort telnet 7072 global
23+
24+
# 3. Basic Event Handling
25+
define eventTypes eventTypes ./log/eventTypes.txt
26+
setuuid eventTypes 695e9c21-f33f-c986-9ac3-190c47641a98acb9
27+
28+
# 4. Define the MQTT Client (Broker Connection)
29+
# 'mqtt' is the hostname of the broker service in docker-compose.yml
30+
define mqtt_broker MQTT2_CLIENT mqtt:1883
31+
setuuid mqtt_broker 695e9c21-f33f-c986-e617-d7301881c4685bc6
32+
attr mqtt_broker autocreate simple
33+
34+
# 5. Define the SignalDuino MQTT Device
35+
define PySignalDuino MQTT2_DEVICE
36+
setuuid PySignalDuino 695e9c21-f33f-c986-4f81-a9f0ab37b6bcedf8
37+
attr PySignalDuino IODev mqtt_broker
38+
attr PySignalDuino readingList signalduino/v1/state/messages:.* { json2nameValue($EVENT, 'MSG_',$JSONMAP) }\
39+
signalduino/v1/responses:.* { json2nameValue($EVENT, 'RESP_') }\
40+
signalduino/v1/errors:.* { json2nameValue($EVENT, 'ERR_') }
41+
attr PySignalDuino setList raw:textField signalduino/v1/commands/set/raw $EVTPART1 \
42+
cc1101_reg:textField signalduino/v1/commands/set/cc1101_reg $EVTPART1 \
43+
# System GET commands (noArg) \
44+
version:noArg signalduino/v1/commands/get/system/version \
45+
freeram:noArg signalduino/v1/commands/get/system/freeram \
46+
uptime:noArg signalduino/v1/commands/get/system/uptime \
47+
# Decoder state commands \
48+
decoder_state:noArg signalduino/v1/commands/get/config/decoder \
49+
decoder_ms_enable:noArg signalduino/v1/commands/set/config/decoder_ms_enable \
50+
decoder_ms_disable:noArg signalduino/v1/commands/set/config/decoder_ms_disable \
51+
decoder_mu_enable:noArg signalduino/v1/commands/set/config/decoder_mu_enable \
52+
decoder_mu_disable:noArg signalduino/v1/commands/set/config/decoder_mu_disable \
53+
decoder_mc_enable:noArg signalduino/v1/commands/set/config/decoder_mc_enable \
54+
decoder_mc_disable:noArg signalduino/v1/commands/set/config/decoder_mc_disable \
55+
# CC1101 GET commands (noArg) \
56+
cc_config:noArg signalduino/v1/commands/get/cc1101/config \
57+
cc_patable_get:noArg signalduino/v1/commands/get/cc1101/patable \
58+
cc_register:noArg signalduino/v1/commands/get/cc1101/register \
59+
cc_freq_get:noArg signalduino/v1/commands/get/cc1101/frequency \
60+
cc_bandwidth_get:noArg signalduino/v1/commands/get/cc1101/bandwidth \
61+
cc_rampl_get:noArg signalduino/v1/commands/get/cc1101/rampl \
62+
cc_sensitivity_get:noArg signalduino/v1/commands/get/cc1101/sensitivity \
63+
cc_datarate_get:noArg signalduino/v1/commands/get/cc1101/datarate \
64+
cc_settings_get:noArg signalduino/v1/commands/get/cc1101/settings \
65+
cc_deviation_get:noArg signalduino/v1/commands/get/cc1101/deviation\
66+
# CC1101 SET commands \
67+
cc_frequency_set:textField signalduino/v1/commands/set/cc1101/frequency $EVTPART1 \
68+
cc_rampl_set:select,24,27,30,33,36,38,40,42 signalduino/v1/commands/set/cc1101/rampl $EVTPART1 \
69+
cc_sensitivity_set:select,4,8,12,16 signalduino/v1/commands/set/cc1101/sensitivity $EVTPART1 \
70+
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 \
71+
cc_bandwidth_set:textField signalduino/v1/commands/set/cc1101/bandwidth $EVTPART1 \
72+
cc_datarate_set:textField signalduino/v1/commands/set/cc1101/datarate $EVTPART1 \
73+
cc_deviation_set:textField signalduino/v1/commands/set/cc1101/deviation $EVTPART1 \
74+
\
75+
# Maintenance commands \
76+
factory_reset:noArg signalduino/v1/commands/set/factory_reset
77+
attr PySignalDuino stateFormat state
78+
# Map JSON payload to readings
79+
# Define setter commands
80+
81+
# Logfile for SignalDuino
82+
define FileLog_PySignalDuino FileLog ./log/PySignalDuino-%Y.log PySignalDuino
83+
setuuid FileLog_PySignalDuino 695e9c21-f33f-c986-1981-abe9a5a366b3c989
84+
attr FileLog_PySignalDuino logtype text
85+
define Logfile FileLog /opt/fhem/log/fhem-%Y-%m-%d.log Logfile
86+
setuuid Logfile 695e9c21-f33f-c986-cfda-4915c3e60c145721

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,7 @@ SIGNALDuino-Firmware/
88
.devcontainer/.devcontainer.env
99
.devcontainer/mosquitto/data/
1010
.devcontainer/mosquitto/log/
11+
.devcontainer/fhem-data/*
12+
!.devcontainer/fhem-data/fhem_signalduino_example.cfg
13+
1114
.roo/mcp.json

docs/01_user_guide/mqtt_api.adoc

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,8 @@ GET-Befehle benötigen eine leere Payload (`{}`) oder nur eine `req_id`.
140140
| CC1101 PA-Tabelle.
141141

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

146146
| `get/cc1101/frequency`
147147
| `{"frequency": 868.3500}`
@@ -303,3 +303,37 @@ Dieser Befehl sendet eine vorab encodierte Nachricht an das Signalduino-Gerät,
303303
| Nein
304304
| Optionale Frequenz in MHz (`F<val>`).
305305
|===
306+
307+
[[_fhem_integration]]
308+
== FHEM Integration
309+
310+
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.
311+
312+
=== Beispielkonfiguration
313+
314+
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.
315+
316+
[source,fhem]
317+
----
318+
# 1. Verbindung zum Broker herstellen (falls noch nicht vorhanden)
319+
define mqtt_broker MQTT2_CLIENT mqtt:1883
320+
attr mqtt_broker autocreate simple
321+
322+
# 2. PySignalduino Device definieren
323+
define PySignalDuino MQTT2_DEVICE
324+
attr PySignalDuino IODev mqtt_broker
325+
326+
# 3. Readings für empfangene Nachrichten extrahieren
327+
# Wandelt JSON-Payload automatisch in Readings um
328+
attr PySignalDuino readingList signalduino/v1/state/messages:.* { json2nameValue($EVENT, '', $JSONMAP) }
329+
330+
# 4. Senden von Befehlen ermöglichen
331+
attr PySignalDuino setList raw:textField signalduino/v1/commands/set/raw $EVTPART1 \
332+
cc1101_reg:textField signalduino/v1/commands/set/cc1101_reg $EVTPART1 \
333+
version:noArg signalduino/v1/commands/get/system/version
334+
----
335+
336+
=== Wichtige Hinweise
337+
338+
* **Topics:** Stellen Sie sicher, dass das `readingList` Attribut dem in PySignalduino konfigurierten `MQTT_TOPIC` entspricht (Standard: `signalduino/v1/state/messages`).
339+
* **JSON Parsing:** Die Funktion `json2nameValue` in FHEM ist ideal, um die flachen JSON-Objekte von PySignalduino direkt in FHEM Readings umzuwandeln.

0 commit comments

Comments
 (0)