This application will demonstrate how to sent a device-to-cloud message from a WICED device to the Azure IoT Hub over HTTP.
Before running the app, you will need to have an Azure IoT Hub set up, and a device provisioned in the account.
- Create an account at https://azure.microsoft.com/
- Follow the instructions here (or below) to set up an IoT Hub in your account
- Log in to portal.azure.com
- On the left sidebar, select New -> Internet of Things -> IoT Hub
- Fill in the form and submit to create the IoT Hub. Deployment of the IoT Hub will take a few minutes.
- On your console dashboard, open the IoT Hub that was just created.
- Click on the key icon to open Shared Access Policies. Open the iothubowner policy and copy the connection string.
- Use the Device Explorer GUI (Windows only) to provision a device. Instructions; Download (scroll down to downloads)
Use the iothub-explorer command line utility (cross platform) to provision a device. Instructions
- Open Device Explorer and paste the connection string into the IoT Hub Connection String field and press update.
- Open the Management tab and create a device. Use your own device ID take note or the device ID if the Auto Generate ID option is selected.
- Use the Device Explorer or WICED functions to generate a SAS token.
Using Device Explorer Using WICED functions
- Select the SAS Token action
- Select the desired device and enter a TTL value.
- Generate the token
Psuedocode to generate SAS:
stringtosign = resourceURI + '\n' + expiryTimeInUTCsecs
signedstring = base64(hmacsha265(stringtosign,secretkey))
snprintf(SAS,length, "SharedAccessSignature sr=%s&sig=%s&se=",URIencode(resourceURI),URIencode(signedstring),expiryTimeInUTCsec)
Configuring WICED app:
- Download the attached .zip file and extract into apps/snip.
- Modify wifi_config_dct.h with credentials for your WiFi AP.
- Modify the HUBNAME, DEVICENAME, and SASTOKEN fields with credentials from your Azure IoT Hub.
The SAS token has the format: SharedAccessSignature sr=<devicehubname>.azure-devices.net%2fdevices%2f<deviceid>&sig=<signature>&se=<expiry>
- As of SDK 3.7.0, TLS v1.1 is needed to connect to IIS servers. This workaround is temporary and should be patched in the next SDK release.
Open the file <WICEDSDK>/WICED/security/BESL/host/WICED/tls_cipher_suites.c
tls_version_num_t tls_maximum_version = TLS1_2;
tls_version_num_t tls_maximum_version = TLS1_1;
- Compile and run the app with the target "snip.azure_https_client-<platform> download run"
- Open Device Explorer to the "Data" tab and start monitoring for data
follow the instructions for iothub-explorer to monitor device-to-cloud messages
Device Messaging REST API documentation can be found here: Device Messaging REST APIs
azure_https_client.zip 6.0 K