Исправлена ошибка при пустом (но не null) имени топика.
authorRoman Bazalevskiy <rvb@rvb.name>
Wed, 3 Jan 2018 19:11:44 +0000 (22:11 +0300)
committerRoman Bazalevskiy <rvb@rvb.name>
Wed, 3 Jan 2018 19:11:44 +0000 (22:11 +0300)
weathermon-mqtt

index f288f51f8055e076b4a7b6c9595a6937f37d6982..c6b6a82db1f6959e4bd297eb0fb868f5d09551de 100755 (executable)
@@ -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:
   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]
       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:
         except:
-          print "Failed to submit data"  
+          None    
 
 def Topics():
 
   c = database.cursor()
   c.execute(
     '''
 
 def Topics():
 
   c = database.cursor()
   c.execute(
     '''
-    select topic from mqtt_topics
+    select topic from mqtt_topics where topic<>""
     '''
   )
 
     '''
   )