Install Rasbian on your Raspberry Pi, and connect it to the internet.
Register a device with IBM Watson IoT Platform. For information on how to register devices, see the Connecting Devices topic in the IBM Watson IoT Platform documentation.
At the end of the registration process, make a note of the following parameters:
- Organization ID
- Type ID
- Device ID
- Authentication Token
Optionally, to learn more about the device code you are going to install and run in this tutorial take a look at the README for the IBM Watson IoT Platform PSUtil Device Client in GitHub.
Installation on Raspbian
Installation across all OS’s is pretty much the same:
- Install any necessary system packages missing from the host (in order to install psutil on Windows you’ll need Visual Studio installed)
- Install the wiotp-sdk and psutil python modules using pip
- Download the sample code from GitHub
pi@raspberrypi ~ $ sudo apt-get update
pi@raspberrypi ~ $ sudo apt-get install python-dev python-pip
pi@raspberrypi ~ $ sudo pip install wiotp-sdk psutil
pi@raspberrypi ~ $ wget https://github.com/ibm-watson-iot/iot-python/archive/master.zip
pi@raspberrypi ~ $ unzip master.zip
pi@raspberrypi ~ $ cd iot-python-master/samples/psutil/src
Connect to Quickstart
Connecting to Quickstart allows you to quickly verify your installation and connectivity to IBM Watson IoT Platform. The –quickstart command line argument will configure the device client to connect to quickstart using a generated deviceId based on your Pi’s MAC address:
pi@raspberrypi ~ $ python iotpsutil.py --quickstart
2019-05-20 12:39:28,621 wiotp.sdk.device.client.DeviceClient INFO Connected successfully: d:quickstart:sample-iotpsutil:3403868c1274
Welcome to IBM Watson IoT Platform Quickstart, view a vizualization of live data from this device at the URL below:
(Press Ctrl+C to disconnect)
The following data points are collected:
- CPU utilization (%)
- Memory utilization (%)
- Outbound network utilization across all network interfaces (KB/s)
- Inbound network utilization across all network interfaces (KB/s)
Use the URL provided to launch the Quickstart web application and see the events coming from your Raspberry Pi visualized in real time.
Connect as a Registered Device
We will use environment variables to configure the device client to connect to your instance of Watson IoT Platform as your registered device.
These variables correspond to the device parameters for your registered device:
pi@raspberrypi ~ $ export WIOTP_IDENTITY_ORGID=myorgid
pi@raspberrypi ~ $ export WIOTP_IDENTITY_TYPEID=mytypeid
pi@raspberrypi ~ $ export WIOTP_IDENTITY_DEVICEID=mydeviceid
pi@raspberrypi ~ $ export WIOTP_AUTH_TOKEN=myauthtoken
pi@raspberrypi ~ $ python iotpsutil.py
(Press Ctrl+C to disconnect)
Visualize Device Events
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.
Conclusion & Next Steps
That was painless. Take a look at the IBM Watson IoT Platform Python SDK documentation and start modifying the device code in iotpsutil.py to fit your needs.