Node-RED provides an elegant solution to merge different IoT devices and services.
- The SensorTag acquires weather data and sends them to the Raspberry Pi through BLE (Bluetooth Low Energy).
- The Node-RED flow runs on the Raspberry Pi, processes the weather data and sends to the Blynk server, either on the cloud or locally, through WiFi.
- An iOS- or Android-based phone or tablet connects to the same Blynk server, either on the cloud or locally, and displays the measures on a beautiful way.
The RedBear IoT pHAT provides BLE and WiFi to the Raspberry Pi Zero.
General PreparationDownload the Debian Jessie Lite image and prepare a microSD-card. On macOS, Iβm using ApplePi-Baker to prepare the microSD-card.
In order to enjoy SSH through USB, update the microSD-card on the main computer with
$
nano config.txt
At the very bottom, add
dtoverlay=dwc2
Press ctrl-O ctrl-X to save and close. Then launch
$
nano cmdline.txt
After rootwait
, add a space then
modules-load=dwc2,g_ether
Press ctrl-O ctrl-X to save and close. Power-cycle the Raspberry Pi.
Connect to the Raspberry Pi, with an USB cable on USB port. On the main computer,
$
ssh pi@raspberrypi.local
Default password is raspberry
.
To proceed with the update and upgrade, launch on the Raspberry Pi
$
sudo apt-get update
sudo apt-get upgrade
Set the timezone. Launch on the Raspberry Pi
$
sudo raspi-config
Install and run rpi-update
. Launch on the Raspberry Pi
$
sudo apt-get install rpi-update
sudo rpi-update
Install RedBear IoT pHATPower the Raspberry Pi off, plug the RedBear IoT pHAT on the Raspberry Pi, power the Raspberry Pi on, connect to it and launch
$
cat /proc/device-tree/hat/product
If the answer is IoT pHAT w/eep_v0.3
, the board is ready. Proceed to next section. Otherwise, the EEPROM needs to be updated. Just follow this procedure.
To confiture WiFi, launch on the Raspberry Pi
$
ifconfig
sudo nano /etc/wpa_supplicant/wpa_supplicant.conf
Add at the end
network={
ssid="SSID"
psk="passwork"
key_mgmt=WPA-PSK
}
Press ctrl-O ctrl-X to save and close. Finally, reboot.
$
sudo reboot
Connect using Ethernet over USB or WiFi and launch on the main computer
$
ssh pi@raspberrypi.local
Default password is raspberry
.
To check Bluetooth is running, launch on the Raspberry Pi
$
hciconfig
hci0: Type: BR/EDR Bus: UART
BD Address: E0:76:D0:CF:2F:A4 ACL MTU: 1021:8 SCO MTU: 64:1
UP RUNNING
RX bytes:717 acl:0 sco:0 events:42 errors:0
TX bytes:1532 acl:0 sco:0 commands:42 errors:0
To scan Bluetooth devices, launch on the Raspberry Pi
$
bluetoothd -v
5.23
sudo bluetoothctl
[bluetooth]#
scan on
[NEW] Device B0:B4:48:ED:B4:84 CC2650 SensorTag
[bluetooth]#
connect B0:B4:48:ED:B4:84
Attempting to connect to B0:B4:48:ED:B4:84
[CHG] Device B0:B4:48:ED:B4:84 Connected: yes
Connection successful
[bluetooth]#
trust B0:B4:48:ED:B4:84
[CHG] Device B0:B4:48:ED:B4:84 Trusted: yes
[bluetooth]#
quit
The SensorTag Node-RED requires Bluetooth, as well as an Ethernet over USB connection or a WiFi connection.
Install node, npm and Node-REDLaunch on the Raspberry Pi
$
sudo apt-get update
sudo apt-get install node
sudo apt-get install nodered
sudo apt-get install npm
Check
$
node -v
v0.10.29
npm -v
1.4.21
To obtain release 0.12
of node, launch on the Raspberry Pi
$
wget https://s3-eu-west-1.amazonaws.com/conoroneill.net/wp-content/uploads/2015/02/node-v0.12.0-linux-arm-pi.tar.gz
tar -zxvf node-v0.12.0-linux-arm-pi.tar.gz
cd node-v0.12.0-linux-arm-pi
sudo cp -R * /usr/local/
cd ..
sudo rm -R node-v0.12.0-linux-arm-pi
node -v
v0.12.0
To install Node-RED
$
sudo apt-get install nodered
To install npm
to manage additional nodes,
$
sudo apt-get install npm
To obtain release 2.15
of npm
, launch on the Raspberry Pi
$
sudo npm install -g npm@2.x
npm -v
2.15.11
Install Additional NodesThere are two releases for the SensorTag, node-red-contrib-sensortag
and node-red-node-sensortag
. I managed to get the first one to work.
$
sudo apt-get install libbluetooth-dev libudev-dev pi-bluetooth
sudo setcap cap_net_raw+eip $(eval readlink -f `which node`)
cd ~/.node-red
npm install node-red-contrib-sensortag
List the installed nodes
npm list
βββ¬ node-red-node-sensortag@0.0.16
βββ¬ sensortag@1.2.3
βββ¬ noble-device@1.4.1
βββ¬ noble@1.7.0
βββ bplist-parser@0.0.6
βββ¬ debug@2.2.0
βββ ms@0.7.1
To install the Blynk node, launch on the Raspberry Pi Zero
$
hash -r
cd ~/.node-red
npm install node-red-contrib-blynk-websockets
Launch the Blynk appOn the iOS- or Android-based phone or tablet, install the Blynk app and launch it. Enter your credentials, either to Blynk cloud or a local server.
Create a new project.
Press E-mail to have the auth token
sent.
For each measure, add a widget. Select one widget among the long list, name it and define a virtual pin.
Below, temperature is defined on virtual pin V0
, and light on virtual pin V3
.
Launch node-red
$
node-red
or
$
node-red-start
Connect using Ethernet over USB or WiFi and open http://raspberrypi.local:1880 on a browser.
In a separate connection, disconnect the SensorTag with bluetoothctl
.
$
bluetoothctl
[NEW] Controller E0:76:D0:CF:2F:A4 myPiZero [default]
[NEW] Device B0:B4:48:ED:B4:84 CC2650 SensorTag
[bluetooth]# disconnect B0:B4:48:ED:B4:84
Attempting to disconnect from B0:B4:48:ED:B4:84
Successful disconnected
[CHG] Device B0:B4:48:ED:B4:84 Connected: no
[CHG] Device B0:B4:48:ED:B4:84 Connected: yes
[bluetooth]# quit
[DEL] Controller E0:76:D0:CF:2F:A4 myPiZero [default]
The SensorTag identification is B0:B4:48:ED:B4:84
.
Connect using Ethernet over USB or WiFi and open http://raspberrypi.local:1880 on a browser.
Click-and-drop the SensorTag
from the left pane to the main area. Each time the Deploy button on the top-right turns red, click Deploy to launch the flow.
On the SensorTag node, press Rescan and select the line with B0:B4:48:ED:B4:84
, corresponding to your SensorTag.
If connection doesn't work, launch bluetoothctl
in a separate connection and disconnect the SensorTag with
[bluetooth]#
disconnect B0:B4:48:ED:B4:84
Attempting to disconnect from B0:B4:48:ED:B4:84
Successful disconnected
[bluetooth]#
Double click on the SensorTag node to configure it.
Click on Scan and select your SensorTag. Select the sensors from the SensorTag to be included in the messages.
Add a Debug node and connect it to the SensorTag node.
The SensorTag outputs
{ sensor: 'humidity',
payload:
{ id: '8631b9178a92.b0b448edb484.2',
tstamp: { '$date': 1474814199515 },
json_data: { temperature: 19.5184326171875, humidity: 73.57177734375 } },
_msgid: '442109d8.bbdef8' }
{ sensor: 'pressure',
payload:
{ id: '8631b9178a92.b0b448edb484.4',
tstamp: { '$date': 1474814199648 },
json_data: { pressure: 1006.95 } },
_msgid: '23f2e413.dc0d1c' }
{ sensor: 'luxometer',
payload:
{ id: '8631b9178a92.b0b448edb484.6',
tstamp: { '$date': 1474817337429 },
json_data: { lux: 240.72 } },
_msgid: 'abe739ac.5418c8' }
On the Node-RED GUI, add a function node and define it with
if (msg.sensor === "pressure")
{
var Msg1 = {payload:msg.payload.json_data.pressure};
return Msg1;
}
else
{
return null;
}
Do the same for other messages. Replace the msg.sensor
criteria and the payload:msg.payload.json_data.
field accordingly.
For example, the criteria for light is "luxometer"
and the field payload:msg.payload.json_data.lux
.
On the Node-RED GUI, add a Blynk write
node and define the URL and project key. The project key is the auth token
sent from the Blynk app.
URL = ws://blynk-cloud.com:8082/websocket
Project key = 0123456789abcdef0123456789abcdef
Name = Light
The URL could be the Blynk cloud...
...or the IP address of a local server.
Press Update and define the virtual pin.
Do the same for the other measures, with different numbers for the virtual pins.
The finalised flow looks like
Click Deploy.
Move the SensorTag and check the measures change accordingly.
Comments