Skip to main content

Connect to Azure IoT Hub using WizFi360 MQTT AT Command

Getting started#

Login to Azure Portal.

※ In this guide we will procedd with free account. To learn how to create IoT Hub please refer to Azure Cloud Service Introduction.

Introduction#

It is possible to connect to Microsoft Azure Service using WizFi360, send data to cloud and monitor current status.

Data communication will be established as following.

MQTT AT Commands will be used to connect to IoT Hub Service & send data.

Data sent to IoT Hub will be saved in Blob Storage through Stream Analytics.

In this guide we will use WizFi360 with Mbed to connect to Microsoft Azure Services using MQTT AT Command.

Step 1: Required items#

Items below are required for this guide.

Hadrware#

Software#

  • Mbed Studio
  • Preferred Serial Terminal (TeraTerm, Hercules, etc . . .)

Step 2: Device preparation#

1. Hardware preparation#

WizFi360-EVB-Shield will be installed on top of NUCLEO-L476RG. Therefore DIP Switch and jumper cables shall be connected as following:

  • SW1 : Off
  • SW2 : Off
  • SW3 : On
  • D2 : UART Tx
  • D8 : UART Rx

2. Device connection#

After connecting hardware, connect NUCLEO-L476RG to Desktop or Laptop using USB Cable.

Check COM Port from Device Manager.

If COM port cannot be found in Device manager, check link below and follow instructions.

Step 3: Sample application#

1. Code Download & Execution#

After code download, open project by selecting File > Open Workspace.

Sample code is stored in following path.

  • samples/Wi-Fi/Mbed_Mqtt_Atcmd_Wizfi360

  • samples/Wi-Fi/Mbed_Mqtt_Atcmd_Wizfi360_Azure_C_Shared_Utility

In case of Mbed_Mqtt_Atcmd_Wizfi360 SAS Token was created using Device Explorer or Azure IoT Explorer.

In case of Mbed_Mqtt_Atcmd_Wizfi360_Azure_C_Shared_Utility there is no need to create SAS Token separately as azure_c_shared_utility Library was ported into Project.

2. Parameter update#

To connect to Azure IoT Hub, update next parameters.

/* Wi-Fi info */
char ssid[] = "xxxxxxxxxx";
char password[] = "xxxxxxxxxx";
/* MQTT info */
int alive_time = xx; // range : 30 ~ 300
/* Azure info */
char hub_name[] = "xxxxxxxxxx";
char host_name[] = "xxxxxxxxxx";
char device_id[] = "xxxxxxxxxx";
char device_key[] = "xxxxxxxxxx";
char sas_token[] = "xxxxxxxxxx";

For SAS Token creation refer to below.

3. Project Build & Run#

Press Run Program to Project Build & Run.

Note :

Start Stream Analytics in order to forward data to Blob Storage.

Step 4: Results#

In terminal program we can check data sent from WizFi360 to Azure IoT Hub. In Blob Storage we can check received data.

References#