Get your device ready
Connect your Raspberry Pi to the internet.
Watson IoT Platform Quickstart connection
Download the installer from GitHub:
curl -LO https://github.com/ibm-messaging/iot-raspberrypi/releases/download/22.214.171.124/iot_1.0-2_armhf.deb(Source code is also available)
- Install the package with:
sudo dpkg -i iot_1.0-2_armhf.deb
- The iot process starts and publishes events to theIBM Watson IoT Platform Quickstart. The process runs as a system service, and starts whenever Raspberry Pi starts. To verify the process is running, use the command:
service iot status
- You can stop the iot process with the following command:
sudo service iot stop
- To uninstall the package, run:
sudo dpkg -P iotNote: For troubleshooting, go to /var/log/syslog to find more information about the iot process.
Real-time visualization of device data
Find the MAC address of your Raspberry Pi by running the following service command:
service iot getdeviceid
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.
Watson IoT Platform Registered connection
During the device registration process you will get file configuration information containing the following details, copy these when you get them.Organization IDDevice Type IDDevice IDAuthentication MethodAuthentication Token
- Stop the iot process
sudo service iot stop
- Type in the following command
sudo nano /etc/iotsample-raspberrypi/device.cfg
Create a new device.cfg file at /etc/iotsample-raspberrypi fill in the configuration file with the details that you copied when registering the device.
#Device configuration file
org = yourOrganizationCode
type = iotsample-raspberrypi
id = b827eba84426
auth-method = token
auth-token = yourAuthToken
#End of Configuration file
Note: All the properties in the configuration file are mandatory. Currently, only token based authentication is supported.
- Save your file by pressing CTRL-X in the Nano editor and follow the steps on the screen.
Start the iot process for the device to start in registered mode
sudo service iot start
Visualize the Raspberry Pi events in Watson IoT Platform dashboard
With the new boards and cards capability in the Watson Internet of Things platform, you can build your own Custom dashboard without writing any code. You can use the boards as the landing page of interest and then make use of the cards within them to:
- Create visualization charts for the real time data from your devices
- Create Gauges for visualizing physical quantities like Vehicle Speed, Temperature, pressure
- Create Donuts charts, bar charts to display the current value of the data points
- See the Data and storage consumption of your devices
- List of registered devices and etc..
Refer to Configuring Boards & Cards in the new Watson IoT Dashboard recipe to view the Raspberry Pi events in Watson IoT Platform using the boards and cards.
Create a Node-RED application to receive events from the device
With events now being sent to Watson IoT, the next step is to create an application in Bluemix to receive the events.
Create Node-RED application in Bluemix
- In the Bluemix catalog, select the Node-RED Starter under the Boilerplate category as shown below,
- Create a new instance, giving your application a unique name. After a few minutes you will be taken to your applications Overview page.
Bind the Node-RED application to Watson IoT Platform service
- From the Node-RED application page, select Connections and then Connect Existing service as shown below to connect (bind) to your Internet of Things Platform service.
- Choose your Internet of Things Platform service and click Connect.
- You will then be able to access the Node-RED editor by opening http://<your-application-name>.mybluemix.net/red.
Create a simple flow to start receiving the device events
- Open the Node-RED flow editor,
- Add an ibmiot input node and configure it to use Bluemix Service authentication. Set the Device Type field to match the type you used to register your device with. Leave the Device Id and Event fields set to all.
- Attach the debug node to the IBM IoT node as shown below to output the datapoints in the debug panel.
- Click Deploy to deploy the flow in Node-RED and observe that the readings are printed in the console.
In this step, we have successfully configured the IBM IoT App In Node to receive the Raspberry Pi events from the Watson IoT Platform.
Send commands to your Raspberry Pi device
When the Raspberry Pi Sample is running in registered mode, it supports the receipt of Commands sent by an Application.
This sample supports the Reboot Command. When the user sends this command, the Raspberry Pi will reboot based on the seconds provided in the payload.
- Drag-n-Drop an inject node and configure the payload as follows,
- As shown the above payload instructs the sample to wait for 3 seconds and reboot the device.
- Drag and drop ibmiot out node from the output pane and configure it to use Bluemix Service authentication. Set the Device Type, Device Id fields appropriately. Set the Output type as Device Command and connect it to the reboot trigger node as shown below,
- The flow should look like the following,
- Click deploy to deploy the flow.
- Click on the Trigger reboot node to send the reboot command to Raspbery Pi device.
In this step, we saw how to send a command to the device to control it using a Node-RED application.
Where to go from here?
As a next step, go through the following recipes that will help you to create an end to end IoT solution,
- Real-time data analytics in Watson IoT Platform – Showcases how to create rules and actions to monitor assets in real-time with just few mouse clicks. There is no coding involved.
- Go through How to connect Raspberry Pi as managed device to Watson IoT Platform to take advantage of device management capabilities present in Watson IoT Platform
- Go through Connect your device as Gateway to Watson IoT Platform recipe to connect your gateway and devices behind the Gateway to IBM Watson IoT Platform
- Go through Configure Cloudant NoSQL DB as Historian Data Storage for IBM Watson IoT to store your device events in Cloudant NoSQL DB without writing any code.