X-Git-Url: https://git.rvb.name/weathermon.git/blobdiff_plain/3710dc777a1990a2868d3d187d9dd18efaa1f90a..7aaa06f870e4fb4954ec65091cc12f9f0bf58b04:/weathermon-mqtt?ds=inline diff --git a/weathermon-mqtt b/weathermon-mqtt index 6c5fd37..1d96410 100755 --- a/weathermon-mqtt +++ b/weathermon-mqtt @@ -5,17 +5,26 @@ import sys from ConfigParser import ConfigParser import MySQLdb from pprint import pprint +import json +from dateutil.parser import parser +tparser=parser() def on_message(mosq, obj, msg): topic=msg.topic - payload=msg.payload - try: - c = database.cursor() - c.execute('CALL meteo.submit_mqtt(%s,%s,NULL)', (topic,payload)) - database.commit() - print topic,payload - except: - print "Failed to submit data" + payload=json.loads(msg.payload) + timestamp=tparser.parse(payload['Time']) + for sensor_type in payload: + if sensor_type != 'Time': + 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 + except: + print "Failed to submit data" def Topics():