AzureIoTHubClientV2

hi all,

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:

I get the same error even when trying an empty setup() and loop().

I’m using the Web IDE to compile and flash this project. When I use VS code it doesn’t compile either.

Can anybody shed light on this issue?

thanks!

-R

@romuloescamilla ,

This message indicates that there is an error in the library. You can fix the error easily but it may not bode well for the utility of this library.

Here is the offending function at line 102 in the library’s cpp file:

bool IotHub::publish(String msg)
{
  if (connected())
  {
    client->publish(this->topic.messagePublish, msg);
  }
}

As you can see, this function promises a boolean return but there is no provision for it in the code. You could modify it to look like this:

bool IotHub::publish(String msg)
{
  if (connected())
  {
    client->publish(this->topic.messagePublish, msg);
    return true;
  }
  return false;
}

But then the compiler goes on to find more errors.

I recommend you take a look at this tutorial - not sure about MQTT but it will get you connected to Azure IOT Hub via a built in Particle integration:

Hope this helps, Chip

thanks Chip!

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.

image

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!

-R

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.

thanks,

-R

You can try opening a CLI window (Particle: Launch CLI) and doing:

particle library copy AzureIotHubClientV2

There is no validation of community libraries. From the AzureIotHubClientV2 library page it has never passed the example building test in any recent version of Device OS.

1 Like

by the way, I’m trying the cloud compile for a Boron v4.0.0
image

image

as I open the files showing the problems, it keeps adding problems on the PROBLEMS tab (the same one, pointing to mbedtls_config.h):

I understand this is an issue related to the configuration of VSCode, so, any comments on how to configure i successfully would be great.

thanks!

-R

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.

#include "AzureIotHubClientV2.h"

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.

bool IotHub::publish(String msg)
{
  if (connected())
  {
    client->publish(this->topic.messagePublish, msg);
  }
  return true;
}

Modified sha256.cpp to fix another missing return value error:

size_t Sha256Class::write(uint8_t data)
{
  ++byteCount;
  addUncounted(data);
  return 1;
}

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.

let me try those changes on the library and see if it allows me to compile.

thanks for your support!

-R

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 .

  1. 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.
  2. 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.
  3. 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.
  4. 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!

thanks!

-R

Hi Romulo,
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.

Best,
Gustavo.
PS: yeah, I know, that turned out to be four things.

1 Like

thanks @gusgonnet !

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 :frowning:

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!

-R

The next suggestion will be to start using those serial logs, in MQTT they abound and they are important.

Hi, I had the chance to look at a log and it mentioned TLSv1.2. Again, I can’t say what versions are supported.

thanks @gusgonnet

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.

Thanks!

-R