I’d like to test connectivity to Azure via MQTT, so I was browsing on the forums to see similar projects. I was found the library ‘AzureIotHubClientV2’ and decided to try the AzureIotHubFull example code in it.
However, I’m getting the following error during compile:
unfortunately I can’t modify the library on the Web IDE, and on VSCode it’s giving me errors from the beginning: 'cannot open source file “AzureIotHubClient.h”, which has me running in circles trying to understand the correct VSCode configuration.
even when the files and folders are there.
Thanks for the link as well. I have tested the Particle Integrations and they work, but I’d like to test the direct connections to IoT Hub.
I’ll let you know if I find a solution to this, thanks!
How did you install the library in Workbench? The easiest way is to use the command palette (Command-Shift-P or Ctrl-Shift-P) the Particle: Install Library.
If you did it from the command line, make sure you both particle library add and particle library copy the library.
Also, the library include-related Intellisense errors are not generally fatal. You may see them in the source file, but if you cloud compile the files will be found if your project.properties file is correctly set up.
thanks @rickkas7 . I have used the Particle:Install Library on the command palette. It still shows the error.
I am surprised to see that the AzureIotHubClientV2 library can’t compile on the Web IDE. is it something that Particle IO verifies?
Reagrding the error on VSCode, this error of not finding the source file is an error which doesn’t allow the project to compile. Could you please share some guide on how to configure the project.properties to make the cloud compile find the files? I am using the Cloud compile, but it still send me the error.
the error is related to the library MQTT-TLS and the file mbedtls_config.h. I know the file is there, I have even downloaded the library files from the library github, and pasted them in different folders throughout the project to see if it can find them. it doesn’t.
I don’t have enough experience and knowledge on VSCode to make sure that my configuration is proper for the project to read the headers. Any guide on this would be of great help.
It will require modifications to make this library compile. I got it to compile locally in Workbench but did not test if it works on a device.
I built the simple example from the library. This line failed because it was missing the V2 in the name of the include file. That fixed one problem.
The other is:
/Users/rickkas7/Documents/src/TestParticle/TestAzureIotHubClientV2/lib/AzureIotHubClientV2/src/AzureIotHubClientV2.cpp: In member function 'bool IotHub::publish(String)':
/Users/rickkas7/Documents/src/TestParticle/TestAzureIotHubClientV2/lib/AzureIotHubClientV2/src/AzureIotHubClientV2.cpp:102:1: error: no return statement in function returning non-void [-Werror=return-type]
102 | }
Changing this function in AzureIotHubClientV2.cpp to return a valid fixed this error.
I wasn’t able to cloud compile this code, with a very non-specific error, so that’s weird. But I was able to compile locally in Workbench for Boron 4.0.0 so at least that works with code modifications.
After exhaustive troubleshooting of the library, I have decided to give up on it. I never got it to compile, so I cannot test it as it is.
I’ll continue testing the MQTT library connecting it to Azure.
I haven’t had any success either connecting to Azure with the MQTT library from @hirotakaster .
I’m being asked to use TLS 3.1.2, which I don’t see defined on the library files. I don’t know if this is a dealbreaker on this connection.
for the MQTT client() I’m defining the iot hub url, the port 8883 and the callback. I don’t need a QoS for now.
On the connect function I’m assigning an arbitrary id, a user, which is the device name on the IoT Hub, a password, with the format of the SAS token ‘SharedAccessSignature sr=iothuburl&sig=characters’ , but it never connects.
I have tried connecting on the setup() and on the loop() if disconnected, but never have any success.
if you have any comments on what I could be missing here, please advise!
If I were in your situation, I would think about doing two things:
1- talk to this person that mentions they used the lib on Gen3:
2- mqtt with certs is… tough. If Azure provides a test mqtt client, I would first check that I get that up and running. Maybe you could even lower the TLS version to just test if this is getting in the way of success.
3- I would get logs of the MQTT connection to see if I can find where and why it fails. Other people have posted their success and fail logs so I would compare that.
4- Since you mention a Boron, are you using the internal sim? Sometimes external SIM card can get in the way in weird ways.
PS: yeah, I know, that turned out to be four things.
I have been successful using MQTT certs to another broker in the past, although never with a consistent connection. It could last from a few hours to a few days, then disconnected and needed to reboot. It might be related to my lack of knowledge of the library to re-enable it and re-connect, but I still was able to connect.
I have been using only Borons, and only for the last year, year and a half. I just started testing the MQTT to Azure a couple weeks ago and just a few hours a week.
I’m working on adding logs to the MQTT connection; I’ll see what comes from it.
Working with SIMs all together is hard, since connectivity can be very unreliable at times. I’m using only internal SIMs, which are fine, but if it’s a bad day, then it will take 3 times the effort to test and troubleshoot. By the way, I don’t use serial logs, so it all has to be done over the cloud using Particle.publish() many, many times
Thanks for your suggestions. I have contacted the author of the post you provided. I’ll let y’all know if I make any progress on this.
I don’t mind the 4 suggestions… if you have more, keep em coming!
I was wrong about the TLS version, I got confused with MQTT version and TLS. MQTT version is 311, and TLS version is 1.2. the MQTT-TLS library should support connectivity to Azure. For some reason, the connection is not taking the parameters properly -or I’m not defining the parameters properly- to allow connection.