Click here to Skip to main content
15,882,152 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am trying to display the single element of json data on screen and this data comes from hivemq MQTT.

When I was tried this part in python it was not working but when I tried to display all data on screen at that time it was working and displayed the completed data on screen.

What I have tried:

I have tried this code to display a complete json data on screen.
here is my code which is used to display the entire data on screen which comes from broker.
def on_message(client, userdata, msg):
    data = msg.payload.decode()   
    print(data) 




I was tried lots of codes to display single element or single data from a list of data. here are the few example which were tried by me but it were not working.

print(data['Temperature'])
print(data.Temperature)





Here is the some example of json data which comes from broker..
{"Temperature":27.07,"Vibration":{"RMS":{"X":2},"Kurtosis":{"X":307},"P2P":{"X":0},"Z2P":{"X":0}},"Timestamp":1628571858,"SensorNodeId":"c5101254","SourceAddress":"5509648","GatewayId":"e9653c05","MeasDetails":{"FftSize":4096,"FftWindow":1,"G-range":4,"Precision":1,"BinSize":1000,"ValueOffset":0,"Trigger":1,"Id":38},"Type":"scalar"}
{"SensorNodeId":"c5101254","Timestamp":1628571859,"GatewayId":"e9653c05","SourceAddress":"5509648","BurstDetails":{"DataType":19,"MeasurementTimeInterval":151,"BurstId":4,"ValueMapping":3},"MeasDetails":{"Id":38},"Type":"scalar"}
{"FragCount":0,"ValueMapping":3,"DataType":19,"BurstId":4,"SensorNodeId":"c5101254","Values":[9,0,-9,12,-4,-8,5,-1,-4,2,-2,1,0,-1,1,-1,2,-1,-1,1,0,-1,1,-1,1,-1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"GatewayId":"e9653c05","BurstDataOffset":0,"DataSize":1002,"Type":"burst","MeasurementId":38,"MeasurementTimeInterval":151}
{"FragCount":1,"ValueMapping":3,"DataType":19,"BurstId":4,"SensorNodeId":"c5101254","Values":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"GatewayId":"e9653c05","BurstDataOffset":99,"DataSize":1002,"Type":"burst","MeasurementId":38,"MeasurementTimeInterval":151}
{"FragCount":2,"ValueMapping":3,"DataType":19,"BurstId":4,"SensorNodeId":"c5101254","Values":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"GatewayId":"e9653c05","BurstDataOffset":198,"DataSize":1002,"Type":"burst","MeasurementId":38,"MeasurementTimeInterval":151}
{"FragCount":3,"ValueMapping":3,"DataType":19,"BurstId":4,"SensorNodeId":"c5101254","Values":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"GatewayId":"e9653c05","BurstDataOffset":297,"DataSize":1002,"Type":"burst","MeasurementId":38,"MeasurementTimeInterval":151}
{"FragCount":4,"ValueMapping":3,"DataType":19,"BurstId":4,"SensorNodeId":"c5101254","Values":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"GatewayId":"e9653c05","BurstDataOffset":396,"DataSize":1002,"Type":"burst","MeasurementId":38,"MeasurementTimeInterval":151}
{"FragCount":5,"ValueMapping":3,"DataType":19,"BurstId":4,"SensorNodeId":"c5101254","Values":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"GatewayId":"e9653c05","BurstDataOffset":495,"DataSize":1002,"Type":"burst","MeasurementId":38,"MeasurementTimeInterval":151}
{"FragCount":6,"ValueMapping":3,"DataType":19,"BurstId":4,"SensorNodeId":"c5101254","Values":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"GatewayId":"e9653c05","BurstDataOffset":594,"DataSize":1002,"Type":"burst","MeasurementId":38,"MeasurementTimeInterval":151}
{"FragCount":7,"ValueMapping":3,"DataType":19,"BurstId":4,"SensorNodeId":"c5101254","Values":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"GatewayId":"e9653c05","BurstDataOffset":693,"DataSize":1002,"Type":"burst","MeasurementId":38,"MeasurementTimeInterval":151}
{"FragCount":8,"ValueMapping":3,"DataType":19,"BurstId":4,"SensorNodeId":"c5101254","Values":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"GatewayId":"e9653c05","BurstDataOffset":792,"DataSize":1002,"Type":"burst","MeasurementId":38,"MeasurementTimeInterval":151}
{"FragCount":9,"ValueMapping":3,"DataType":19,"BurstId":4,"SensorNodeId":"c5101254","Values":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"GatewayId":"e9653c05","BurstDataOffset":891,"DataSize":1002,"Type":"burst","MeasurementId":38,"MeasurementTimeInterval":151}
Posted
Updated 10-Aug-21 1:12am
Comments
Richard MacCutchan 10-Aug-21 10:22am    
Note also, that JSON is badly formed.

1 solution

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900