-def on_message(mosq, obj, msg):
- topic=msg.topic
- payload=json.loads(msg.payload)
- timestamp=tparser.parse(payload['Time'])
- for sensor_type in payload:
- if sensor_type != 'Time' and sensor_type != 'TempUnit':
- sensor_data=payload[sensor_type]
- for param in sensor_data:
- try:
- value=sensor_data[param]
- 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:
- None
+local function uuid()
+ local template ='xxxx-xxxx'
+ return string.gsub(template, '[x]', function (c)
+ local v = random(0, 0xf)
+ return string.format('%x', v)
+ end)
+end