Convert namedtuple to json for mqtt - thingsboard
-
I am attempting to upload data in json format to thingsboard from a ruuvitag. I have the data from the device as a namedtuple but need to convert it.
What is the best way to convert this?data
RuuviTagRAW(mac='aa:aa:aa:aa:aa:aa', rssi=-49, format=5, humidity=47.7525, temperature=22.25, pressure=102188, acceleration_x=8, acceleration_y=-16, acceleration_z=1008, battery_voltage=2953, power_info=4, movement_counter=24, measurement_sequence=6190)
required json
{ "RuuviTagRAW": [ { "mac": "aa:aa:aa:aa:aa:aa", "rssi": "-49", "format": "5", "humidity": "47.7525", "temperature": "22.25", "pressure": "102188", "acceleration_x": "8", "acceleration_y": "-16", "acceleration_z": "1008", "battery_voltage": "2953", "power_info": "4", "movement_counter": "24", "measurement_sequence": "6190" } ] }