This repo shows sample code for connecting the Wio Terminal to Azure IoT Hub. This uses the Azure Arduino SDK.
This code connects to IoT Hub, then sends telemetry in the loop
function. It also listens to direct method requests.
The IoT Hub code runs single-threaded, so you need to call IoTHubDeviceClient_LL_DoWork(_device_ll_handle)
to process messages from IoT Hub. Instead of a long delay
in the loop
function, this code shows how to implement a long delay as lots of short delays with calls to IoTHubDeviceClient_LL_DoWork
.
When your device connects, part of the internal connection logic uses the current time to build a key. This means the device time has to be correct, and this is implemented in the ntp.h
file, with code to get the current time from an NTP server and set it on the Wio Terminals RTC.
- Create an Azure IoT Hub
- Create a device and get the connection string
- Open this folder in VS Code using the PlatformIO extension
- Set the
CONNECTION_STRING
constant inconfig.h
in thesrc
folder to the device connection string - Set the
SSID
andPASSWORD
constants inconfig.h
in thesrc
folder to the relevant values for your WiFi - Build and deploy to your Wio Terminal using PlatformIO
If you are using the Arduino IDE, you can copy the
main.cpp
code into your sketch file, and add the other files in thesrc
folder into your sketch folder. You will need to choose the Wio Terminal in the board manager and add the following libraries using the library manager:
- bblanchon/ArduinoJson
- seeed-studio/Seeed Arduino rpcWiFi
- seeed-studio/Seeed Arduino FS
- seeed-studio/Seeed Arduino SFUD
- seeed-studio/Seeed Arduino rpcUnified
- seeed-studio/Seeed_Arduino_mbedtls
- seeed-studio/Seeed Arduino RTC
- arduino-libraries/AzureIoTHub
- azure/AzureIoTUtility
- azure/AzureIoTProtocol_MQTT
- azure/AzureIoTProtocol_HTTP
- azure/AzureIoTSocket_WiFi