5.3.5. IBM Watson Demo for KSDK

This demo demonstrates connection to IBM Watson IoT platform using pre-provisioned device credentials and publish/subscribe procedure using MQTT

5.3.5.1. Prerequisites

  • Active IBM Watson account

  • MCUXpresso installed (for running IBM demo on K64F)

  • Any Serial communicator

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

  • Refer to CLI Tool for ssscli tool setup

  • Build Plug & Trust middleware stack. (Refer Building / Compiling)

5.3.5.2. Using WiFi with LPC55S

WiFi shield CMWC1ZZABR-107-EVB by muRata is supported with LPCS55S. Mount the WiFi shield on to the mikroBUS stackable headers.

5.3.5.3. Setting up IBM Watson IoT Platform

  1. Create an IBM ID which enables you to create an service instance for the Watson IoT platform (https://idaas.iam.ibm.com/idaas/mtfim/sps/authsvc?PolicyId=urn:ibm:security:authentication:asf:basicldapuser)

  2. Create an instance of Internet of Things Platform in the Watson IoT after logging in.

  3. Register the Root CA certificate (and Intermediate CA certificates if applicable) by following the below link https://console.bluemix.net/docs/services/IoT/reference/security/set_up_certificates.html#set_up_certificates

    1. Click on ‘Launch’ button to access to the IoT dashboard

    2. Click on ‘Settings’ tab

    3. Click on ‘CA Certificates’

    4. Click on ‘Add Certificate’

    5. A new pop-up appears. Click on ‘Select a file’ option and select the certificate

    6. Click on ‘Save’

  4. Configure the security policies of the service by following steps

    1. Click on ‘Security’ tab

    2. Click on the pencil of ‘Connection Security’ to edit the preferences

    3. A new window is loaded, ‘Connection Security’. In the Security Level field, select ‘TLS with Client Certificate Authentication’.

    4. click on ‘Save’

  5. Register Device type

    1. In the service, Click on ‘Devices’ tab and ‘Device Types’

    2. Click on ‘Add device type.

    3. Select the ‘Device’ type and write a name. Device type shall be registered as ‘NXP-SE050-EC-D’ and Optionally, add a description.

    4. Click ‘Next’

    5. Optionally, add information to the rest of the fields. In this guide all the fields have been intentionally left empty. Finally, click ‘Done’.

    6. For more information, refer to https://console.bluemix.net/docs/services/IoT/ iotplatform_task.html#iotplatform_task

  6. Register device

    1. Click on ‘Devices’ tab.

    2. Click on ‘Add Device’

    3. In the ‘Identity’ tab, select as ‘Device Type’ the one created in ‘Register Device type’ and the ‘Device ID’ the one retrieved using the pycli tool (UID of the device)

    4. Click on ‘Next’ button

    5. Click Done button to create the device

  7. Configure the application.

    1. In the ‘watson_iot_config.h’ file, update the org details in the macro “WATSONIOT_MQTT_BROKER_ENDPOINT” which we get from the URL of the dashboard https://org_id.internetofthings.ibmcloud.com/dashboard/#/overview

    2. update the org details and UID of the device in the macro ‘WatsonechoCLIENT_ID’ which is available in ‘watson_iot_config.h’

  8. Configuring the publish application

    Create API key and authentication pair token

    1. In the Watson IoT Platform dashboard, go to Apps > API Keys.

    2. Click Generate API Key.

      Note

      Important: Make a note of the API key and token pair. Authentication tokens are non-recoverable. If you lose or forget this token, you will need to re-register the API key to generate a new authentication token.

      An example of an API key is a-organization_id-a84ps90Ajs

      An example of a token is MP$08VKz!8rXwnR-Q*

    3. Add a comment to identify the API key in the dashboard, for example: Key to connect my application.

    4. Click Finish

5.3.5.4. Creating and updating device keys and certificates to SE

  1. Complete Section 9.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 GenerateIBMCredentials.py <COM_PORT>
    python ResetAndUpdate_IBM.py <COM_PORT>
    

    Note

    Provisioning of the keys is done with default policies. Refer - Section 9.9 to change the scripts to add required policies.

  4. Certificates and Keys are generated at simw-top/pycli/Provisioning/ibm

5.3.5.5. Building the Demo

  1. Open cmake project found under <SIMW-TOP>projects in MCUXPRESSO IDE

  2. Update cmake options::
    • RTOS=FreeRTOS

    • mbedTLS_ALT=SSS

  3. Update the build target in make file
    • Project:cloud_ibm_watson

5.3.5.6. Running the Demo

  1. In the ‘watson_iot_config.h’ file, update the org details in the macro “WATSONIOT_MQTT_BROKER_ENDPOINT” which we get from the URL of the dashboard https://org_id.internetofthings.ibmcloud.com/dashboard/#/overview

  2. Update the org details and UID of the device in the macro ‘WatsonechoCLIENT_ID’ which is available in ‘watson_iot_config.h’

  3. In OrgDetails.cfg file, update the Org details which we got from the previous step in the ‘org’ section

  4. In OrgDetails.cfg file, update the auth-key which we got from the above sections in to the ‘auth-key’ section

  5. Upate the UID of the device in the application test.py (at Line 40)

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

  7. Connect your board to open network

  8. 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

  9. Press reset button on the board

  10. To see the event coming in to device and event going out of the device, login to the Watson IoT platform and launch the service: i) Click ‘Devices’ #) Click the registered device id #) Click ‘Recent Events’ #) Events will be displayed in portal

  11. Persistent RED LED ON indicates error

  12. All lights off along with the following message indicates readiness to subscribe messages fromAWS:

    Subscribing...
    -->sleep
    -->sleep
    Publish done
    
  13. Run the Publish application to publish events to the device.

    To do that, run:

    python test.py OrgDetails.cfg GREEN ON
    

    The above command ensures that the green LED is turned ON. Similarly RED and BLUE LED can be turned ON and OFF

  14. Events that are published shall be verified in the Watson Platform Dashboard(Refer to section 15)