Skip to content

Commit

Permalink
New Module for MQTT at PV2 (snaptec#1544)
Browse files Browse the repository at this point in the history
* New Module for MQTT at PV2

New Module Config for MQTT on PV2.
  • Loading branch information
DetMoerk authored Sep 2, 2021
1 parent ead180a commit b6c5d01
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 1 deletion.
15 changes: 15 additions & 0 deletions modules/wr2_mqtt/main.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash
OPENWBBASEDIR=$(cd `dirname $0`/../../ && pwd)
RAMDISKDIR="${OPENWBBASEDIR}/ramdisk"
MODULEDIR=$(cd `dirname $0` && pwd)
DMOD="PV"
Debug=$debug


pvwatt=$(<${RAMDISKDIR}/pvwatt2)
echo $pvwatt
openwbDebugLog ${DMOD} 1 "PV2Watt: ${pvwatt}"

pvkwh=$(<${RAMDISKDIR}/pv2kwh)
openwbDebugLog ${DMOD} 1 "PV2kWh: ${pvkwh}"
openwbModulePublishState "PV" 0 "Kein Fehler" 1
8 changes: 7 additions & 1 deletion modules/wr_mqtt/main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,14 @@
OPENWBBASEDIR=$(cd `dirname $0`/../../ && pwd)
RAMDISKDIR="$OPENWBBASEDIR/ramdisk"
MODULEDIR=$(cd `dirname $0` && pwd)
DMOD="PV"
Debug=$debug

pvwatt=$(<$RAMDISKDIR/pvwatt)
pvwatt=$(<${RAMDISKDIR}/pvwatt)
echo $pvwatt
openwbDebugLog ${DMOD} 1 "PVWatt: ${pvwatt}"

pvkwh=$(<${RAMDISKDIR}/pvkwh)
openwbDebugLog ${DMOD} 1 "PVkWh: ${pvkwh}"

openwbModulePublishState "PV" 0 "Kein Fehler" 1
14 changes: 14 additions & 0 deletions runs/mqttsub.py
Original file line number Diff line number Diff line change
Expand Up @@ -1273,6 +1273,20 @@ def on_message(client, userdata, msg):
f = open('/var/www/html/openWB/ramdisk/pvwatt', 'w')
f.write(str(pvwatt))
f.close()
if (msg.topic == "openWB/set/pv/2/WhCounter"):
if (float(msg.payload) >= 0 and float(msg.payload) <= 10000000000):
f = open('/var/www/html/openWB/ramdisk/pv2kwh', 'w')
f.write(msg.payload.decode("utf-8"))
f.close()
if (msg.topic == "openWB/set/pv/2/W"):
if (float(msg.payload) >= -10000000 and float(msg.payload) <= 100000000):
if (float(msg.payload) > 1):
pvwatt=int(float(msg.payload.decode("utf-8"))) * -1
else:
pvwatt=int(float(msg.payload.decode("utf-8")))
f = open('/var/www/html/openWB/ramdisk/pv2watt', 'w')
f.write(str(pvwatt))
f.close()
if (msg.topic == "openWB/set/lp/1/AutolockStatus"):
if (int(msg.payload) >= 0 and int(msg.payload) <=3):
f = open('/var/www/html/openWB/ramdisk/autolockstatuslp1', 'w')
Expand Down
13 changes: 13 additions & 0 deletions web/settings/modulconfigpv.php
Original file line number Diff line number Diff line change
Expand Up @@ -966,6 +966,7 @@ function display_pvwattmodul() {
</optgroup>
<optgroup label="generische Module">
<option <?php if($pv2wattmodulold == "wr2_json") echo "selected" ?> value="wr2_json">Json Abfrage</option>
<option <?php if($pv2wattmodulold == "wr2_mqtt") echo "selected" ?> value="wr2_mqtt">MQTT</option>
<option <?php if($pv2wattmodulold == "wr2_ethsdm120") echo "selected" ?> value="wr2_ethsdm120">SDM120 an Netzwerk Modbus Adapter</option>
</optgroup>
</select>
Expand Down Expand Up @@ -1061,6 +1062,14 @@ function display_pvwattmodul() {
</div>
</div>
</div>
<div id="pv2mqttdiv" class="hide">
<div class="alert alert-info">
Keine Konfiguration erforderlich.<br>
Per MQTT zu schreiben:<br>
<span class="text-info">openWB/set/pv/2/W</span> PV-Leistung in Watt, int, negativ<br>
<span class="text-info">openWB/set/pv/2/WhCounter</span> Erzeugte Energie in Wh, float, nur positiv
</div>
</div>
<div id="pv2piko2" class="hide">
<div class="form-row mb-1">
<label for="wr2_piko2_user" class="col-md-4 col-form-label">Benutzername</label>
Expand Down Expand Up @@ -1102,6 +1111,7 @@ function display_pv2wattmodul() {
hideSection('#pv2id2div');
hideSection('#pv2kitdiv');
hideSection('#pv2wrjsondiv');
hideSection('#pv2mqttdiv');
hideSection('#pv2piko2');
hideSection('#pv2solarlogdiv');

Expand All @@ -1111,6 +1121,9 @@ function display_pv2wattmodul() {
if($('#pv2wattmodul').val() == 'wr2_json') {
showSection('#pv2wrjsondiv');
}
if($('#pv2wattmodul').val() == 'wr2_mqtt') {
showSection('#pv2mqttdiv');
}
if($('#pv2wattmodul').val() == 'wr2_ethlovatoaevu') {
showSection('#pv2kitdiv');
}
Expand Down

0 comments on commit b6c5d01

Please sign in to comment.