5.9. Azure Demo for KSDK

This demo demonstrates connection to Azure IoTHub using pre-provisioned device credentials and demonstrates publish/subscribe procedure using MQTT.

5.9.1. Prerequisites

  • Active azure account with iot hub created

  • MCUXpresso installed (for running azure demo on k64)

  • Any Serial communicator

  • Flash VCOM binary on the device. VCOM binary can found under <PROJECT>/binaries folder.

  • Refer to CLI Tool for pyCLI tool setup

5.9.2. Using WiFi with LPC55S

WiFi shield Silex-2401 is supported with LPCS55S. Mount the WiFi shield on to the arduino stackable headers.

5.9.3. Creating a device on azure IoT Hub portal

  1. Navigate to the Dashboard –> <Your IoT Hub> –> “IoT Devices”

  2. Add a new device (e.g. device1), and for its authentication type choose X.509 CA Signed

    Note

    Creating a new device For large deployment of device, creating a device on azure iot hub can be done using Azure IoT service SDK

5.9.4. Creating and updating device keys and certificates to SE

  1. Complete Section 7.3 Steps needed before running ssscli tool

  2. Check the vcom port number

  3. To create certificates on windows and provision, go to simw-top/pycli directory and call:

    call venv\Scripts\activate.bat
    cd Provisioning
    python GenerateAZURECredentials.py <COM_PORT>
    python ResetAndUpdate_AZURE.py <COM_PORT>
    
  4. Certificates and Keys are generated at simw-top/pycli/Provisioning/azure

5.9.5. Uploading root certificates to IoT Hub

  1. On Azure IoT Hub portal, Navigate to Dashboard --> <Your IoT Hub> --> Certificates. Click on Add

  2. Enter a friendly name and upload the root certificate created in the previous step. Location - simw-top/pycli/Provisioning/azure/RootCA.cer -> Save

  3. Your certificate will show in the Certificate Explorer list. Click on certificate added

  4. In Certificate Details, click Generate Verification Code

  5. The provisioning service creates a Verification Code that you can use to validate the certificate ownership. Copy the code to your clipboard

  6. Use the verification_certificate.py to generate a verify certificate (verifyCert4.cer)

    cd simw-top/pycli/Provisioning
    python verification_certificate.py <RootCA_Certificate> <RootCA_Keypair> <Verification Code>
    
  7. On Azure portal -> Certificate Details, upload the verifyCert4.cer file generated and click Verify.

    STATUS of your certificate should change to Verified in the Certificate Explorer list

5.9.6. Running the Demo

  1. Open frdmk64f_mbedtls_sss_azure_demo project found under <PROJECT>projects in MCUXPRESSO IDE

  2. Update AZURE_IOT_HUB_NAME and AZURE_DEVICE_NAME in <PROJECT>\demo\azure_demo\azure_iot_config.h with your details

  3. Build the project and flash the binary on FRDM-K64F board

  4. Connect your board to open network

  5. Open a serial terminal on PC for OpenSDA serial device with these settings
    • 115200 baud rate

    • 8 data bits

    • No parity

    • One stop bit

    • No flow control

    • change Setup->Terminal->New-line->Receive->AUTO

  6. Console Output

  • Press reset button on the board If everything is setup correctly, the output would be as follows:

    ,----
    |
    | Connecting to network
    | Getting IP address from DHCP ...
    |
    | IPv4 Address     : 192.168.0.68
    | DHCP OK
    | MQTT attempting to connect to 'dev2'...
    |
    | Signing using key lX
    | MQTT Echo demo subscribed to devices/dev2/messages/devicebound/#
    | -->sleepEcho successfully published
    | Echo successfully published
    | -->sleepEcho successfully published
    | Echo successfully published
    |
    |   ...
    |   ...
    |
    `----
    
  • You can use device explorer tool to control the on-board LEDs. Open device explorer tool and update the IoT Hub connection string to connect to azure IoT hub, IoT Hub connection string is found at Azure IoT Hub -> Shared access policies -> iothubowner -> Connection String Primary key

  • In the “Message To Devices” tab, select the device and send the message as:

    ,----
    | {"green": "toggle"}, {"green": "on"}, {"red": "off"}
    `----
    

5.9.7. Appendix

  1. for more inforation, refer to https://docs.microsoft.com/en-us/azure/iot-hub/iot-hub-mqtt-support