Overview In this lab, you will send environmental information from your RaspberryPi + SenseHat to IoT Platform and display it on a dashboard. You will also use the weather service to check the weather for your area and display weather status on the Sense Hat. It is assumed you have already setup your RaspberryPi and Sense Hat and have Node-RED installed and running on it. Note: some of the tasks below contain a shortened link to the Bluemix dashboard that opens the US South Region. If you wish to use the UK region instead then substitute the link below US South: http://bit.ly/bluemix_new_us UK: http://bit.ly/bluemix_new_uk Copyright IBM Corp. 2017
Task 1. Deploy a New Application In this task, you will deploy a new Node-RED Starter Application and connect it to an existing IoT Platform. If you prefer you can deploy a new IoT Platform Starter. You will also add a new Weather Company service to the application. 1. Deploy new application: a. Open your Bluemix dashboard: http://bit.ly/bluemix_new_us b. In the All Apps section, click Create App:: c. In the Search bar, type node-red d. Click the Node-RED Starter Boilerplate: TIP: TIP: e. Give the new application a unique name Suggestion: IoT-BB-SenseHat-Weather-YourInitials+DOB f. Click Create g. Wait for the application to deploy Check the logs and look for the message Started Flows 2. Connect an existing IoT Platform Service a. Click the Connections tab in the sidebar: Raspberry Pi, SenseHat and Weather Service - 2 Copyright IBM Corp. 2017
b. Click Connect New: c. In the Search field, type weat d. Click the Weather Company Data service: e. Click Create: Copyright IBM Corp. 2017 Raspberry Pi, SenseHat and Weather Service - 3
f. Click Restage to restage the application: g. Wait until the application has finished restaging and is running: 3. Connect an existing IoT Platform: a. Click Connect existing: b. Click an existing IoT Platform service: c. Click Connect: d. Click Restage e. Wait for the application to finish restaging 4. Open the IoT Platform: a. Click the IoT Platform service to open it: Raspberry Pi, SenseHat and Weather Service - 4 Copyright IBM Corp. 2017
b. Click Launch Dashboard 5. Add a new Device Type a. In the sidebar, click Devices: Copyright IBM Corp. 2017 Raspberry Pi, SenseHat and Weather Service - 5
b. Click the Device Types tab: c. Click Create Type: d. Click Create device type: e. In the Name field, type SenseHAT: Raspberry Pi, SenseHat and Weather Service - 6 Copyright IBM Corp. 2017
f. This is all the information required so click Next a few times until it turns into Create g. Click Create 6. Create a new device: a. On the Devices page, click Browse: b. Click Add Device: c. In the Choose Device Type field, select SenseHAT: d. At the bottom of the page, click Next e. In the Device ID field, type WeatherDisplay: Copyright IBM Corp. 2017 Raspberry Pi, SenseHat and Weather Service - 7
TIP: You can use any ID you like you will enter the same device type and device id into Node-RED on the Pi in a few minutes. f. Click Next g. There is no Metadata so click Next h. In the Provide a token (optional) field, type 12345678 TIP: You can use any token you like as long as you can remember it. If you do not enter one then one will be generated for you which will be a very long string which you must record. Once the token has been generated and you close this page you can never get back to it. i. Click Next j. Click Add k. Record the Organization ID, Device Type, Device ID and token you will need these in a moment on your Pi: Task 2. Create a Flow on Raspberry Pi In this task, you will create a simple flow on your Raspberry Pi to read environmental information and send the data to the IoT Platform instance you created/connected to in Task 1. 1. Create a flow: a. Make sure Node-RED is running on your Raspberry Pi. b. Open a new web browser tab and navigate to the address of your Pi Flow editor for example: http://192.168.1.146:1880/ Raspberry Pi, SenseHat and Weather Service - 8 Copyright IBM Corp. 2017
c. From the palette, drag on a Sense HAT input node: d. Double-click the new node to edit it e. Clear Motion events f. Clear Joystick events: g. Click Done h. Drag on a debug node and connect it to the Sense HAT node: 2. Deploy and Test: a. Click Deploy b. Note the Sense HAT information in the debug panel: 3. Send data to IoT Platform: Copyright IBM Corp. 2017 Raspberry Pi, SenseHat and Weather Service - 9
a. From the palette, drag on a Watson IoT output node: b. Double-click the new node to edit it: c. In the Connect as section, select Registered: d. Click the pencil icon in the Credentials field to add new credentials: e. Enter the device credentials you recorded in the previous step: Raspberry Pi, SenseHat and Weather Service - 10 Copyright IBM Corp. 2017
TIP: Be careful copying and pasting from the web dialog in IoT platform it is very easy to copy additional characters f. Click Add g. Click Done h. Connect the SenseHAT node to the Watson IoT node: 4. Deploy and Test a. Click Deploy b. Switch back to the Watson IoT Platform tab c. You should now be seeing SenseHAT data in IoT Platform: Copyright IBM Corp. 2017 Raspberry Pi, SenseHat and Weather Service - 11
5. Unguided Exercise: a. Create Boards in the IoT Platform to display the Sense HAT data TIP: You will need to create a schema in IoT Platform. If you are unsure how to do this see the IoT Bootcamp lab on Sensor Data Visualization Task 3. Obtain Weather Data In this task, you will get the weather data from the Weather Service using location data from your home town. You will need the latitude and longitude which can be obtained from this website: http://ibm.biz/nasa-loc-finder. You will then publish some of the returned weather data to IoT Platform and modify the application on the Pi to subscribe to it such that the SenseHAT displays different colours based on the outside temperature. 1. Obtain your location co-ordinates: a. Open a new web browser tab and navigate to: http://ibm.biz/nasa-loc-finder b. Enter your location and click Search: Raspberry Pi, SenseHat and Weather Service - 12 Copyright IBM Corp. 2017
c. Record the co-ordinates reported: 2. Add a flow a. Return to the Bluemix tab b. Open the Node-RED Flow Editor in the application you deployed on Bluemix c. From the palette, drag on a weather insights node: d. Double-click the new node to edit it e. In the Service field, select Current Observations f. In the Location field, paste in the co-ordinates you obtained from the previous step: TIP: If you copy and paste be sure to remove the space between the longitude and latitude Copyright IBM Corp. 2017 Raspberry Pi, SenseHat and Weather Service - 13
g. Drag on a debug node and change its Output to msg.observation TIP: Check the Info tab for the node to see the other options h. Drag on an inject node and connect the nodes as shown below: 3. Deploy and Test: a. Click Deploy b. Activate the inject node and observe the results in the output window: Raspberry Pi, SenseHat and Weather Service - 14 Copyright IBM Corp. 2017
4. Separate temperature data: a. From the palette, drag on a change node b. Double-click the new node to edit it c. In the Name field, type Get Temp d. In the to field, change the type to msg e. In the to field, type observation.temp: Copyright IBM Corp. 2017 Raspberry Pi, SenseHat and Weather Service - 15
f. Click Done g. Connect the weather insights node to the change node: 5. Publish Command IoT Platform: a. From the palette, drag on an ibmiot output node b. Double-click the new node to edit it c. In the Authentication field, select Bluemix Service d. In the Output Type field, select Device Command e. In the Device Type field, type SenseHAT f. In the Device Id field, type WeatherDisplay g. In the Command Type field, type setdisplay h. In the Data section, type {} TIP: The Data section will be overridden by the msg.payload Raspberry Pi, SenseHat and Weather Service - 16 Copyright IBM Corp. 2017
i. Click Done j. Connect the iot output node to the change node: 6. Publish at predefined intervals: a. Double-click the inject node to edit it b. In the Repeat field, select interval c. Change the interval to default as every 10 seconds Copyright IBM Corp. 2017 Raspberry Pi, SenseHat and Weather Service - 17
TIP: In a real system, you would only need to publish every few minutes/hours or even longer depending on the need. In the free version, you are only allowed 10 calls per minute. d. Click Done TIP: If you wish to test the flow before switching to the Pi simply add an iot input node and subscribe to the SenseHAT commands: Raspberry Pi, SenseHat and Weather Service - 18 Copyright IBM Corp. 2017
Task 4. Set the SenseHAT Display for Current Weather Conditions In this task, you will modify the flow to subscribe to commands from the IoT Platform and change the color of messages on the SenseHAT depending on current external temperature. 1. Subscribe to Weather commands: a. Switch to the Node-RED Flow Editor on your Raspberry Pi b. From the palette, drag on a Watson IoT input node: c. Double-click the new node to edit it d. In the Commands field, select specify command: e. In the Command field, type setdisplay: TIP: Remember these are still MQTT topics so you could have a topic tree and subscribe to specific commands as well as trees / branches f. Click Done 2. Process the command payload: Copyright IBM Corp. 2017 Raspberry Pi, SenseHat and Weather Service - 19
a. Open the supplied weathercheck.txt file in a text editor b. Copy all the text c. In the Node-RED Flow on your Pi, click the burger menu button and select Import à Clipboard: d. Paste in the copied text e. Click Import: f. Left-click on the flow canvas to place the new nodes Raspberry Pi, SenseHat and Weather Service - 20 Copyright IBM Corp. 2017
g. Connect the new switch node to the iot input node you just created: 3. Deploy and Test a. Click Deploy b. The SenseHAT should now display the current temperature using a colour that reflects whether it is warm or cold 4. Unguided exercise: a. Try building your own weather station dashboard b. Try storing the data in cloudant / dash so that later you can build an app to read that data at faster speeds and get time-lapse weather data for use in demos! Copyright IBM Corp. 2017 Raspberry Pi, SenseHat and Weather Service - 21
Raspberry Pi, SenseHat and Weather Service - 22 Copyright IBM Corp. 2017