wiotp Python SDK to Node-RED Dashboard

Node-RED Dashboard for Python wiotp psutil sample

The Watson IoT Python SDK (wiotp) includes several samples that demonstrate how to send data from a system to Watson IoT Platform. The psutil example sends system utilization data to Watson IoT. This Node-RED dashboard flow can be deployed to an IBM Cloud hosted Node-RED Internet of Things web app. It displays the system utilization and can send MQTT commands back down to the iotpsutil.py script. Together, the Python script and this flow demonstrate the techniques necessary to use the wiotp Python SDK MQTT publish / subscribe functions and how to connect them to Watson IoT and Node-RED running in IBM Cloud. This might be helpful on constrained embedded systems that are headless but are capable of running Python - eg Raspberry Pi, Onion Omega, ST Microelectronics STM32MP157C-DK2, Linux, etc.

Node-RED Dashboard - psutil System Utilization

Node-RED-Dashboard-wiotp-psutil-sample

Node-RED flow running in IBM Cloud

Node-RED Flow wiotp psutil sample

Instructions

wget https://github.com/ibm-watson-iot/iot-python/archive/master.zip

  • Visit your Watson IoT Platform service instance
    • https://<myorgid>.internetofthings.ibmcloud.com/dashboard/devices/browse
  • Create a DeviceType called PythonExample
  • Create a Device called psutil
  • Set the device credentials as env vars or in a device.cfg
$ export WIOTP_IDENTITY_ORGID=myorgid
$ export WIOTP_IDENTITY_TYPEID=PythonExample
$ export WIOTP_IDENTITY_DEVICEID=psutil
$ export WIOTP_AUTH_TOKEN=myauthtoken
  • Run the script

$ python iot-python-master/samples/psutil/src/iotpsutil.py -v

A tutorial guiding you through the process of setting up this python sample on a Raspberry Pi is published on IBM Developer developerWorks Recipes

