I'm testing out MQTT from my Wago PLC using JSON object. I have managed to publish this {"Temperature":15.6,"Setpoint":38.0} to my broker. Now I', trying to subscribe to the same message. The result is this:
'{"Temperature":15.6,"Setpoint":38.0}95}ê$10šå$04$Nå$08²Ÿå$0B` á$08@šå'
First, why do I see 95}ê$10šå$04$Nå$08²Ÿå$0B` á$08@šå' at the end of the message?
Second, how Can i sort out this data to use it in my program? I followed a youtube tutorial which gave me the attached result, which works. But I need some other smart way of doing this when the object gets even more data in it.
Just adding:
sSubscriberdata := '';
Right before your memcopy should fix the extra characters. It is because your are copying 36 characters into a string which can contain more than 36 characters and there is garbage left in the extra characters.
Regarding the parsing of json, I usually build a structure that mirrors the json data and use the available methods in the IIoT library to parse the data and fill the structure.
Hi there,
I'm testing out MQTT from my Wago PLC using JSON object. I have managed to publish this {"Temperature":15.6,"Setpoint":38.0} to my broker. Now I', trying to subscribe to the same message. The result is this:
'{"Temperature":15.6,"Setpoint":38.0}95}ê$10
Å¡Ã¥$04
$Nå$08²Ÿå$0B` á$08@šå'First, why do I see 95}ê$10
Å¡Ã¥$04
$Nå$08²Ÿå$0B` á$08@šå' at the end of the message?Second, how Can i sort out this data to use it in my program? I followed a youtube tutorial which gave me the attached result, which works. But I need some other smart way of doing this when the object gets even more data in it.
Any help is very appreciated :)
Just adding:
sSubscriberdata := '';
Right before your memcopy should fix the extra characters. It is because your are copying 36 characters into a string which can contain more than 36 characters and there is garbage left in the extra characters.
Regarding the parsing of json, I usually build a structure that mirrors the json data and use the available methods in the IIoT library to parse the data and fill the structure.
Last edit: yannickasselin 2024-05-08