This project uses NodeJS,Node-RED, and WolkConnect-Node-RED, an npm package running on Raspberry Pi and its Raspbian OS to connect and send data to WolkAbout IoT Platform. Node-RED supports deployment to Raspberry Pi out of the box, and the set of nodes provided by the package greatly reduces the time needed to connect to the Platform.
Setting Up NodeJS and Node-REDTo be able to run Node-RED on our Raspberry Pi, you need to install NodeJS. Install NodeJS by running:
curl -sL https://deb.nodesource.com/setup_12.x | bash -
apt-get install -y nodejs
After having installed NodeJS, you can use its package manager to install Node-RED. Make sure to install version 1.0.6 by running:
sudo npm install -g --unsafe-perm node-red@1.0.6
Finally, you are ready to install WolkConnect-Node-RED through npm. First, open the terminal and run node-red
. This will make sure that Node-RED sets up all files and directories required for it to run successfully. After the process has successfully reported to have started the flows, it is safe to terminate it. Then, navigate to Node-RED’s folder:
cd .node-red
Then install your package by running:
npm install @wolkabout/wolkconnect-node-red
Finally, you are ready to run Node-RED by using the command:
node-red
Now, you can navigate to http://127.0.0.1:1880 and use Node-RED’s flow editor. The following screen greets you:
WolkConnect nodes should appear at the bottom of the nodes list.
You are now able to use the full potential of NodeJS and Node-RED!
Setting up the Device on WolkAbout IoT PlatformWith your package installed, you are ready to set up a device on WolkAbout IoT Platform.
Go to https://demo.wolkabout.com, log in, and select the Device Management tool.
Here you can create a new typed device by using the provided Full example device type.
This will open the device creation screen, where you should select Full example for the device type, enter a device name, set the connectivity type to MQTT and tick the checkbox for creating a default semantic.
Click Save.
A new popup dialogue appears. Write down device credentials, or download them, and finally click OK. Your device is now ready!
This gif first illustrates how to import a device type, this is not needed at this time.
At this point, you are ready to add some widgets to the dashboard on the Platform to be able to visualise the data you are sending. First, you need to create a dashboard, then create widgets.
Add a Reading widget for Temperature, Pressure, Humidity and Accelerometer.
Add a Actuator widget for Switch and Slider.
Navigate to Node-RED’s flow editor in your browser. Click the hamburger menu in the top-right corner of the browser screen, and select Import >Clipboard.
Copy the contents of full-example-flow.json
located in .node-red/node-modules/@wolkabout/wolkconnect-node-red/examples/full-feature-set
and paste them to the dialogue popup that appeared.
Click Import.
It is also possible to drag the flow file directly onto the browser flow, instead of copying its contents to the import dialogue.
Now that you have imported the flow, you are ready to set up the nodes. But, you need to configure the MQTT nodes first. Double click the MQTT out node, and a new edit dialogue appears.
Edit the WolkAbout Demo server.
On the Connection tab, use your device key as ClientID.
If you want to use a secure connection, select the Enable secure (SSL/TLS) connection check box. Add new TLS config, and upload ca.pem
located in .node-red/node-modules/@wolkabout/wolkconnect-node-red/examples/
, as CA Certificate.
Click Add, and then change the port to 8883.
On the Security tab, pass your device key as Username and your device password as Password.
On the Messages tab, configure your close and disconnect messages in the following manner: lastwill/device-key
.
Now, you can go on to set up the MQTT input nodes. All you need to do is pass your device key to the topics, and select WolkAbout Demo as the server. No configuration of the server is needed here, as you have already completed it in the previous steps.
Lastly, pass your device key and password to connect node.
Device configuration and actuators initialiser nodes are already preconfigured for the example flow you are using.
Using the FlowIn this example, you are using a device with four sensors, two actuators, and an alarm. Also, you are using getRandomValue
node for providing values to sensors and actuators. Your sensor and actuator nodes are preconfigured for the example you are using, with the sensor and actuator references already passed to them.
Now you can deploy the flow and send the data to WolkAbout IoT Platform.
Click Deploy in the top-right corner of the screen.
If you have entered the data correctly, MQTT nodes will show a connected notification.
Next connect your device to the Platform by clicking the inject node labelled Connect device.
Now check if you have connected your device to the Platform. Go to Device Management on the Platform, and it should register the device as connected.
Success! The device is connected to the Platform.
Having done this, you can now send readings. Use the inject nodes labelled Send random values from sensors/alarms and Send random values from actuators.
To check for readings, navigate to the Dashboard tab on the Platform.
Great! The readings have been sent to the Platform successfully.
You can also send fixed sensor, actuator, and alarm values by passing the desired value directly to the sensor and actuator nodes, while the configuration node only takes user-defined values. Passing fixed values will ignore random values and send user-defined values to the Platform (note - whenever making changes to nodes/flow, it is necessary to deploy the flow, and use connect
node to reconnect the device to the Platform).
Next, add the value of 50 to your temperature sensor.
And, again, check for the value of temperature sensor on the dashboard once you have redeployed the flow and sent the reading.
To disconnect from the Platform slick the inject node labelled Disconnect device.
The device is now disconnected from the Platform.
With the high degree of customisation and the visual tool Node-RED provides, as well as WolkConnect-Node-RED package, it is straightforward to connect almost any device to WolkAbout IoT Platform. Node-RED contributions library also offers additional packages that further expand the possibilities of Node-RED to run and communicate with various devices, aside from Raspberry Pi used in this example. To learn more about the possibilities of WolkConnect-Node-Red, check the repo’s readme files.
For more information about WolkAbout IoT Platform's features, visit our User Guidespage.
Comments