2015-06-13 22:05:41 +02:00
|
|
|
'''
|
|
|
|
Created on 20.05.2015
|
|
|
|
|
|
|
|
@author: wn
|
|
|
|
'''
|
|
|
|
|
|
|
|
import paho.mqtt.client as mqtt
|
|
|
|
import json
|
|
|
|
import pymongo
|
|
|
|
import datetime
|
|
|
|
import sys
|
|
|
|
import MeterbusLib
|
|
|
|
|
|
|
|
devices = []
|
|
|
|
device_dishwasher_electric = MeterbusLib.Device(0x53, "Dishwasher", ["Energy total", "Energy partial", "Voltage", "Current", "Power", "img. Power"])
|
|
|
|
devices.append(device_dishwasher_electric)
|
|
|
|
device_laundry_electric = MeterbusLib.Device(82, "Laundry", ["Energy total", "Energy partial", "Voltage", "Current", "Power", "img. Power"])
|
|
|
|
devices.append(device_laundry_electric)
|
|
|
|
device_dryer_electric = MeterbusLib.Device(81, "Dryer", ["Energy total", "Energy partial", "Voltage", "Current", "Power", "img. Power"])
|
|
|
|
devices.append(device_dryer_electric)
|
|
|
|
device_light_electric = MeterbusLib.Device(84, "Light", ["Energy total", "Energy partial", "Voltage", "Current", "Power", "img. Power"])
|
|
|
|
devices.append(device_light_electric)
|
|
|
|
device_3phase_electric = MeterbusLib.Device(0x50, "3 Phase Electric", ["Energy T1 total", "Energy T1 partial", "Energy T2 total", "Energy T2 partial",
|
|
|
|
"Voltage phase 1", "Current phase 1", "Power phase 1", "img. Power phase 1",
|
|
|
|
"Voltage phase 2", "Current phase 2", "Power phase 2", "img. Power phase 2",
|
|
|
|
"Voltage phase 3", "Current phase 3", "Power phase 3", "img. Power phase 3",
|
|
|
|
"converter ratio", "Power total", "img. Power total", "tariff"
|
|
|
|
])
|
|
|
|
devices.append(device_3phase_electric)
|
|
|
|
device_thermometer = MeterbusLib.Device(0x21, "Thermometer", ["Uptime Seconds", "Uptime Minutes", "Uptime Hours", "Uptime Days",
|
|
|
|
"Temperature 1", "Temperature 2", "Temperature 3", "Temperature 4",
|
|
|
|
"rawdata"
|
|
|
|
])
|
|
|
|
devices.append(device_thermometer)
|
|
|
|
|
|
|
|
|
|
|
|
def on_message(client, userdata, msg):
|
|
|
|
j = json.loads(msg.payload)
|
|
|
|
# print(json.dumps(j, indent=2, separators=(',',':')))
|
|
|
|
mbusPayload = j['data']['telegram']
|
|
|
|
if mbusPayload[-1] == ' ':
|
2015-06-15 22:28:31 +02:00
|
|
|
mbusPayload2 = mbusPayload[:-1]
|
2015-06-13 22:05:41 +02:00
|
|
|
else:
|
2015-06-15 22:28:31 +02:00
|
|
|
mbusPayload2 = mbusPayload
|
2015-06-13 22:05:41 +02:00
|
|
|
print("<" + mbusPayload2 + ">")
|
|
|
|
telegram = MeterbusLib.Telegram(devices)
|
|
|
|
telegram.fromHexString(mbusPayload2)
|
|
|
|
telegram.parse()
|
|
|
|
print(json.dumps(telegram.getJSON(), indent=2))
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
print("Starting client ...")
|
|
|
|
|
|
|
|
client = mqtt.Client()
|
|
|
|
client.on_message = on_message
|
|
|
|
client.connect("mqttbroker", 1883, 60)
|
|
|
|
client.subscribe("IoT/Measurement/MeterbusHub")
|
|
|
|
|
|
|
|
client.loop_forever()
|
|
|
|
|