typora-copy-images-to |
---|
images_Lab2 |
In this lab, we will use two different techniques to visualize the IoT sensor data collected on the Watson IoT platform.
We will first use the real-time insights dashboard provided by the platform, and then use an external application, in this case Node-RED running as a Cloud Foundry application on the IBM Cloud.
This lab assumes that the RaspiLamp types, schemas and devices of Lab 1 have been setup.
We will now create a graphical interface to plot the data of the various sensors of the lamp.
- For example, add a brightness gauge
- Check that the type is
Number
- Choose size and design of your gauge:
- Choose a card
Line chart
: - Add two datasets, one for
ldr
: - Another on for
solar
: - Choose a size chart
L
: - The values of the two sensors will be displayed on the same diagram
You can create maps for other sensor values.
We will now create a dashboard to act on the lamp. For this we will use Node-RED, but directly out of the Cloud.
- Return to the IBM Cloud Dashboard (https://console.bluemix.net/dashboard/apps)
- You must have an application running;
Select it
- In the
Routes
menu select the first one : - The node-RED setup screen is displayed, click
Next
thenforcez la configuration non-sécurisée
- Press
Next
and thenFinish
- Finally, click
, which opens the Node-RED flow editor.
-
Flow 1
predefined does not interest us necessarily, we will create another thanks to the + top right; -
From the palette on the left side of the screen, add a
ibmiot
send node. Warning, there are two similar nodes, this one has an entry on the left, and it comes from the drawer
output
-
modify the properties of the injected node to send a string of characters:
like RGB for instance
-
Change
ibmiot
node parameters to match your lamp:Authentication
should beBluemix Service
Output Type
must be**Device Command**
Format
must betext
,
-
Activation of the entry (left pellet of the node)
of the
inject
node should turn on your lamp. -
Note that this interface is accessible from the internet now, which was not the case in the first part.
-
Click on the
Install
buttonThis added a series of nodes in the left palette, under the category
Dashboard
:
-
From the palette, add a
Text input
node and wire it toIBM iot
: -
Accept defaults or change names to your liking
-
Validate and deploy, then click on the table launch from the new tab
dashboard
on the top right: -
You can now interactively change the color of the lamp by typing for example W or a sequence
We can decorate this dashboard of various displays:
-
Add 3 nodes from the palette:
-
Configure the nodes as follows:
-
When we go back to the dashboard, we now see a gauge that changes when the sensor is more or less lit:
This interface is now exposed directly on the internet, you can connect to its public URL from a smartphone for example.
You can change the dashboard at your convenience!
Last step, we will program a simple automation mechanism that changes the color of the lamp according to the ambient light level.
- Add a
switch
nodeand set it with the button
Add
as follow:
- The node now has 3 outputs. Add 3
change
nodes, and configure each one for a given R G B color:
- Wire as follow
and deploy
The lamp will change color depending on the illumination of the LDR sensor.
For this section of the Lab, you will be tasked with a creating a more complex Dashboard, without precise instructions but just a functional and visual description, and a few hints.
The goal now will be to create a more elaborate dashboard, which will look like the following:
- The line chart graph shows the value of both the
solar
andldr
sensors - The set of buttons on the left will send a single W,R,G,B,0 command to the RaspiLamp
- The text entry below will send a command string when the
[Set]
button is clicked. - The Clear button will reset the line graph
- The 4 dial gauges below will reflect the current value of the LEDs.
Implementation Hints:
- To set multiple values on the line graph, each sensor value must be passed in
msg.payload
with amsg.topic
set to the sensor ID. You can use achange
node for that, e.g.: - The LEDs colors are in the
d.leds
, as a WRGB field, with an octet for each element of the LED. You will need afunction
node with multiple outputs to split the LED colors into 4 outputs: - To clear the line graph, you must send it a
msg.payload
with an empty array:
On this model, you can design different dashboards or automations loops variations to your liking!