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.

Configuring Azure:

  1. Create an account at https://azure.microsoft.com/
  2. 1.PNG
  3. Follow the instructions here (or below) to set up an IoT Hub in your account
    1. Log in to portal.azure.com
    2. On the left sidebar, select New -> Internet of Things -> IoT Hub
    3. Fill in the form and submit to create the IoT Hub. Deployment of the IoT Hub will take a few minutes.
    4. On your console dashboard, open the IoT Hub that was just created.
    5. Click on the key icon to open Shared Access Policies. Open the iothubowner policy and copy the connection string.
  4. 2.1.PNG
    3.PNG
  5. Use the Device Explorer GUI (Windows only) to provision a device. Instructions; Download (scroll down to downloads)
    or
    Use the iothub-explorer command line utility (cross platform) to provision a device. Instructions
    1. Open Device Explorer and paste the connection string into the IoT Hub Connection String field and press update.
    2. 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.
  6. Use the Device Explorer or WICED functions to generate a SAS token.
    Using Device ExplorerUsing WICED functions
    1. Select the SAS Token action
    2. Select the desired device and enter a TTL value.
    3. 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)

  7. 4.PNG5.PNG6.PNG

 

Configuring WICED app:

  1. Download the attached .zip file and extract into apps/snip.
  2. Modify wifi_config_dct.h with credentials for your WiFi AP.
  3. 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>
  4. 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
    Change

    tls_version_num_t tls_maximum_version = TLS1_2;

    To

    tls_version_num_t tls_maximum_version = TLS1_1;

  5. Compile and run the app with the target "snip.azure_https_client-<platform> download run"
  6. Open Device Explorer to the "Data" tab and start monitoring for data
    or
    follow the instructions for iothub-explorer to monitor device-to-cloud messages
  7. 7.PNG8.1.PNG


Device Messaging REST API documentation can be found here: Device Messaging REST APIs