LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

MQTT communication issue with parsing JSON data

Hello again,

 

Been working on a little MQTT setup. The setup isn't too complex but I can't seem to get the data to come in or get parsed correctly. Not sure what the issue is since I've been tweaking it for a while now but I do notice however that the issue seems to be with how I'm handling the incoming payload from the MQTT client. I'll also point out that I am using an Ammonia sensor connected to an ESP32 - the measurements are already being taken and the MQTT publisher, broker, subscriber are working together fine so my PC receives the data just fine but I can't get it to work in LabVIEW. 

 

The gist of the code is to subscribe to the publishing data via MQTT (step complete), take the incoming JSON data and have the real-time changing measurements display individually in the front panel (type - string, concentration - numeric, temperature - numeric, voltage - numeric). I also included a waveform chart after an Unbundle node to display only one of these variables at a time for now but can't display any of the measurements yet. 

 

I'm including a few versions of my current setup and also a screen shot of how the string data looks when its received on a Serial Monitor outside of LabVIEW. Please let me know what I'm doing wrong here. Thank you in advance!

 

Kind regards,

PDB

 

PDBSteenhuisen_0-1758205789343.png

 

 

Download All
0 Kudos
Message 1 of 4
(86 Views)

Use Decode Application Message (Raw).vi instead of Decode Application Message (Type).vi.

 

The one you are using now is expecting flattened variants on the wire iirc. You can use that when communication between LabVIEW programs.

 

Use byte array to string to convert the payload to string and then unflatten from JSON.

0 Kudos
Message 2 of 4
(75 Views)

I can't open your VI's (still on 2023) but I can say if you're using the built-in JSON library, I recommend switching to the JSONText library: https://www.vipm.io/package/jdp_science_jsontext/

 

It's VERY flexible and has a LOT more features than the other libraries I've tried.

0 Kudos
Message 3 of 4
(67 Views)

An example of two ways to decode the message using JSONText, assuming you get the whole JSON bundle from your MQTT library:

 

Example_VI.png

 

The "$" notation is a little confusing at first, but you get the hang of it. "$" just means the "root" item in the JSON input. Dots let you get sub-items.

0 Kudos
Message 4 of 4
(63 Views)