Skip to content

Raw payload not working #7

@lalo-uy

Description

@lalo-uy

If you have a raw payload the json_load throw an exception and the val is not loaded.

here is a patch that check the payload_text before

@@ -58,13 +60,14 @@ class MQTT_SENSOR(SensorActive):
             
             try:
                 print "payload " + msg.payload        
-                json_data = json.loads(msg.payload)
-                #print json_data
-                val = json_data
+                val = msg.payload
                 if self.payload_text is not None:
+                    json_data = json.loads(msg.payload)
+                    #print json_data
+                    val = json_data
                     for key in self.payload_text:
                         val = val.get(key, None)
                 #print val
                 if isinstance(val, (int, float, basestring)):
                     q.put({"id": on_message.sensorid, "value": val})
             except Exception as e:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions