LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to Publish and Subscribe using MQTT to share topics between LabVIEW and other programming languages

This is going to be short and sweet. I had a detailed post that, by the time I posted it, produced an error (I think something timed out).

 

I am using the MQTT Client from LabVIEW Open Source Project to share data between LabVIEW and .NET. I tried to use the pub sub example. It works when publishing and subscribing within LabVIEW, but would not decode payloads that were published outside of LabVIEW. I discovered that Publish.vi adds bytes to the payload and Decode Application Message (Type).vi removes those bytes from the payload. I did not know how to deal with the extra bytes within .NET, so I replaced Publish.vi with Publish (Raw Payload).vi and Decode Application Message (Type).vi with Decode Application Message (Raw).vi.

 

This post is for future users (including me) who need MQTT payloads to work between multiple programming languages.

Message 1 of 9
(2,665 Views)
附上你的VI,从你的语言里不太好判断
0 Kudos
Message 2 of 9
(2,553 Views)

Yes, this is a good changes. My publish & subscribe works well, or else error generated.

Message 3 of 9
(1,932 Views)

Can you provide an example or point me to an example where I can publish to a given topic and also include the command example similar to MQTT Explorer as my command does work there but not in the labview environment unfortunately.

0 Kudos
Message 4 of 9
(408 Views)

Publish notifications to smartwatch.jpg

 

Hi Rehan,

You may refer to my SS, will give you an idea using LabVIEW MQTT library for publish method.

Install MQTT from VIPM

0 Kudos
Message 5 of 9
(386 Views)

Yan,

 

I tried without success. where am I going wrong?  It's a simple topic and value that I just want to send once.  It works using MQTT Explorer but not in a vi.  

Rehal_0-1768841588847.png

Thanking you in advance for your help.

0 Kudos
Message 6 of 9
(319 Views)

Hi!

Check this:

 

SebastianWeber_4-1768905349872.png

 

SebastianWeber_5-1768905379069.png

 

 

 

The Publish VI flattens each input datatype to a string, which contains information about the datatype, as well as the data itself. This results in the extra characters.

 

The flattening by default is done by the open source Serializer class, but you can use your own serializer.

There's already a plain text serializer, which works almost as expected, but surround strings with double-quotes. 

I'd derive a class from this one, which does not add double quotes. 

 

Finally, there's the Publish (Raw Payload) VI, which takes a byte array and sends them exactly as they are. However, you have to deal with converting everything to byte array, so I'd suggest to create an own serializer class.

Message 8 of 9
(293 Views)

Hi Rehal,

 

Please refer to this youtube link.

 

https://www.youtube.com/watch?v=2TUv8o7KdWc

0 Kudos
Message 9 of 9
(248 Views)