Jump to content

Recommended Posts

Hi,

I am trying to send a simple message to an Azure IoT hub. I am pretty new to all this, but have followed a few tutorials and Pluralsight courses and can successfully send a message from VS Code to my hub.

What I have not been able to do yet is send a message using LabVIEW. I have tried several different MQTT libraries, without any success. Has anyone done this kind of thing before and can offer guidance on which toolkit they used?

I am using VSCode to generate the SAS token and using that as the password.

Edit: I have been able to send some messages using simple C# code, this code works fine.

image.png.84aaf87467b72df258a4e02053489787.png

Edited by Neil Pate
Link to post
Share on other sites

I have successfully used (unsecure) MQTT for LabVIEW, I have not tried it with the Azure IoT broker though. With this LabVIEW implementation for example: https://github.com/cowen71/mqtt-LabVIEW. The connection settings just had to be reconfigured slightly to get the link up and running. Here is a setup that works to connect to adafruit.io....you just need to change the user account and feed name of course, and the password (intentionally cropped out here):

mqtttest.PNG.fb61e268899187931dabc78cff278839.PNG

 

You may also need to open the firewall...In my case it allowed the connection, but blocked everything afterwards (producing error 66).

I have not been able to use TLS with any of LabVIEW implementations though, but perhaps that can be remedied more easily now that TLS is supported in LabVIEW 2020...

 

 

Edited by Mads
Link to post
Share on other sites
Posted (edited)

Thanks, I am actually already about half-way through the 2020 installation so I can check out the TLS stuff.

That library you mentioned is what I am using, I did try modifying all the settings that seem sensible (for example Azure IoT hub uses port 8883) but it still does not work. Actually the connect seems to work, and the publish does not give any errors but no data appears in my hub. I am still very much a newbie in Azure IoT so there is a lot to learn for me.

Edited by Neil Pate
Link to post
Share on other sites

Just a thought. Have you verified which version of MQTT is supported on Azure? MQTT 5 is most recent, and although MQTT 3.1 is normally supported by brokers, Azure IoT hub is not a fully-compatible MQTT broker. There might be restrictions on QoS, will messages or even TCP vs Web Sockets...

Link to post
Share on other sites

Thank Francois. I believe Azure does support 3.1 but I cannot recall where I saw this info.

I think the problem is the missing TLS which I am now digging into. Now I am down a rabbit hole of security concepts and terminology that I have only ever had a passing interest in. TLS, X.509, primary thumbprints 🤯

Link to post
Share on other sites
1 minute ago, Francois Normandin said:

If it's a commercial project and you're on a deadline, you can check Wireflow's MQTT client. It ain't free, but supports TLS. http://sine.ni.com/nips/cds/view/p/lang/fr/nid/213501

Yes I am more than happy to pay for a commercial toolkit, but I did try this out also and it did not connect either. I will get in touch with them I think 🙂

  • Sad 1
Link to post
Share on other sites

Port 8883 is usually used for TLS (1883 for non-TLS).

There are a couple of examples of how to use TLS in 2020, if you search for TLS in the examples finder:

 

image.png.8f49d1f79b6b852dfd30a9600a740834.png

  • Thanks 1
Link to post
Share on other sites
1 hour ago, Mads said:

Port 8883 is usually used for TLS (1883 for non-TLS).

There are a couple of examples of how to use TLS in 2020, if you search for TLS in the examples finder:

 

image.png.8f49d1f79b6b852dfd30a9600a740834.png

Thanks, I did actually search but did not press enter and just bailed when the Keywords list was empty!

Link to post
Share on other sites
Posted (edited)

@mads

Awesome, it works! Thank you for your suggestion. I did not realise TLS could be done "simply", I was messing around with certificates and stuff and getting nowhere!

image.png.05fd9149e2ac00c842a4ab4860951ed5.png

Edited by Neil Pate
Link to post
Share on other sites
11 hours ago, Neil Pate said:

This is the only change I made to the MQTT library. Simples 🙂

I had not realized either it was so simple to add TLS.
I didn't plan to upgrade my broker to 2020, but multiplatform TLS is tempting.

