Contents


Overview

Skill Level: Any Skill Level

This recipe will help you connect TE Connectivity digital sensors on a Raspberry Pi , send measures using MQTT protocol on IBM Watson Platform and display measurements with Bluemix application

Ingredients

For this reciepe you need :

  • A Raspberry Pi 2 or 3 with the latest official Debian image running
  • A TE Connectivity Pi Weather Shield
  • A Bluemix account with organization and space

 

Step-by-step

  1. Create an Internet of Things Platform Starter Application

    0001

    • Now select Internet of Things Platform

    0003

    • Click the Create button

    0004

    Now you've got your instance

  2. Connect to Watson Plateform

    • Click on Lauch Dashboard

    0005

    • You will be¬†redirected to the IBM Watson Plateform

    Capture_2

    Observe that a new Organization is created where you can add, connect and manage IoT devices.

    At this step, we have successfully created the IBM Watson IoT Platform organization.

  3. Configure Watson Plateform

    Add device type

    Each device connected to the IBM Watson IoT Platform is associated with a device type. Device types are intended to be groups of devices which share common characteristics. So in order to add devices in IBM Watson IoT Platform, one need to create a device type. Following are the instructions for creating a Device Type.

    • Go back to the IBM Watson IoT Platform dashboard, click Devices tab, device types tab, then click on the Create Type button as shown below

    • Click on Create device type

    • Specify a name for the device type to be added and optionally a description as shown below and click next

    00081

    Observe that a template page is given where you can select and define one or more attributes. All of these attributes are optional. They will be used as a template for new devices that are assigned this device type. Attributes that you do not define may still be edited individually later when you add the device. You can define one or more attributes by selecting them and clicking Next as shown below

    • Define the selected attributes Manufacturer and Model as shown below, then click next

    • ¬†Observe that a new device type is added in the IBM Watson IoT Platform Organization

    We have successfully created a device type in IBM Watson IoT Platform organization.

     

     

     

    Add device

    A device can be defined that has a connection to the internet and has data it wants to get into the cloud. And devices can accept commands from applications as well. You need to add the device in IBM Watson IoT Platform Organization before connecting it to the IoT. Carry out the following steps to add the device in IBM Watson IoT Platform

     

    • In the IBM Watson IoT Platform dashboard, click Browse tab and then Add Device button as shown below

    • Choose the device type ‚ÄúRaspberryPi‚ÄĚ that we created in the last step, then click Next

    00083

    • Enter a unique device id, which will distinguish your device from all other devices that you might connect to the IoT (you can use 1 or something more sophisticated like your devices MAC address, without “:”), then click Next as shown below. Also note that the values of ‚ÄúManufacturer‚ÄĚ and ‚ÄúModel‚ÄĚ attributes are populated from the device type ‚Äúiotsample-devicetype‚ÄĚ. These values can be overridden, attributes not set in the device type can be added as well

    00084

    • Add a Metadata and click next (it's optional)
    • Click on next, the token will be generated automatically
    • As shown below, you will be given a summary page to verify the details before adding the device to IBM Watson IoT Platform. Verify and click Add
    • At this step, the device is registered to your Organization and you will be provided with the registration details as marked below. To get your device connected, you need to add the credentials to your device.

    Conserve the Device Crentials because you will not be able to retrieve this information later !!

    00086

    • ¬†Click the cross button to get back to the main dashboard and observe that the device is added in your Organization

    00087

     

    Now we have successfully added a device in the IBM Watson IoT Platform organization.

     

    Generate API Keys

    To give external applications (i.e., the Node-RED application described later) access to your organization, you need to generate API access key/token pairs. Once pair in enough for this demo. To do so, follow these steps:

    • In Watson IoT Platform dashboard, select Access from the left pane, select API Keys and click on +Generate API Keys

    • A window appear with the API Key and the Authentification Token

    Like the Device Crentials, you need to conserve this information since you won't be able to recover it later !

     

    The first step is finish you have all informations to connect your Raspberry PI to Bluemix.

  4. Raspberry Pi setup

    • Open a terminal session on your Raspberry Pi (though SSH or directly from the Pi)
    • Install pip
    sudo apt-get install python-pip
    • Install the IBM IoT and Pi Weather Shield pip packages
    sudo pip install ibmiotf
    sudo pip install pi-weather-shield
    git clone https://github.com/TEConnectivity/piweathershield-ibm-watson-iot-python.git
    cd piweathershield-ibm-watson-iot-python
    • Create the device configuration file
    cp sample-device.cfg mydevice.cfg
    nano mydevice.cfg
    [device]org=ydxo1w
    type=RaspberryPi
    id=b827eb7e7bc0
    auth-method=token
    auth-token=qmn-mewxN3&5NCRcZ) 
    domain=internetofthings.ibmcloud.com
    • You can now run the software for this device
    python ibm-watson-iot-demo.py -v -c mydevice.cfg

    The software will measure all the sensors and push their data to the IBM Cloud every seconds

  5. Node -RED GUI installation

    0023

    • Provide an app name¬†at your convenience and Deploy
    • The deployment can take several minutes

    0014

    • Once successful you can “View Your App”

    0015

    • This will open the Node-RED application in your brower

    00231

    • You can now click on¬†Go to your Node-RED flow editor
  6. Node -RED GUI configuration

    • Node-RED comes with a pre-configured flow for the Raspberry Pi Weather Shield

    0024

    • Note that the IBM IoT provider is disconnected from our Raspberry Pi

    00161

    • We will now need to connect it to our Raspberry Pi
    • Double on the IBM IoT to configure it

     

    • Select Authentication with API Key then¬†Add¬†Aew ibmiot

    0018

     

    • Insert the API Key and API Token you previously generated

    0019

     

    • Finally, specify your Device Type, Device Id and Event

    0020

     

    • You can now Deploy your flow

    0021

     

    • And visualize it through the dashboard tab

    00212

     

    • ¬†Enjoy your live data visualization !

     0022

Join The Discussion