Commit eee5eaa2 authored by Peter-Bernd Otte's avatar Peter-Bernd Otte

Update enoceanReceiver.py

parent bca57057
......@@ -7,13 +7,15 @@ from datetime import datetime
import paho.mqtt.client as paho
import json
from crcTable import *
#import random #for tests sending it twice
broker="localhost"
clientName = "enocean-eg"
Const_USBPort = str(sys.argv[1])
print ('Use the following Serial-Device:',Const_USBPort)
client= paho.Client("enocean-eg")
client= paho.Client(clientName)
print("connecting to broker ",broker)
client.connect(broker)
client.loop_start() #start loop to process received messages in separate thread
......@@ -52,7 +54,16 @@ while (WatchDogCounter > 0):
pData, pOptData = charSet[6:6+pDataLength], charSet[6+pDataLength:6+pDataLength+pOptionalLength]
print("pPaketType", pPaketType, "Data",pData,"OptData",pOptData)
# list() converts bytearray into array of int
client.publish("homie/enocean-eg/messages", json.dumps({"type":pPaketType, "data":list(pData), "optData":list(pOptData), "time":t}), qos=1)
t = datetime.now()
t = time.mktime(t.timetuple()) + t.microsecond / 1E6
client.publish("homie/"+clientName+"/enocean-messages", json.dumps({"type":pPaketType, "data":list(pData), "optData":list(pOptData), "time":t}), qos=1)
# senderlist = random.sample(['eg','og','ug'], k=round(random.uniform(1,3)) )
# for x in senderlist:
# t = datetime.now()
# t = time.mktime(t.timetuple()) + t.microsecond / 1E6
# client.publish("homie/enocean-"+x+"/enocean-messages", json.dumps({"type":pPaketType, "data":list(pData), "optData":list(pOptData), "time":t}), qos=1)
# time.sleep(random.uniform(0,0.05))
# pOptData[-2] += 5
else:
print("Data CRC NOT ok")
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment