add AwsPublish

This commit is contained in:
Wolfgang Hottgenroth
2017-07-18 21:23:19 +02:00
parent 6884d44bb8
commit d9064f3527
3 changed files with 69 additions and 10 deletions

View File

@ -24,22 +24,22 @@ class RePublisher(threading.Thread):
def run(self):
client = mqtt.Client()
client.connect(self.broker, 1883, 60)
client.loop_start()
client.loop_start()
while True:
try:
msg = self.queue.get()
dataBlock = msg['data']
if 'decodedTelegram' in dataBlock:
del dataBlock['decodedTelegram']
if 'telegram' in dataBlock:
del dataBlock['telegram']
if 'decodedTelegram' in dataBlock:
del dataBlock['decodedTelegram']
if 'telegram' in dataBlock:
del dataBlock['telegram']
metadataBlock = msg['metadata']
if 'Slave' in metadataBlock:
if metadataBlock['Slave'] == 'Thermometer' and metadataBlock['device'] == 'ModbusHub':
metadataBlock['name'] = 'FridgeThermometer'
topic = "IoT/ParsedData/%s" % metadataBlock['name']
if 'Slave' in metadataBlock:
if metadataBlock['Slave'] == 'Thermometer' and metadataBlock['device'] == 'ModbusHub':
metadataBlock['name'] = 'FridgeThermometer'
topic = "IoT/ParsedData/%s" % metadataBlock['name']
client.publish(topic, json.dumps(msg, cls=MyEncoder))
Logger.log("RePublisher has sent data")
Logger.log("RePublisher has sent data")
except Exception, e:
Logger.log("Unexcepted exception %s in RePublisher: %s" % (e.__class__.__name__, str(e)))