(shameless plug for my project: https://github.com/LabVIEW-Open-Source/LV-MQTT-Broker)

Link to post
Share on other sites
Posted (edited)

WOOT!

Just tested this MQQT library running on a simulated cRIO in a VM and it also works and can talk to my Azure IoT hub 🤩

image.png.4001baec06d6c55a51eacb439d413646.png

Edited by Neil Pate
Link to post
Share on other sites
Posted (edited)
On 6/15/2020 at 1:54 AM, Francois Normandin said:

I had not realized either it was so simple to add TLS.
I didn't plan to upgrade my broker to 2020, but multiplatform TLS is tempting.

(shameless plug for my project: https://github.com/LabVIEW-Open-Source/LV-MQTT-Broker)

I did look at your Github page but did not try your code as I though it was the broker only. However upon closer examination I see it does include a client also. Would it be of interest to you to see if I can get it connecting to my Azue IoT hub?

Edit: there seems to be an error in the project, the two Destroy.vi are not there. Removing them manually seems to fix the Test Server

image.png.1388e8c72f7885536ca16b0f7e408d22.pnge

 

I did try make the TLS changes and connect with sensible parameters but it did not seem to work. I can try again tomorrow if you like, otherwise I am probably going to park this here for now as I have a working solution with the other MQTT library.

 

 

 

Edited by Neil Pate
Link to post
Share on other sites

@Neil Pate

I thought I had fixed this bug. It dates from my NIWeek 2019 demo when I made a last minute change from "Destroy" public method to "onDestroy" protected method.

You see what happens when you do a TDD project and you skip the tests "JUST ONCE" because you're in a hurry and the boss wants this code deployed ASAP??? Hahaha!

I'll do a fix this weekend... 

Edit: Was fixed in the Develop branch... I'll test, bring to master branch, build and release a new package.

Edited by Francois Normandin
  • Haha 1
Link to post
Share on other sites
  • 2 weeks later...

Quick update.

I can send data from my cRIO to an Azure IoT hub, from there pass it to an Azure Streaming Analytics job which pumps the data into an Azure SQL DB and also to a Power BI Dashboard. The pieces of the puzzle are starting to fall into place 🙂

  • Like 1
Link to post
Share on other sites

Hi guys,

So there's no way I could use either library (original or Francois') in LabVIEW 2018 to send data to an Azure IoT hub? - 

I read a post that someone used .NET constructors to a TLS 1.2 DLL but it sounds like a minefield.

Jorge

Link to post
Share on other sites
  • 2 months later...
4 hours ago, Breizh_Instruments said:

Hello everybody,

Thank you for this very interesting topic.

I need to connect as a client to a broker with a certificate.

Is there someone that use the LV 2020 TLS with this client LV-MQTT ?

I have not used this particular client, but have done something similar with AWS and MQTT and a different client. I wound up stripping out all the OpenSSL stuff for the new native LabVIEW tools. Here is what worked for me during some initial tests. It may not be perfect, but hopefully it's a start at least. After that it's regular TCP Read/Write.

 

image.png.d3f4dcd5791fe7e7b828c2c3251803ef.png

Link to post
Share on other sites
  • 2 weeks later...

@Steve Drouilhet

No problem. I believe it was this toolkit: https://github.com/Indie-Energy/AWS-IoT-RESTful and the license is pretty wide open I believe. If I have a chance I'll see if I can pack it up and contribute to the project on the github.

I'm also using the WireFlow toolkit (paid) for some MQTT projects with a broker that I've set up. I was initially drawn to the Indie-Energy one even though I have a WF toolkit license since it was more plug and play for AWS. I do think now after learning more about the AWS IoT stuff that either will work, but also that I don't want to work with AWS IoT if I can help it. Note, the WF toolkit does not use the native LV2020 implementation and they do not have plans to do so. The reason I replaced the IE toolkit TLS code is because I had issues on Linux RT and that fixed it. I have not had issues in general with WF on RT, but I'm not using TLS in that application (yet).

  • Like 1
Link to post
Share on other sites
  • 1 month later...

Hi Neil.  

Long time no see.  I am trying to do something similar to what you have done above - I have my Azure hub set up and can talk to it via my Beaglebone ok (trying to open the door of my Chicken Coop).  What I'm not getting is where the Primary Key/Connection String gets inserted using the MQTT (Cowen71).  I seem to connect to the hub ok, just not the device.  Can you offer any assistance?

Thanks, Rob (FIF1)

 

 

 

LV MQTT Settings.png

Edited by UncleFungus46
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.