X-Git-Url: https://git.rvb.name/weathermon.git/blobdiff_plain/7aaa06f870e4fb4954ec65091cc12f9f0bf58b04..7edb3771717d15f7c36d8459fa12b3d6f76d7d9a:/weathermon-mqtt?ds=inline diff --git a/weathermon-mqtt b/weathermon-mqtt index 1d96410..c6b6a82 100755 --- a/weathermon-mqtt +++ b/weathermon-mqtt @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/python -u import paho.mqtt.client as paho import sys @@ -14,24 +14,27 @@ def on_message(mosq, obj, msg): payload=json.loads(msg.payload) timestamp=tparser.parse(payload['Time']) for sensor_type in payload: - if sensor_type != 'Time': + if sensor_type != 'Time' and sensor_type != 'TempUnit': sensor_data=payload[sensor_type] for param in sensor_data: try: value=sensor_data[param] - c = database.cursor() - c.execute('CALL meteo.submit_mqtt(%s,%s,%s,%s,NULL)', (topic,sensor_type,param,value)) - database.commit() - print topic,sensor_type,param,value + try: + c = database.cursor() + c.execute('CALL meteo.submit_mqtt(%s,%s,%s,%s,NULL)', (topic,sensor_type,param,value)) + database.commit() + print topic,sensor_type,param,value + except: + print "Failed to submit data" except: - print "Failed to submit data" + None def Topics(): c = database.cursor() c.execute( ''' - select topic from mqtt_topics + select topic from mqtt_topics where topic<>"" ''' )