IBM WATSON IoT (1): CONNECTING A RASPBERRY PI AS A DEVICE WITH NODE-RED QUICKSTART
- Layout for this exercise:
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiOBA8mIudhReQyMVOdvf5ppVjTHdpeQ33Oez4Dj8dhBqvWwyFdqFGUVP9j5CwPO29pnLzyW4PaZNxMUNFCZLjKEPfpfc1rnoqqtB-pNVk6mKsUhcBwbOWfPEPpt51Mznlu-lfcx8im7Yep/s1600/screenshot.78.jpg)
1 - Introduction
- The IBM Watson IoT Platform is a fully managed cloud-hosted service that makes it simple to derive value from Internet of Things (IoT) devices.
- It provides solutions for device registration, connectivity, control, rapid visualization and storage of data derived from the IoT.
- When combined with the IBM Bluemix environment and access to secure Watson APIs the platform allows to integrate and analyze predictive, cognitive, and contextual analytics for stronger decision-making.
https://www.ibm.com/internet-of-things/platform/watson-iot-platform/
- Node-RED is a programming tool for wiring together hardware devices, APIs and online services in new and interesting ways.
- It provides a browser-based editor that makes it easy to wire together flows using the wide range of nodes in the palette that can be deployed to its runtime in a single-click.
https://nodered.org/
- The goal of this exercise is to connect a Raspberry Pi device to the IBM Watson IoT Platform using the Node-RED programming tool and the Quickstart service.
- The Raspberry Pi device will send messages about its CPU temperature every 5 seconds and the IBM Watson IoT platform receives and handles the information displaying the messages at a website.
- Quickstart is a sandbox service provided by Node-RED that runs 24/7 and it's freely accesible. However, it does not provide any security that data is coming from a trusted source, so anybody using the API can send data into the service. That is the reason because in the next exercise we will see how to use Node-RED with a Registered device.
2 - Installing Node-RED nodes at the Raspberry Pi
- Installing a pair of Node-RED nodes for connecting the Raspberry Pi as a Device (also as a Gateway) to the IBM Watson Internet of Things Platform:
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjoEhxI8SQFJ9w3S66ZGk8e5hj81P161mJF8NHdlwZEq1HLvJE026zVPPUHKbCnbddxlt1gUpEMRTAD21gGST0n_mJqkCXvTsZ4f3UHzXHbSqu5x8thUGt2AVc6uYam99KpqTJlXTUr9Pqr/s1600/screenshot.1.jpg)
- Installing a pair of Node-RED nodes for connecting to both the Quickstart and Registered flows in IBM Watson IoT Platform:
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEguer2Z2mvCxQ0hfTztDKOuixL9ok-ImESnTbcdkMrMgyFCB_SjLKyPS3jyISVAVKoWsk2g3hWzZDwvJdG7xQtkZNQPOCxGAxaOQ-GgkhH2rP04xh0bI-TkgWO-JeY3H1cnzZFcK1yCbBGd/s1600/screenshot.2.jpg)
- Starting Node-RED:
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjXxeKEEgVli-xudhX4UaFIwQQLTdmc6m7wTAKeNjYd1FLpfqZ2oAVZBiKecOmQaTd7UXCuxTKUQ6IpXy_5A2y4J1XT-ZbUQa323a0MqEwmJMHUUJPvR2Ab0_2CUFiDHX5gEtl-qNXa_q0S/s1600/screenshot.3.jpg)
- Browsing to localhost IP at port 1880 lets us access the Node-RED editor:
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhMdtTFEJrZVZtJ9mMtqIRaSR5mudhyphenhyphenNHKnNWfLbbaGar3WfcWWBSY5493IqEh5U12m6sHtke9hzqKwKc6H7ol4IK-q-Lyy1u6hBVEt0ASVzivIxu24GkqM4xrOPFAgmACzkIJmrw1yFkWY/s400/screenshot.4.jpg)
- Checking that the installation of the two nodes has been successful:
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjsPoQGQeDdNLu94Z3aFXceWzGyWhU0kxIHWooTdDugxZL22gtzrRnCgjmj9PCyT_yILXljAxFJ8gHFYzUh_OjSZHNyz7AsRX5WuPvZjgtu6TdkvDDArLJXE3q6uLfOdsrmeSh2PdBoS58_/s400/screenshot.5.jpg)
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhQQbbA1jYfaM-XLZMCggCMCPcicra-RZpeBlS7ReP-vJ2ZcMbJfunSZDnJJ5E03UlBcVkQpsslkac1ok1ELH__S6E53857W7fFTlSIPnhzHzyKyELUNRvoIQbKFkBmafN6iZp98-UkYIBV/s400/screenshot.6.jpg)
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjHp4pe2EHEdj5Ovp2cbWip4BvgBrbP-hFs8v_MOpkm1P9_MeyYe_j8gfnEI3uxKfqaFhKgUqzeTrZx74uSn9EOPX8K7ctxukaajw-VY-kT8Sgy36vRQcd7gXHkMhkMqk4YtUjvvlbKRJP_/s400/screenshot.7.jpg)
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg9S728vUuWLfDYXn472ctswkuapRlPKiV_SBeTd3zO6A0MpC9OUX4Ns034mU_WlOSwsZsdM6Cc5ujZxWEgre2B3mB_UXI8FT_S3scELCqf9YW3Uvv2TTMNbU5iYgVGdGXc-pL66JzgaRvO/s400/screenshot.8.jpg)
3 - Creating a Node-RED flow
- This flow measures the CPU temperature from the Raspberry Pi and sends it to the IBM Watson IoT platform:
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiPY-vApOo_TkoUXFunKV0jBlRvqbzAXDh9ParIzoNhGGAVpmsUyBhOAXNU4h3mVb1JUyNns1dXiq2e8MrxD0kqR8KNUGfBaQsWYzfVFCd-chmMZCqOtoDObeWC3NUdyoQIZexmM03z6vfd/s1600/screenshot.48.jpg)
- Let's check the configuration of the nodes.
- The first node is the injection node, what injects messages every 5 seconds from the start:
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh_yMDX2AIb2_2yI4oXD6T_1tpihqivfLyee1Tpgj4eMW42yaN-XIo_5zhrOJluXp9RniwgiGURKJGWTxOTHAfGqSRkWR7gHwdl_oF3Npj9VV16_Lqfasr1x98Dw3SyLuEVn821SFvJxCsO/s400/screenshot.42.jpg)
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEisH5AcMZtMz5LdfPIRbgycKNcixzf1EZKZgXBPeqXi1Cyc7m_kkQG3EjR6X2dVFIoiinAySzsW4n6ieybwFwXdsy9xadz5CvwVQ5vX4H-5CDv7U81FloXjhsGVLJUdha-sFFtuhrb-eGm8/s1600/screenshot.15.jpg)
- The exec node runs the function vcgencmed with the option measure_temp to measure the CPU temperature of the Raspberry Pi device:
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgyrUq3FJD07DrrZ9oQe-pWjeUpmyZ7s4B-tp6GZ-peUXsV0vDExVJklu556t8aenCEMg08tNJiX2H1JgAFGyH9VhcMq0wECzQAc8oenTsrZn9KWrjpt0jDw9VMFz6UuteOr2hlahydD36d/s400/screenshot.43.jpg)
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgypuiSQF99YDVaMfnM0w4sJ4kgDQ2mYsSooZdrGXjvHT9aD6x3V0XvU7UBKUFm8RRYl41Izq006GtMvSF5sYZrsokhQrTFLCDjAbDk1_y6laHmNGYnEOqCr9794RbF0oZouxbYqNEB94YM/s1600/screenshot.26.jpg)
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgfsbCL37veJNqJICagxOTVsrKeoAFNFhe2xU7sYPLrA3d7931b1SjZDR1cpok9DY_qobD_bOFltCSKVOtMvq8NKc336IyHYH33xOvth3_aYxcRAiUepAqSSCYC8TsoPUkbQV6cXLje9nZu/s1600/screenshot.49.jpg)
- The function node formats the msg.payload:
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj3WgpNUEPl_HmmmooL8RtBnkm9YfZzId22wMhJkq9BW0oBvGodndl3hVMQptfk-S_33tm1fOVkv7rG2iqi1Z39ye6lMIRr_Esl-NZHdVx22fVnA0OOmZ-_xskKXf83a_fc8JTAAg7YjaSL/s400/screenshot.44.jpg)
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgN_-ClDOhhaS2fiAy4jtLwmTAbr08bFSuP-aiu20hy19Uxg-VzWw18Ft0T28cOH4_t4VfJ2kBKcP0G64sudpq2-atmrcT4-eo5ZoB9NF82IEJL4NhvOGNVZGWMPFwhbpV9K-daCiEolAN2/s1600/screenshot.32.jpg)
- The debug node outputs the msg.payload to the Debug tab:
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhcwsCPQNQjaxViA4H2OhVqIRhL7AimT5LjvTW4vuDs4YcB1tTmSWt-oGwJi85wN14lRaIaruz0t15SV2py9qSa_ieKsLDxJslgvv6dBJhJTxdLm89IoOa46TV60d0d2rNEoMtGKVKZ9Ko2/s400/screenshot.45.jpg)
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh282hr5ETG8XO5lXB7eacbhNg2W63xMWIAfWQd5pcM_4Qk3RzWR8hoGH17l_b5Z-eA0zidodbYoZ4KSz4hjPvoue2TPGAyaiVmAnKMyCnK0gz6KQqZ3QIq-VU1EgAVW7Mm5AJciQZExJOz/s1600/screenshot.34.jpg)
- Finally, the Watson IoT node allow to connect the Raspberry Pi device sending events to the IoT platform. In this case, the Quickstart mode is selected:
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEino2v3D7LMJGO3GPe3YrLuzOi2WCnHrRVz_CMRam8gqepZ5FVI0yHO_guUaEPhQy-PxwkYY06bG5wX_NRFV9xQPBUglLSCiKjgQadjtVClSgQei16DqB-ezeqJiOLvaWgsaoTFE09zB_c9/s400/screenshot.46.jpg)
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgudwFT8oKiGSxR_V9Qq3OMktkGcZbmMc_l_yqdXO8_LU-PdCgXqR99L7f0JT5oNH2Cl3qkWnLfMnMeEwWeUZ5WN-Zy3EawQXoSQhf8Tej7LxdFrtolDGmpCYR8uj3lpiIOagjaDYenL0k6/s1600/screenshot.36.jpg)
- Exporting the flow to the clipboard:
[{"id":"aa1ea7a8.5cac6","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"474020f5.41c758","type":"inject","z":"aa1ea7a8.5cac6","name":"","topic":"","payload":"","payloadType":"date","repeat":"5","crontab":"","once":true,"x":216,"y":212,"wires":[["3377c7a3.ca8418"]]},{"id":"3377c7a3.ca8418","type":"exec","z":"aa1ea7a8.5cac6","command":"vcgencmd","addpay":false,"append":"measure_temp","useSpawn":"","timer":"","oldrc":false,"name":"RaspberryPi_CPU_temperature","x":410,"y":305.5,"wires":[["69a8e49e.1adb7c","21d130ef.8669c8"],[],[]]},{"id":"69a8e49e.1adb7c","type":"debug","z":"aa1ea7a8.5cac6","name":"debug","active":true,"console":"false","complete":"payload","x":845,"y":117.5,"wires":[]},{"id":"21d130ef.8669c8","type":"function","z":"aa1ea7a8.5cac6","name":"msg.payload","func":"msg.payload = {\"d\":{\"temp\":msg.payload.replace(\"temp=\",\"\").replace(\"'C\\n\",\"\")}};\nreturn msg;","outputs":1,"noerr":0,"x":675,"y":313,"wires":[["69a8e49e.1adb7c","a67a1c60.187598"]]},{"id":"a67a1c60.187598","type":"wiotp out","z":"aa1ea7a8.5cac6","authType":"d","qs":"true","qsDeviceId":"a67a1c60.187598","deviceKey":"","deviceType":"","deviceId":"","event":"event","format":"json","qos":"","name":"Watson IoT","x":895,"y":409.5,"wires":[]}]
4 - Deploying the NODE-Red flow in the Quickstart mode
- Clicking the Deploy tab:
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgstkuANXCyoBadQjtJyCAVWDKVN5kjWGxyqF9CHdXi9SwxlotSKEFr0oZEeQfbvRwTnKCyselJh4lVWYXS6M0U6b7O5Ah2AzOFSUneQWzUQTig9hSJGq5qcvPfqju7q9wY8hf-zvmhdXsd/s400/screenshot.24.jpg)
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjy0KyrwMN6Kws5niCv7Nu6kK8sltkUWl7mVgLw38JvZF-Vk_1Ib_mJB8tTgUW9acviupasqyFEKhNRQx-5gqSaHvB50qXy96k4aS_IxUD1Le9MIF9FzEngkidhEMwpY9QY4b_aqENnbXue/s400/screenshot.25.jpg)
- The Debug tab displays the CPU temperature every 5 seconds:
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEipMTrKzV3I5aNrmpF8RObrqsw7ksAb3yIbBtZoN-Wyri7fJeDbd1Gko7PN6IjW5yO3iHiVVMMxgXoJi8aaqpJ-tpr0Iqllx_REOo1jZU4fueztaezVlVXV8qelCAwwxphv9gRFDVJo3D_3/s400/screenshot.35.jpg)
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhvifpg_p4kGaZdo8VsJ5AhSCVPcqdTnUhXzg8Z-XYsrlarTMwOHKIbPxn442oKZmYyMx-iraQMLOa2FaMdUPezqW8UsjNUb216NUmvgfxyOsrDdgog8Zbg4dlrX4Ksx3_F2hjU8TUdtwM3/s1600/screenshot.37.jpg)
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh1MNkVJfaEARYJXwhRXGFk4r_Pxq2DqRofApSWz8niAVWVlP14S5jCcGJmxqxtUyy1sg6FNk15mSITiG9YnvqBGZzfhGX5tuLV1c3viQoYiDSByzApme98aPOgVYC94T62WCfKv5uIx63o/s1600/screenshot.38.jpg)