Share on facebook
Share on twitter
Share on linkedin

BY Jordy van Paassen

How to connect an Arduino MKR WiFi 1010 device with Azure IoT Device Central

The last couple of months, we were experimenting with IoT devices powered by Arduino, which were pre-programmed to connect to AWS. But what about Azure? I took the challenge to make the Arduino MKR WiFi 1010 work with Azure and I can tell you now that it wasn’t that easy as you would expect. In this blog I describe how I managed to deal with Arduino libraries in combination with Azure IoT Device Central in order to make this work.
Share on facebook
Facebook
Share on twitter
Twitter
Share on linkedin
LinkedIn

At our office, we have some plants that need watering from time to time. As nerds are, this is something we often forget. For this reason, we bought the Arduino MKR WiFi 1010 device with two sensors to measure the moisture of the soil and to get alerted when the soil moisture is below a certain threshold. 

In my struggle to get this working I’ve contacted the Principal Program Manager at Microsoft Benjamin Cabe, who helped me out big time with getting everything working. Thank you, Benjamin!

Prerequisites

To get started with IoT in Azure, you’ll need the following to be in place before starting.

Microsoft Azure

  • An Azure subscription (of course)
  • Registered resource ‘IoT Device Central’ on your subscription

Arduino MKR WiFi 1010

  • Install library ‘WiFiNINA’
  • Install library ‘SimpleDHT’
  • Install library ‘RTCZero’
  • Install library ‘PubSubClient’

Additional required software

Setting up the Azure environment

The first step is to go to your Microsoft Azure Environment and to sign in. Once you’re logged in, you can start creating IoT Device Central resources. If you have trouble locating the Azure IoT Device Central service, use the search bar.

Create a default IoT Device Central on an existing or new resource group. 

In my case I’ve chosen the name ‘iotdemorgcn’ as resource group name and ‘iotcndemo’ as resource name.

IoT Device Central

Registering the MKR WiFi 1010 

Now we have a successfully created IoT Device Central. In order to configure the MKR WiFi 1010 device, select the ‘MXChip’ template from the menu option ‘Device templates’.

MKR WiFi 1010

Once the ‘MXChip’ template is selected, the provisioning of the device will start.

The default configuration has a simulated device as an example. Now it’s time to connect the real MKR WiFi 1010 to the IoT Device Central. Select the + icon in the navigation menu right on top to create a real device.

The next thing we need to do is to bind the connection between the MKR WiFi 1010 device with the Arduino Software and Azure Portal.

Download the Arduino software version.

Get started with the GitHub Library

Some steps of the readme.md from this GitHub repository are probably the same. However, the configuration file shown below needs to be changed. 

After loading all prerequisites of the GitHub library and documentation 

After that, we have to change the connection parameters in the configure.h file.

Azure IoT Central Device Information

When you have set al the needed parameters you can compile the software with this Keys.

With regard to security, be sure to not commit to a public repository with your Azure environment keys and your WiFi password.

Compile your software to build your solution custom for your device and Azure Environment. Once the compilation has succeeded, you can upload the software to the MKR WiFi 1010. You can monitor the steps and output in de COM3 windows of the Arduino Software. Additionally, you can check the information received in the Microsoft Azure portal.

IoT Hub
MXChipdemo

Troubleshooting

When you run into a compilation error in the Arduino software, try to fix a pointer method in the Utils class.

When you run into a compilation error in the Arduino software, try to fix a pointer method in the Utils class.

Replace the *dtostrf method from Utils.h for an alternative shorter solution of *dtostrf.

char *dtostrf (double val, signed char width, unsigned char prec, char *sout) {
  char fmt[20];
  sprintf(fmt, "%%%d.%df", width, prec);
  sprintf(sout, fmt, val);
  return sout;
}

When you are experiencing connection problems, use this the table with error codes to troubleshoot issues in the Arduino software. 

Additional information

For the pricing details, click here.