This repository has been archived by the owner on May 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit f81dcde
Showing
12 changed files
with
3,225 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
*.py[cod] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[submodule "velib_python"] | ||
path = ext/velib_python | ||
url = https://github.com/victronenergy/velib_python.git |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2014 mpvader | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
SOURCEDIR = $(PWD) | ||
SRC_PAHODIR = $(PWD)/paho | ||
SRC_PAHO_MQTT_DIR = $(PWD)/paho/mqtt | ||
VEDLIBDIR = $(PWD)/ext/velib_python | ||
INSTALL_CMD = install | ||
LIBDIR = $(bindir)/ext/velib_python | ||
PAHODIR = $(bindir)/paho | ||
PAHO_MQTT_DIR = $(bindir)/paho/mqtt | ||
|
||
FILES = \ | ||
$(SOURCEDIR)/dbus-mqtt.py | ||
|
||
PAHO_FILES = \ | ||
$(SRC_PAHODIR)/__init__.py | ||
|
||
PAHO_MQTT_FILES = \ | ||
$(SRC_PAHO_MQTT_DIR)/__init__.py \ | ||
$(SRC_PAHO_MQTT_DIR)/client.py \ | ||
$(SRC_PAHO_MQTT_DIR)/publish.py | ||
|
||
VEDLIB_FILES = \ | ||
$(VEDLIBDIR)/logger.py \ | ||
$(VEDLIBDIR)/ve_utils.py \ | ||
$(VEDLIBDIR)/vedbus.py | ||
|
||
help : | ||
@ echo "The following make targets are available" | ||
@ echo " help - print this message" | ||
@ echo " install - install everything" | ||
|
||
install_app : $(FILES) | ||
@if [ "$^" != "" ]; then \ | ||
$(INSTALL_CMD) -d $(DESTDIR)$(bindir); \ | ||
$(INSTALL_CMD) -t $(DESTDIR)$(bindir) $^; \ | ||
echo installed $(DESTDIR)$(bindir)/$(notdir $^); \ | ||
fi | ||
|
||
install_paho : $(PAHO_FILES) | ||
@if [ "$^" != "" ]; then \ | ||
$(INSTALL_CMD) -d $(DESTDIR)$(PAHODIR); \ | ||
$(INSTALL_CMD) -t $(DESTDIR)$(PAHODIR) $^; \ | ||
echo installed $(DESTDIR)$(PAHODIR)/$(notdir $^); \ | ||
fi | ||
|
||
install_paho_mqtt : $(PAHO_MQTT_FILES) | ||
@if [ "$^" != "" ]; then \ | ||
$(INSTALL_CMD) -d $(DESTDIR)$(PAHO_MQTT_DIR); \ | ||
$(INSTALL_CMD) -t $(DESTDIR)$(PAHO_MQTT_DIR) $^; \ | ||
echo installed $(DESTDIR)$(PAHO_MQTT_DIR)/$(notdir $^); \ | ||
fi | ||
|
||
install_velib_python: $(VEDLIB_FILES) | ||
@if [ "$^" != "" ]; then \ | ||
$(INSTALL_CMD) -d $(DESTDIR)$(LIBDIR); \ | ||
$(INSTALL_CMD) -t $(DESTDIR)$(LIBDIR) $^; \ | ||
echo installed $(DESTDIR)$(LIBDIR)/$(notdir $^); \ | ||
fi | ||
|
||
install: install_velib_python install_app install_paho install_paho_mqtt | ||
|
||
.PHONY: help install_app install_velib_python install install_paho install_paho_mqtt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
dbus-mqtt | ||
========= | ||
|
||
A python script that publishes values from the D-Bus to an MQTT broker. The script also supports requests | ||
from the MQTT broker to change values on the local D-Bus. This script only works with the D-Bus interface | ||
defined for use with the Color Control GX (CCGX). | ||
|
||
Set-up | ||
------ | ||
Right now, there is no MQTT broker running on the CCGX itself. There is a package for mosquitto, which is a | ||
popular MQTT broker. You can install it on the CCGX with: | ||
|
||
opkg install mosquitto | ||
|
||
The broker is not started automatically. You have to start it yourself with the command: | ||
|
||
mosquitto -c /etc/mosquitto/mosquitto.conf | ||
|
||
It is also possible to connect the a MQTT broker elsewhere using the command line options of the script. | ||
For example: | ||
|
||
dbus-mqtt.py --mqtt-server my.mqqt.server | ||
|
||
will connect to your favorite MQTT server, assuming it allows access without authentication. | ||
|
||
Notifications | ||
------------- | ||
|
||
When a value on the D-Bus changes, the script will send a message to the broker. | ||
The MQTT topic looks like this: | ||
|
||
N/<portal ID>/<service_type>/<device instance>/<D-Bus path> | ||
|
||
* Portal ID is the VRM portal ID associated with the CCGX. | ||
* service type is the part of the D-Bus service name that describes the service. | ||
* device instance is a number used to make all services of the same type unique (this value is published | ||
on the D-Bus as /DeviceInstance) | ||
|
||
The payload if the D-Bus value converted to json wrapped in a dictionary. The messages are retained by the | ||
broker, so if you subscribe to the broker you'll always get last message for each subscribed topic. | ||
|
||
Example: | ||
Suppose we have a PV inverter, which reports a total AC power of 936W. The topic of the MQTT message would be: | ||
|
||
Topic: N/e0ff50a097c0/pvinverter/20/Ac/Power | ||
Payload: {"value": 936} | ||
|
||
Write requests | ||
-------------- | ||
|
||
Write requests can be sent to change values on the D-Bus. The format looks like the notification. Instead of | ||
a N, the topic should start with a W. The payload format is identical. | ||
|
||
Example: | ||
On a Hub-4 system we can change the AC-In setpoint with this message: | ||
|
||
Topic: W/e0ff50a097c0/vebus/257/Hub4/L1/AcPowerSetpoint | ||
Payload: {"value": -200} | ||
|
||
The device instance (in this case 257) of a service usually depends on the communication port used the | ||
connect the device to the CCGX, so it is a good idea to check it before sending write requests. A nice way to | ||
do this is by subscribing to the broker using wildcards. | ||
For example: W/e0ff50a097c0/vebus/+/Hub4/L1/AcPowerSetpoint will get you the list of all registered | ||
Multis/Quattros (=vebus services) which have the /Hub4/L1/AcPowerSetpoint. You can pick the device instance | ||
from the topics in the list. | ||
|
||
Read requests | ||
------------- | ||
|
||
A read request will force the script to send a notification message with a specific D-Bus value. Again the | ||
topic is identical to the notification message itself, except that the first character is a 'R'. Wildcards | ||
in the topic are not supported. The payload will be ignored (it's best to keep it empty). | ||
|
||
Example: | ||
To retrieve the AC power of out favorite PV inverter we send: | ||
|
||
Topic: R/e0ff50a097c0/pvinverter/20/Ac/Power | ||
Payload: empty | ||
|
||
The script will reply with this message (make sure you subscribe to it): | ||
|
||
Topic: N/e0ff50a097c0/pvinverter/20/Ac/Power | ||
Payload: {"value": 926} | ||
|
||
Normally you do not need to use read requests, because most values are published automatically. There are | ||
some exception however. Most important are the settings (com.victronenergy.settings on the D-Bus). If you | ||
want to retrieve a setting you have to use a read request. |
Oops, something went wrong.