[{"id":"e2632345.da0258","type":"tab","label":"wiotp Python Dashboard","disabled":false,"info":""},{"id":"aa8c652a.27374","type":"ibmiot in","z":"e2632345.da0258","authentication":"boundService","apiKey":"27af7288.78c8b6","inputType":"evt","logicalInterface":"","ruleId":"","deviceId":"","applicationId":"","deviceType":"PythonExample","eventType":"+","commandType":"","format":"json","name":"IBM IoT","service":"registered","allDevices":true,"allApplications":"","allDeviceTypes":"","allLogicalInterfaces":"","allEvents":true,"allCommands":"","allFormats":"","qos":0,"x":90,"y":240,"wires":[["814af528.f0f49","32c247a1.8b48e","8d6ab7a8.ab8768","457cf6b0.9a894","899daf9e.8a0fa8","97638305.2d371","fd84c9ae.96403","f137dd0a.2d191"]]},{"id":"814af528.f0f49","type":"debug","z":"e2632345.da0258","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":290,"y":100,"wires":[]},{"id":"32c247a1.8b48e","type":"change","z":"e2632345.da0258","name":"CPU","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.cpu","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":270,"y":180,"wires":[["5ff74d1a.16dfb4"]]},{"id":"8d6ab7a8.ab8768","type":"change","z":"e2632345.da0258","name":"Memory","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.mem","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":280,"y":220,"wires":[["52370095.59cba"]]},{"id":"457cf6b0.9a894","type":"change","z":"e2632345.da0258","name":"Network Up","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.network.up","tot":"msg"},{"t":"set","p":"topic","pt":"msg","to":"network-up","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":290,"y":260,"wires":[["4d67e6d3.6bb02"]]},{"id":"899daf9e.8a0fa8","type":"change","z":"e2632345.da0258","name":"Network Down","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.network.down","tot":"msg"},{"t":"set","p":"topic","pt":"msg","to":"network-down","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":300,"y":300,"wires":[["4d67e6d3.6bb02"]]},{"id":"97638305.2d371","type":"change","z":"e2632345.da0258","name":"Disk Read","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.disk.read","tot":"msg"},{"t":"set","p":"topic","pt":"msg","to":"disk-read","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":290,"y":340,"wires":[["40047cff.121b04"]]},{"id":"fd84c9ae.96403","type":"change","z":"e2632345.da0258","name":"Disk Write","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.disk.write","tot":"msg"},{"t":"set","p":"topic","pt":"msg","to":"disk-write","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":290,"y":380,"wires":[["40047cff.121b04"]]},{"id":"f137dd0a.2d191","type":"ui_text","z":"e2632345.da0258","group":"401768c4.5e5548","order":1,"width":0,"height":0,"name":"","label":"System Name:","format":"{{msg.payload.name}}","layout":"row-spread","x":300,"y":140,"wires":[]},{"id":"4d67e6d3.6bb02","type":"ui_chart","z":"e2632345.da0258","name":"","group":"4503ce44.47ac98","order":0,"width":0,"height":0,"label":"Network","chartType":"line","legend":"false","xformat":"HH:mm:ss","interpolate":"linear","nodata":"","dot":false,"ymin":"","ymax":"","removeOlder":1,"removeOlderPoints":"","removeOlderUnit":"3600","cutout":0,"useOneColor":false,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"useOldStyle":false,"outputs":1,"x":520,"y":280,"wires":[[]]},{"id":"40047cff.121b04","type":"ui_chart","z":"e2632345.da0258","name":"","group":"4503ce44.47ac98","order":1,"width":0,"height":0,"label":"Disk","chartType":"line","legend":"false","xformat":"HH:mm:ss","interpolate":"linear","nodata":"","dot":false,"ymin":"","ymax":"","removeOlder":1,"removeOlderPoints":"","removeOlderUnit":"3600","cutout":0,"useOneColor":false,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"useOldStyle":false,"outputs":1,"x":510,"y":360,"wires":[[]]},{"id":"9dd648c9.9877a","type":"ui_form","z":"e2632345.da0258","name":"","label":"Send a Command to the remote system:","group":"401768c4.5e5548","order":2,"width":"0","height":"0","options":[{"label":"Message","value":"message","type":"text","required":true}],"formValue":{"message":""},"payload":"","submit":"submit","cancel":"cancel","topic":"","x":220,"y":440,"wires":[["c552fcb2.8e1d6","29ee0c8f.077c34"]]},{"id":"c552fcb2.8e1d6","type":"debug","z":"e2632345.da0258","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":570,"y":440,"wires":[]},{"id":"29ee0c8f.077c34","type":"ibmiot out","z":"e2632345.da0258","authentication":"boundService","apiKey":"27af7288.78c8b6","outputType":"cmd","deviceId":"psutil","deviceType":"PythonExample","eventCommandType":"print","format":"json","data":"msg.payload overrides the value of \"Data\"","qos":0,"name":"IBM IoT","service":"registered","x":560,"y":480,"wires":[]},{"id":"239d6d08.949b5a","type":"ui_form","z":"e2632345.da0258","name":"","label":"Change the reporting interval on the remote system:","group":"401768c4.5e5548","order":4,"width":"0","height":"0","options":[{"label":"Interval","value":"interval","type":"text","required":true}],"formValue":{"interval":""},"payload":"","submit":"submit","cancel":"cancel","topic":"","x":260,"y":560,"wires":[["f50c01a1.301d7","3411e934.3b190e"]]},{"id":"f50c01a1.301d7","type":"debug","z":"e2632345.da0258","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":570,"y":560,"wires":[]},{"id":"3411e934.3b190e","type":"ibmiot out","z":"e2632345.da0258","authentication":"boundService","apiKey":"27af7288.78c8b6","outputType":"cmd","deviceId":"psutil","deviceType":"PythonExample","eventCommandType":"setInterval","format":"json","data":"msg.payload overrides the value of \"Data\"","qos":0,"name":"IBM IoT","service":"registered","x":560,"y":600,"wires":[]},{"id":"5ff74d1a.16dfb4","type":"ui_gauge","z":"e2632345.da0258","name":"","group":"960cc7cb.a224d8","order":1,"width":0,"height":0,"gtype":"gage","title":"CPU","label":"units","format":"{{value}}","min":0,"max":"100","colors":["#00b500","#e6e600","#ca3838"],"seg1":"","seg2":"","x":510,"y":180,"wires":[]},{"id":"52370095.59cba","type":"ui_gauge","z":"e2632345.da0258","name":"","group":"960cc7cb.a224d8","order":2,"width":0,"height":0,"gtype":"gage","title":"Memory","label":"units","format":"{{value}}","min":0,"max":"100","colors":["#00b500","#e6e600","#ca3838"],"seg1":"","seg2":"","x":520,"y":220,"wires":[]},{"id":"7fb041.91cd87c","type":"comment","z":"e2632345.da0258","name":"Node-RED Dashboard for wiotp SDK iotpsutil Sample","info":"Download the sample scripts from \nhttps://github.com/ibm-watson-iot/iot-python/tree/master/samples/psutil","x":260,"y":60,"wires":[]},{"id":"27af7288.78c8b6","type":"ibmiot","z":"","name":"TinyPi","keepalive":"60","cleansession":true,"appId":"","shared":false},{"id":"401768c4.5e5548","type":"ui_group","z":"","name":"System Info","tab":"df703df8.763f","order":1,"disp":true,"width":"9","collapse":false},{"id":"4503ce44.47ac98","type":"ui_group","z":"","name":"System Network / Disk","tab":"df703df8.763f","order":3,"disp":true,"width":"8","collapse":false},{"id":"960cc7cb.a224d8","type":"ui_group","z":"","name":"System CPU / Memory","tab":"df703df8.763f","order":2,"disp":true,"width":"8","collapse":false},{"id":"df703df8.763f","type":"ui_tab","z":"","name":"System Stats - Python","icon":"dashboard","order":11,"disabled":false,"hidden":false}]

Flow Info

Created 5 years, 10 months ago
Updated 5 years, 5 months ago
Rating: not yet rated

Owner

Actions

Rate:

Node Types

Core
  • change (x6)
  • comment (x1)
  • debug (x3)
Other

Tags

  • wiotp
  • ibmcloud
  • psutil
Copy this flow JSON to your clipboard and then import into Node-RED using the Import From > Clipboard (Ctrl-I) menu option