-
Notifications
You must be signed in to change notification settings - Fork 14
Description
Now that mqtt output plugin is present and working very well, I missed a lot the possibility to send mqtt input to pyHPSU, also.
I implemented a simple MQTT Daemon.
By now it is an option of pyHPSU.py, --mqttdaemon, only this code file has been modified.
This is the excerpt from the mode section of the new README.md
4. MQTT Daemon mode
pyHPSU starts in daemon mode, it subscribe an MQTT topic and listen forever waiting for commands.
MQTT coordinates are specified through configuration file: the same property used by mqtt output plugin plus an additional COMMANDTOPIC.
The daemon subscribe to the topic
PREFIX / COMMANDTOPIC / +
e.g.
configuration file (e.g. /etc/pyHPSU/pyhpsu.conf)
...
[MQTT]
BROKER = 192.168.1.94
PREFIX = myhpsu
COMMANDTOPIC = command
...
root@rotex:# pyHPSU.py --mqttdaemon
user@anothersystem:# mosquitto_pub -h 192.168.1.94 -t "myhpsu/command/t_flow_day" -m 29
set the parameter t_flow_day to 29°C
Proposed code is on top of the branch with the revised log management (logrevision branch in segaura repo, testing in Spanni26 repo), this is the latest commit
Coding is not complete, --mqttdaemon can't live along other "command/output" options, like -a, -c, -o, ..., it has been tested alone only, so far.
Moreover, as with previous commits, I tried to stick with existing code setup, avoiding refactoring wherever possible: this is not ideal but I think it is the correct "first step".
Other changes included:
- code prevents writing to a readonly HPSU parameter and exit(9) while logging an error
- additional debug and info log lines has been added to code
NOTE: current implementation is dedicated to "write" commands, in the next commit I plan to enable "read" command (mqtt daemon publish) and also to enable automatic read after write (e.g. mqtt daemon receives a write command in the subscribed topic, executes it, read the changed value back from hpsu and publish it on mqtt)