This content is no longer being updated or maintained. The content is provided “as is.” Given the rapid evolution of technology, some content, steps, or illustrations may have changed.
Skill Level: Beginner
N.B: All services used in this repo are Lite plans.
Create a basic conveyor belt with an IoT device that sends monitoring data to Watson IoT Platform on IBM Cloud
This guide steps you through the process of connecting devices to Watson IoT Platform, monitoring and acting on device data
We set up a connected conveyor belt and use it to send IoT data to Watson IoT Platform. Depending on your skill level, you can follow one or both of the following paths to set up your conveyor belt:
- Path A
This path gets you started quickly by installing a conveyor belt simulator app on IBM Cloud. The app self-registers a device with Watson IoT Platform and automatically sends well-formatted data to the platform. Instructions for this path are in Step 2A - Use the simulator sample app from GitHub. - Path B
This path is technically more challenging and requires additional hardware, Python programming skills, and manual registration of your device with Watson IoT Platform. Instructions for this path are in Step 2B - Build a physical conveyor belt with a Raspberry Pi and an electric motor.
As part of this guide, you will:
- Create and deploy a Watson IoT Platform organization by using Cloud Foundry CLI.
- Build and deploy a sample conveyor belt device.
- Connect the simulated conveyor belt device to Watson IoT Platform.
- Monitor and visualize device data by using the Watson IoT Platform dashboards.
To get started with Watson IoT Platform using a different IoT device, see the Getting started tutorial.
- Create & Deploy Watson IoT Platform on IBM Cloud
- Build & Deploy Simulated Sample Conveyor
- Connect the conveyor belt to the Watson IoT Platform
- Monitor & Visualize device data on the Watson IoT dashboard.
Click here to view the IBM Pattern for this project.
You will need the following accounts and tools:
- IBM Cloud account
- Bluemix CLI
- Optional: Git If you choose to use Git to download the code samples you must also have a GitHub.com account. You can also download the code as a compressed file without a GitHub.com account.
- Optional: A mobile phone on which to run the Conveyor belt sample web application to send accelerometer data.
If you want to deploy directly to IBM Cloud, click on Deploy to IBM Cloud
button below to create a IBM Cloud DevOps service toolchain and pipeline for deploying basic conveyor belt with an IoT device that sends monitoring data to Watson IoT Platform on IBM Cloud, else jump to Steps
After deploying the application, please continue with Step 3 - See raw data in Watson IoT Platform.
-
Do one of the following 2 steps:
Watson IoT Platform provides powerful application access to IoT devices and data to help you rapidly compose analytics applications, visualization dashboards, and mobile IoT apps. The steps that follow will deploy an instance of the Watson IoT Platform service with the name
iotp-for-conveyor
in your IBM Cloud environment. If you already have a service instance running, you can use that instance with the guide and skip this first step. Just make sure that you use the correct service name and IBM Cloud space when you proceed through the guides.
- From the command line, set your API endpoint by running the
bx api
command.
Replace theAPI-ENDPOINT
value with the API endpoint for your region.
bx api <API-ENDPOINT>
Example: bx api https://api.ng.bluemix.net
Region | API Endpoint |
---|---|
US South | https://api.ng.bluemix.net |
United Kingdom | https://api.eu-gb.bluemix.net |
- Log into your IBM Cloud account.
bx login
If prompted, select the organization and space where you want to deploy Watson IoT Platform and the sample app. Note example a) org: lbenn@us.ibm.com b) space = dev
- Deploy the Watson IoT Platform service to IBM Cloud.
bx create-service iotf-service iotf-service-free YOUR_IOT_PLATFORM_NAME
For YOUR_IOT_PLATFORM_NAME
, use iotp-for-conveyor.
Example: bx create-service iotf-service iotf-service-free iotp-for-conveyor
Next, you will create a sample conveyor belt device. Choose which path you want to take:
- Path A: Step 2A - Use the simulator sample app from GitHub.
- Path B: Step 2B - Build a physical conveyor belt with a Raspberry Pi and an electric motor.
The sample app lets you simulate a IBM Cloud connected industrial conveyor belt. You can start and stop the belt and adjust the speed of the belt. Every change to the belt is sent to IBM Cloud in the form of an MQTT message that is displayed in the app. You can monitor the belt behavior by using the default dashboard cards. The sample app is built using the Node.js client libraries at: https://github.com/ibm-watson-iot/iot-nodejs
- From the guide-conveyor-simulator directory, push your app to IBM Cloud and give it a new name by replacing
YOUR_APP_NAME
in the bx push command. Use the--no-start
option because you will start the app in the next stage after it is bound to Watson IoT Platform.
Note: Deploying your application can take a few minutes.
bx app push YOUR_APP_NAME --no-start
- In the guide-conveyor-simulator directory, bind your app to your instance of the Watson IoT Platform by using the names that you provided for each.
bx bind-service YOUR_APP_NAME iotp-for-conveyor
For more information about binding applications, see Connecting applications.
- Start your application for the binding to take effect.
bx start YOUR_APP_NAME
At this stage, your sample web application is deployed on IBM Cloud. When deployment is completed, a message is displayed to indicate that your app is running. Example:
name: YOUR_APP_NAME
requested state: started
instances: 1/1
usage: 64M x 1 instances
routes: YOUR_APP_NAM.mybluemix.net
last uploaded: Tue 09 May 09:29:49 EDT 2017
stack: cflinuxfs2
buildpack: SDK for Node.js(TM) (ibm-node.js-4.8.0,
buildpack-v3.11-20170303-1144)
start command: ./vendor/initial_startup.rb
state since cpu memory disk details
#0 running 2017-05-09T13:35:08Z 0.0% 19.6M of 64M 66.2M of 256M
Troubleshoot errors in the deployment process by using the
bx app logs YOUR_APP_NAME --recent
command.
-
In a browser, access the app.
Open the following URL:https://YOUR_APP_NAME.mybluemix.net
Example:https://conveyorbelt.mybluemix.net/
. -
Enter a device ID and token for your device.
The sample app automatically registers a device of typeiot-conveyor-belt
with the device ID (e.g. my-first-device) and token that you provided. For more information about registering devices, see Connecting devices.
- Continue with Step 3 - See raw data in Watson IoT Platform.
The Raspberry Pi solution is built using the Python client libraries at: https://github.com/ibm-watson-iot/iot-python
The following connections between the Raspberry Pi and the L298N Dual H Bridge Motor Driver Board are required. Connect:
- Pin 2 of the Raspberry Pi to +5v on the L298N board
- Pin 6 of the Raspberry Pi to GND on the L298N board
- Pin 13 of the Raspberry Pi to the IN1 of the L298N board
- Pin 15 of the Raspberry Pi to the IN2 of the L298N board
- +9v of the battery to +12v on the L298N board
- -9v of the battery to GND on the L298N board
- The +ve node of the motor to OUT1 on the L298N board
- The -ve node of the motor to OUT2 on the L298N board
- Raspberry Pi(2/3) with Raspbian Jessie (8.x).
- L298N Dual H Bridge Motor Driver Board
- 9V DC motor
- 9V Battery
- Python 2.7.9 and above, installed with Raspbian Jessie (8.x).
- Watson IoT Python library
- Optional: Git.
If you do not have git installed on your Raspberry Pi, you can install it by using the following command:
$ sudo apt-get install git
- Open the terminal or SSH to your Raspberry Pi.
- Use your favorite git tool to clone the following repository to your Raspberry Pi:
https://github.com/ibm-watson-iot/guide-conveyor-rasp-pi In Git Shell, use the following command:
$ git clone https://github.com/ibm-watson-iot/guide-conveyor-rasp-pi
-
Register the device with Watson IoT Platform. For more information about registering devices, see Connecting devices.
- In the IBM console, click Launch other Watson IoT Platform service details page. The Watson IoT Platform web console opens in a new browser tab at the following URL:
Where
https://ORG_ID.internetofthings.ibmcloud.com/dashboard/#/overview
ORG_ID
is the unique six character ID of your Watson IoT Platform organization. - In the Overview dashboard, from the menu pane, select Devices and then click Add Device.
- Create a device type for the device that you are adding.
- Click Create device type.
- Enter the device type name
iotp-for-conveyor
and a description for the device type.
Note: You can enter any device type name, but the other guides in the series expect devices that use the device type
iotp-for-conveyor
. If you use a different device type, you must modify the settings in the other guides accordingly.- Optional: Enter device type attributes and metadata.
- Click Next to begin the process of adding your device with the selected device type.
- Enter a device ID, for example,
conveyor_belt
. - Click Next to complete the process.
- Provide an authentication token or accept an automatically generated token.
- Verify the summary information is correct and then click Add to add the connection.
- In the device information page, copy and save the following details:
- Organization ID
- Device Type
- Device ID
- Authentication Method
- Authentication Token. You'll need the values for the Organization ID, Device Type, Device ID, and Authentication Token to configure your device to connect to Watson IoT Platform.
- In the IBM console, click Launch other Watson IoT Platform service details page. The Watson IoT Platform web console opens in a new browser tab at the following URL:
-
Navigate to the guide-conveyor-rasp-pi root of the cloned repository.
-
Make the shell script executable by using this command
sudo chmod +x setup.sh
-
Run the setup.sh file and enter the details that you copied from the device information page when prompted.
./setup.sh
- Run the deviceClient program.
When you run the program, your Raspberry Pi starts the motor and it will run for up to 2 minutes based on parameter settings.
python deviceClient.py -t 2
While the motor is running, the program publishes events of event type sensorData
that have the following sample payload structure:
{
"d": {
"elapsed": 1,
"running": true,
"temperature": 35.00,
"ay": "0.00",
"rpm": "0.6"
}
}
- Continue with Step 3 - See raw data in Watson IoT Platform.
-
Verify that the device is registered with Watson IoT Platform.
- Login to your IBM dashboard at: https://bluemix.net
- From your list of services, click the iotp-for-conveyor Watson IoT Platform service.
- Click Launch to open the Watson IoT Platform dashboard in a new browser tab.
You can bookmark the URL for easy access later.
Example:https://*iot-org-id*.internetofthings.ibmcloud.com
. - From the menu, select Devices and verify that your new device is displayed.
-
View raw data
- From the menu, select Boards.
- Select the Device Centric Analytics board.
- Locate the Devices I Care About card and select your device.
The device name is displayed in the Device Properties card.
-
Send sensor data to the platform.
The device sends data to Watson IoT Platform when sensor readings change. You can simulate this data sending by stopping, starting or changing the speed of the conveyor belt.
Path A: If you are accessing the app on a mobile browser, try shaking your smart phone to trigger accelerometer data for the conveyor belt.
- Verify that the updated device data points that correspond to the published message are displayed in the Device Properties card.
Message example A:
{
"d": {
"id": "belt1",
"ts": 1494341288662,
"ay": "0.00",
"running": true,
"rpm": "0.6"
}
}
Message example B:
{
"d": {
"elapsed": 1,
"running": true,
"temperature": 35.00,
"ay": "0.00",
"rpm": "0.6"
}
}
To create a dashboard card to see live conveyor belt data:
- On the same Device Centric Analytics board, click Add New Card and then select Line Chart.
- For card source data, click Cards.
A list of card names is displayed. - Select Devices I Care About and then click Next.
- Click Connect new data set and enter the following values for the data set parameters:
- Event: sensorData
- Property: d.rpm
- Name: Belt RPM
- Type: Float
- Unit: rpm
- Click Next.
- On the card preview page, select L, and then click Next.
- On the card information page, change the name of the title to
Belt data
and then click Submit. - Change the speed of your belt to see live data in your new card.
- Optional: Add a second data set to add acceleration data for the belt.
If you use your phone to connect to the sample app, you can shake the phone to send acceleration data for the belt.
- Click the menu icon on your card and select to edit the card.
- For card source data, select Cards.
- Select Devices I Care About and click Next.
- Click Connect new data set and enter the following values:
- Event: sensorData
- Property: d.ay
- Name: Accel. Y
- Type: Float
- Unit: gs
- Click Next.
- Path A only: Shake your phone to see the live accelerometer data in your new card. For more information about creating boards and cards, see Visualizing real-time data by using boards and cards.
- IBM Cloud
- IBM Cloud Documentation
- IBM Cloud Developers Community
- IBM Watson Internet of Things
- IBM Watson IoT Platform
- IBM Watson IoT Platform Developers Community
- Artificial Intelligence Code Patterns: Enjoyed this Code Pattern? Check out our other AI Code Patterns.
- Data Analytics Code Patterns: Enjoyed this Code Pattern? Check out our other Data Analytics Code Patterns
- AI and Data Code Pattern Playlist: Bookmark our playlist with all of our Code Pattern videos
- With Watson: Want to take your Watson app to the next level? Looking to utilize Watson Brand assets? Join the With Watson program to leverage exclusive brand, marketing, and tech resources to amplify and accelerate your Watson embedded commercial solution.
- Watson Studios: Master the art of data science with IBM's Watson Studios
- PowerAI: Get started or get scaling, faster, with a software distribution for machine learning running on the Enterprise Platform for AI: IBM Power Systems
- Spark on IBM Cloud: Need a Spark cluster? Create up to 30 Spark executors on IBM Cloud with our Spark service
- Kubernetes on IBM Cloud: Deliver your apps with the combined the power of Kubernetes and Docker on IBM Cloud
This code pattern is licensed under the Apache Software License, Version 2. Separate third party code objects invoked within this code pattern are licensed by their respective providers pursuant to their own separate licenses. Contributions are subject to the Developer Certificate of Origin, Version 1.1 (DCO) and the Apache Software License, Version 2.