Overview

Skill Level: Any Skill Level

Beginner interested in a fast overview of the STM32 Discovery Kit IoT Node usage with IBM Watson with notes for more advanced users on how to start coding using this starter kit

This recipe shows how to program the STM32L4 Discovery Kit IoT Node in order to periodically:

1. sample the sensor data
2. publish the values on-the-fly over WiFi to the IBM Watson IoT platform
3. visualize them live on the Quickstart web page

Ingredients

  • STM32L4 Discovery Kit IoT Node: B-L475E-IOT01A1
  • Windows 7/8/10 Laptop. Mac or Linux also supported with limited IDE Choice.
  • USB type A to Micro-B USB cable to supply the power to the IoT Node, and to program it from a PC
  • 2.4GHz b/g/n WiFi access point connected to the Internet (accessible via SSID/Password)

telemetry_flow

Step-by-step

  1. Get one IoT Node

    It can be purchased in one click from the board homepage: B-L475E-IOT01A1

  2. Connect the IoT Node to your PC

    1. Download and install STSW-LINK004 from ST (this step is required for Windows 7 users)
    2. Connect the IoT node STLINK USB to a PC USB 2.0 port using a USB type A to Micro-B USB cable.
    3. Install a terminal emulator (e.g. Tera Term) and open the virtual serial port to which your device is connected. You will use it to visualize the log messages of the IoT Node and configure it interactively in a later step.

     

    Configure the serial terminal with the following parameters:

    Baud rate 115200
    Data 8 bit
    Parity none
    Stop 1 bit
    Flow Control none
    New line Receive LF
    New line Transmit LF

     

    You may also want to enable the local echo.

  3. Download the software bundle

    Download and unzip the IBM IoT cloud software expansion package for STM32Cube (X-CUBE-WATSON), which includes drivers, middleware, application code and project files compatible with three different development environments: IAR Embedded Workbench for ARM, Keil Embedded Development Tools for ARM, and System Workbench for STM32.

    Here is the folder tree that you should see after unzipping:

    Folder_projects

  4. Flash the application

    You can take advantage of the IoT Node being exposed to the PC OS as a USB mass storage and copy the pre-compiled file Projects/B-L475E-IOT01A/Applications/Cloud/Bluemix/Binary/B-L475E-IOT01_Cloud_WATSON_V1.0.0.bin to the DIS_L4IOT drive. This will flash the new binary on the target MCU.

    Alternatively, you may choose your preferred development environment and open the corresponding project from the folder Projects/B-L475E-IOT01A/Applications/Cloud/Bluemix/. Build the sample application and flash it to the STM32 IoT Node.

  5. Connect to Watson in Quickstart mode

    Once the embedded application is flashed and the virtual terminal is connected to the device, reset the IoT Node by pushing the black button, and see the log messages and dialogs on the terminal.

    Note: The bold text below denotes the user input on the virtual terminal. The optional terminal echo is not displayed.

    Upon request, insert the WiFi SSID, security mode and password of your WiFi network.

     

    *** WIFI connection ***

    Your WiFi parameters need to be entered to proceed.

    Enter SSID:
    Enter Security Mode (0 - Open, 1 - WEP, 2 - WPA, 3 - WPA2):
    Enter password:

     

    Upon request, specify the root certificates to be used by the application by pasting the contents of Projects\Common\Bluemix\comodo_bluemix.pem to the terminal. You may have to validate your input by typing the carriage return key.

     

    Initializing the WiFi module
    Module initialized successfully: Inventek eS-WiFi ISM43362-M3G-L44-SPI XXXXXX
    Retrieving the WiFi module MAC address: xx:xx:xx:xx:xx:xx

    Connecting to AP: xxxxxxxx  Attempt 1/3 ...
    Connected to AP xxxxxxxx
    Mac address: xx:xx:xx:xx:xx:xx
    Retrieving the IP address.
    IP address: xxx.xxx.xxx.xxx

    Updating TLS security credentials.

    Enter the x509 certificates or keys as per the following format:
    -----BEGIN CERTIFICATE-----
    YMPGn8u67GB9t+aEMr5P+1gmIgNb1LTV+/Xjli5wwOQuvfwu7uJBVcA0Ln0kcmnL
    R7EUQIN9Z/SG9jGr8XmksrUuEvmEF/Bibyc+E1ixVA0hmnM3oTDPb5Lc9un8rNsu
    .......
    -----END CERTIFICATE-----
    -----BEGIN CERTIFICATE-----
    YMPGn8u67GB9t+aEMr5P+1gmIgNb1LTV+/Xjli5wwOQuvfwu7uJBVcA0Ln0kcmnL
    .......
    -----END CERTIFICATE-----
    \n.......

    Enter your root CA:
    -----BEGIN CERTIFICATE-----
    MIIF2DCCA8CgAwIBAgIQTKr5yttjb+Af907YWwOGnTANBgkqhkiG9w0BAQwFADCB
    hTELMAkGA1UEBhMCR0IxGzAZBgNVBAgTEkdyZWF0ZXIgTWFuY2hlc3RlcjEQMA4G
    A1UEBxMHU2FsZm9yZDEaMB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czL+zUdqnR+WEUwIDAQABo0IwQDAdBgNVHQ4E
    FgQUu69+Aj36pvE8hI6t7jiY7NkyMtQwDgYDVR0PAQH/BAQDAgEGMA8GA1UdEwEB
    /wQFMAMBAf8wDQYJKoZIhvcNAQEMBQADggIBAArx1UaEt65Ru2yyTUEUAJNMnMvl
    wFTPoCWOAvn9sKIN9SCYPBMtrFaisNZ+EZLpLrqeLppysb0ZRGxhNaKatBYSaVqM
    4dc+pBroLwP0rmEdEBsqpIt6xf4FpuHA1sj+nq6PK7o9mfjYcwlYRm6mnPTXJ9OV
    2jeDchzTc+CiR5kDOF3VSXkAKRzH7JsgHAckaVd4sjn8OoSgtZx8jb8uk2Intzna
    FxiuvTwJaP+EmzzV1gsD41eeFPfR60/IvYcjt7ZJQ3mFXLrrkguhxuhoqEwWsRqZ
    CuhTLJK7oQkYdQxlqHvLI7cawiiFwxv/0Cti76R7CZGYZ4wUAc1oBmpjIXUDgIiK
    boHGhfKppC3n9KUkEEeDys30jXlYsQab5xoq2Z0B15R97QNKyvDb6KkBPvVWmcke
    jkk9u+UJueBPSZI9FoJAzMxZxuY67RIuaTxslbH9qh17f4a+Hg4yRvv7E491f0yL
    S0Zj/gA0QHDBw7mh3aZw4gSzQbzpgJHqZJx64SIDqZxubw5lT2yHh17zbqD5daWb
    QOhTsiedSrnAdyGN/4fy3ryM7xfft0kL0fJuMAsaDk527RH89elWsn2/x20Kk4yl
    0MC2Hb46TpSi125sC8KKfPog88Tk5c0NqMuRkrF8hey1FGlmDoLnzc7ILaZRfyHB
    NVOFBkpdn627G190
    -----END CERTIFICATE-----
    -----BEGIN CERTIFICATE-----
    MIIDrzCCApegAwIBAgIQCDvgVpBCRrGhdWrJWZHHSjANBgkqhkiG9w0BAQUFADBh
    MQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3
    d3cuZGlnaWNlcnQuY29tMSAwHgYDVQQDExdEaWdpQ2VydCBHbG9iYWwgUm9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fv1C5qfPrmAESrciIxpg0X40KPMbp1ZWVbd4=
    -----END CERTIFICATE-----

     

    Upon request, choose the registration mode to the Watson IoT platform: Quickstart.

    If you want to use another registration mode (which would allow a secure connection or device management features, please refer to the X-CUBE-WATSON package User Manual UM2273: Getting started with X-CUBE-WATSON IBM® IoT cloud software expansion for STM32Cube).

     

    Enter Registration Mode (1 - Quickstart, 2 - Simple):
    1

     

    Then, choose a DeviceId, which will identify the device when you are to visualize the data in real time on the Quickstart web page. Be careful, it must be unique.

    The DeviceType value does not matter in Quickstart mode.

     

    You have selected the Quickstart registration mode.
     
    Enter the Bluemix connection string of your device: (template: DeviceType=xxx;DeviceId=xxx)
    DeviceType=doesnotmatter;DeviceId=myIotNode
    Setting the RTC from the network time.
    Configuring the RTC from Date: xxx, xx xxx xxxx xx:xx:xx GMT
    Device Client Connected to quickstart.messaging.internetofthings.ibmcloud.com Platform in QuickStart Mode

    You can see your published data at https://quickstart.internetofthings.ibmcloud.com
    Device Id is myIotNode

    When user button is pushed shortly, application publishes the sensor values, a 0/1 toggle value (the green Led switches accordingly) and a timestamp
    On double button push, application enters in a loop and publishes automatically every second. Next double push returns to previous mode

     

    Now, follow the instructions displayed and push the blue (user) button of the IoT node to start publishing telemetry data.

  6. Visualize your data

    You can reach your live data at https://quickstart.internetofthings.ibmcloud.com by filling the form with your DeviceId, or directly at https://quickstart.internetofthings.ibmcloud.com/#/device/myIotNode/sensor/, provided that you customize the URL according to your DeviceId.

    Quickstart_page-1

     

     

    The plotted value can be selected by clicking the event line of your choice (for example, click on the line with acc_x to plot acc_x values).

1 comment on"Connect an STM32L4 Discovery Kit IoT Node to IBM Watson IOT"

  1. hi
    iam so happy to join this discussion about ibm cloud

Join The Discussion