Overview

Skill Level: Beginner

Beginner

PreparingGetting your device ready to connect to the IBM Watson IoT Platform.Add the microcontroller to the application board, the connect the application board to the internet by using an ethernet cable.Plug the microcontroller into your computer using a USB cable (be sure to connect the microcontroller, not the application board). A blue LED on the […]

Ingredients

mbed NXP LPC 1768 microcontroller

Application board containing:

  • Temperature sensor.
  • Accelerometer
  • Potentiometer
  • Joystick

Step-by-step

  1. Preparing

    Getting your device ready to connect to the IBM Watson IoT Platform.

    1. Add the microcontroller to the application board, the connect the application board to the internet by using an ethernet cable.
    2. Plug the microcontroller into your computer using a USB cable (be sure to connect the microcontroller, not the application board). A blue LED on the microcontroller lights up when it’s ready. Note: Windows users may need to install drivers. Advice is available in the mbed handbook.
    3. The microcontroller appears as a drive on your computer named mbed.
  2. Connecting to the IBM Watson IoT Platform Quickstart Service

    1. Navigate to the IBMIoTClientEthernetExample code repository.
    2. Click ‘Import this Program‘ on the right. It will import the porgram into the online compiler, you will need to sign in, or create an account.
    3. Within the online compiler, click ‘Compile‘ and save the bin file to the mbed drive. Wait for the blue LED to stop flashing before continuing. Note: Ensure the mbed LPC1768 target is selected on the right of the compile toolbar.
    4. Press the blue reset button on top of your microcontroller to run the downloaded program. The device will now run in Quickstart mode.
  3. Visualizing your data

    1. Note the device ID displayed on the LCD screen on the application board, you may need to use the joystick to scroll downwards on the display.
    2. Enter your device ID here.
  4. Register your Device In Watson IoT Platform

    To explore and make use of full capabilities of Watson IoT Platform, we need to setup and register your device(s) in it. This section shows how you can setup the same.

    Carry out the steps present in this recipe to register your device(s) in IBM Watson Internet of Things Platform.

    At this step, we have successfully created the Watson IoT service and registered your device(s) in it.

  5. Connecting to the IBM Watson IoT Platform Registered Service

    1. Once you have access to an IBM Watson IoT Platform organization through Bluemix or the Marketplace, you can click to ‘Add a new device’ on the IoT organization dashboard.
    2. During the device registration process you will get configuration information containing the following details, copy these when you get them.
      • Organization ID
      • Device Type
      • Device ID
      • Authentication Method
      • Authentication Token
    3. Within the online compiler, open the main.cpp file and ensure the value of “QUICKSTARTMODE” is set to 0, as can be seen below. Then replace the relevant parts from the following lines with the credentials you copied during registration.
          #define QUICKSTARTMODE 0    #define ORG "Replace with your org"    #define ID "Replace with your id"    #define TYPE "Replace with your type"    #define AUTH_METHOD "Replace with your auth-method"    #define AUTH_TOKEN "Replace with your auth-token"
    4. Click “Compile” and save the bin file to the mbed drive. Wait for the blue LED to stop flashing before continuing.

      Note: Ensure the mbed LPC1768 target is selected on the right-hand side of the compiler toolbar.

    5. Press the blue reset button on the top of your microcontroller to restart the program.

    The device will now run in registered mode.

  6. Command Support

    When an mbed device is running in registered mode you can send it commands from a Watson IoT application. By way of illustration, the sample code that you have loaded into the device supports a simple command that will make the device’s onboard LED blink at a specified rate.

    1. You can try this out by writing an application which connects to the Watson IoT and publishes a message to the device.
    2. The payload of this command message should be:
                          {            "rate":          }
    3. The device’s topic is: iot-2/type//id//cmd/blink/fmt/json

      Note: Sending a rate of 0 will cause the LED to stop blinking.

Join The Discussion