Connect to Azure IoT Hub using WizFi360 Azure AT Command
#
Getting Started#
Hardware Requirement- Desktop or laptop computer
- MicroUSB cable
- WizFi360-EVB-Shield
#
Software Requirement- Preferred Serial Terminal (TeraTerm, YAT, etc.)
- Azure IoT Explorer
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.
#
IntroductionMicrosoft Azure is cloud computing service. Using WizFi360 we can connect to Azure services, transmit data and monitor status.
In this document we will guide how to connect Arduino Mega 2560 + WizFi360 to MS Azure Services. Thic process consists of following steps:
- Azure IoT Hub preparation
- IoT device registration
- Connect to Azure IoT and transmit data
For Azure IoT Hub setup and IoT device creation please refer to [Azure Cloud Introduction].
For this guide WizFi360-EVB-Shield Evaluation board was used.
#
Device preparation#
Hardware configurationWizFi360-EVB-Shield will be used in Standalone mode. Therefore DIP Switch and jumper cables shall be connected as following:
- SW1 : On
- SW2 : Off
- SW3 : Off
#
Device connectionAfter connecting hardware, connect WizFi360-EVB-Shield to Desktop or Laptop using USB Cable.
Check COM Port from Device Manager.
If COM port cannot be found in Device manager, check drivers from link below.
#
AT Commands#
1. Set current WiFi mode (not saved in flash)AT Command: AT+CWMODE_CUR Syntax:
Type | Command | Response |
---|---|---|
Query | AT+CWMODE_CUR? | +CWMODE:<mode> OK |
Set | AT+CWMODE_CUR=<mode> | OK |
Defined values:
Mode | Value |
---|---|
1 | Station mode |
2 | SoftAP mode (factory default) |
3 | Station+SoftAP mode |
#
2. Enable DHCPAT Command: AT+CWDHCP_CUR Syntax:
Type | Command | Response |
---|---|---|
Query | AT+CWDHCP_CUR? | +CWDHCP_CUR:<para> OK |
Set | AT+CWMODE_CUR=<para>,<en> | OK |
Defined values:
Parameter | Value |
---|---|
0 | DIsable SoftAP DHCP & Station DHCP. |
1 | Enable SoftAP DHCP & Disable Station DHCP. |
2 | Disable SoftAP DHCP & enable Station DHCP. |
3 | Enable SoftAP DHCP & Station DHCP. (factory default) |
#
3. List available APsAT Command: AT+CWLAP Syntax:
Type | Command | Response |
---|---|---|
Query | AT+CWLAP | +CWLAP:([<ecn>,<ssid>,<rssi>,<mac>,<channel>,<wps>]) |
Defined values:
Parameter | Value |
---|---|
<ecn> | 0: Open 1: WEP 2: WPA_PSK 3: WPA2_PSK 4:WPA_WPA2_PSK |
<ssid> | string parameter. AP ssid |
<rssi> | signal strength |
<mac> | string parameter. AP mac |
<wps> | 0: Disable WPS 1: Enable WPS |
#
4. Connect to APAT Command: AT+CWJAP_CUR Syntax:
Type | Command | Response |
---|---|---|
Set | AT+CWJAP_CUR=<ssid>,<pwd>,[<bssid>] | +CWJAP_CUR:<ssid>,<bssid>,<channel>,<rssi> OK |
Defined values:
Parameter | Value |
---|---|
<ssid> | string parameter. Target AP의 ssid. MAX: 32 bytes |
<pwd> | string parameter. Target AP의 password. MAX: 64-byte ASCII |
<bssid> | string parameter, target AP' MAC address, used in case if there are several APs with same SSID. |
#
5. Azure IoT Hub configuration setAT Command: AT+AZSET
Syntax:
Type | Command | Response |
---|---|---|
Set | AT+AZSET=<iothub_name>,<device_id>,<device_key> | OK |
Defined values:
Parameter | Value |
---|---|
<hub ID> | string parameter. IoT Hub ID |
<device ID> | string parameter. IoT Device ID |
<key> | string parameter, IoT Device Key |
#
6. Set MQTT TopicAT Command: AT+MQTTTOPIC
Syntax:
Type | Command | Response |
---|---|---|
Set | AT+MQTTTOPIC=<publish topic>,<subscribe topic>,<subscribe topic2>,<subscribe topic3> | OK |
Defined values:
Parameter | Value |
---|---|
<publish topic> | string parameter, topic where WizFi360 will publish |
<subscribe topic> | string parameter, topic where WizFi360 will subscribe |
<subscribe topic2> | string parameter, topic where WizFi360 will subscribe |
<subscribe topic3> | string parameter, topic where WizFi360 will subscribe |
Note:
- This command shall be set before connecting to broker.
- <subscribe topic2> & <subscribe topic3> are available in Firmware v1.0.5.0 and later.
#
7. Connect to AzureAT Command: AT+AZCON
Syntax:
Type | Command | Response |
---|---|---|
Set | AT+AZCON | CONNECT OK |
Note: • Before sending this ocmmand, AT+AZSET command & AT+MQTTTOPIC command shall be set. • After connection data can be sent to Azure server using AT+MQTTPUB command. • For more details please refer to https://docs.microsoft.com/en-us/azure/iot-hub/iot-hub-mqtt-support.
#
8. Publish a messageAT Command: AT+MQTTPUB
Syntax:
Type | Command | Response |
---|---|---|
Set | AT+MQTTPUB=<message> | OK |
Note: • This command shall be used when MQTT connection is established. • Topic where data will be published is set with AT+MQTTTOPIC command, user shall define topic before connecting to broker.
#
Running sample code#
Connect in serial terminal & code executionFor connection use following configuration in terminal: 115200-8-N-1, None.
#
WiFi setting#
1. Set Wifi station modeCommand | Response |
---|---|
AT+CWMODE_CUR=1 // station mode | OK |
#
2. Set DHCP EnableCommand | Response |
---|---|
AT+CWDHCP_CUR=1,1 // DHCP enable on Station mode | OK |
#
3. Get possible Wi-Fi AP List for connectionCommand | Response |
---|---|
AT+CWLAP | +CWLAP : (3,"ssid",-57,"mac address",1,1) // encryption method, ssid, rssi, mac address, channel, wps |
#
4. Connect to Wi-Fi APCommand | Response |
---|---|
AT+CWJAP_CUR="ssid","password" | WIFI CONNECTED WIFI GOT IP |
#
5. Query WizFi360 device' IP addressCommand | Response |
---|---|
AT+CIPSTA_CUR? | +CIPSTA_CUR:ip:”192.168.10.13” +CIPSTA_CUR:gateway:”192.168.10.1” +CIPSTA_CUR:network:”255.255.255.0” |
#
Connect to Azure services using next AT commands#
1. Set Azure connectionCommand | Response |
---|---|
AT+AZSET="iothub_name","device_id","device_key" | OK |
#
2. Set MQTT TopicCommand | Response |
---|---|
AT+MQTTTOPIC="/devices/{device_id}/messages/events/","/devices/{device_id}/messages/devicebound/#" Example AT+MQTTTOPIC="/devices/testDevice/messages/events/","/devices/testDevice/messages/devicebound/#" | OK |
Note: MQTT Topic follows the rules defined in Azure IoT Hub. Refer to document: Communicate with your IoT hub using the MQTT protocol: Using the MQTT protocol directly (as a device)
#
3. Connect to AzureCommand | Response |
---|---|
AT+AZCON | OK |
#
4. Publish dataCommand | Response |
---|---|
AT+MQTTPUB="{"deviceId":"WizFi360","temperature":28.16,"humidity":46.04}" | OK |
#
Results- Press "Start" button in Telemetry Section in IoT Hub Explorer.
"Start" button shall be pressed before sending data using MQTTPUB commands.
- Check data sent with MQTTPUB command.