I have been working on low power wireless sensor development in the past five years and would like to share some design experience with Node-RED. The wireless sensors are ultra low power. For example, the temperature sensor SVT100-T, it can send out temperature values every 10 seconds continuously and the battery life can easily last 3-4 years. The wireless vibration sensor SVT100-A working in batch mode consumes less than 0.5mA in average when taking measurements and sending out data. The battery is only half AA size (14250 battery) with 1200mAh capacity.
We want to visualize the data quickly and Node-RED fits the purpose really well. Node-RED also provides the flexibility to expand the functions and modify the flows based on users requirements. During the Node-RED development, many thanks to the help from this forum.
The wireless protocol we choose is BLE 5.0 (Bluetooth Low Energy). Many articles on the internet are outdated about BLE range. BLE5.0 can reach 1km in range in low speed mode. At 1Mbps, it can reach 300m in open space with a chip antenna. At the beginning, we used WIFI (ESP8266, ESP32) but the power consumption of WIFI is way too high for the applications. Zigbee's speed is low compared to BLE 5.0. BLE 5.0 provides relative high speed wireless transmission with very low power consumption. There are may BLE chip vendors right now. One popular BLE 5.0 chip is from Nordic Semiconductor: nrf52840. Actually, for simple task such as temperature measurement, one can just use the cheaper version nrf52832. The development kit nrf52840 DK can be purchased from Digikey or Mouser. You can download the SDK from Nordic if interested.
Multiple wireless sensors can connect to the gateway GU200. The gateway uses Raspberry Pi 3B+ or Raspberry Pi 4. We have been using Raspberry Pi 3B and Pi 3 Compute Module 3 (CM3) for industrial applications and they work well. That's why we choose Raspberry Pi 3B+ or 4 for the gateway. Why don't we use Pi 3B or CM3 for the gateway? This is because we put InfluxDB in the gateway for data storage and export. InfluxDB consumes quite some resources, especially during data input and query. When there are more than four vibration sensors sending data to GU200 at the same time, only Raspberry Pi 4 can handle it well. This why we limit the number of sensors in a group to be less than 4. We also have to limit the number points to be less than 100,000 in a query.
The following is the architecture plot of the low power wireless system.
Sensor data are transmitted to the gateway via BLE 5.0 protocol. Then the data are saved in the gateway. At the same time, the data are transferred via MQTT protocol to user's private cloud. User can also set up their own server with InfluxDB and Grafana.The sensors and gateway are pretty reliable in our applications. Here is a picture of the sensor in action. You can see that the environment is pretty hostile.
I will focus more on the Node-RED side instead of BLE 5.0 interface between the sensors and gateway, since that part does not belong here (complicated with heavy C programming). Inside GU200, there is NRF52840 chip that interfaces with Raspberry Pi 3B+/4 with UART interface. Currently, the UART interface runs at speed of 232,400. We may bump up the speed later on after extensive testing. Because there will be more low power wireless sensors such as wireless distance sensors and strain gauges developed, the wireless incoming data length may vary. We have to customize the serial node to handle the variable data length. I will talk more about this later on. The following is a screen shot of the front panel of the dashboard.
Once data are in, they are divided based on types and drawn in the dashboard. They are saved into InfluxDB at the same time. Data can be queried and displayed again. We did not choose Grafana for the data review since we want to flexibility of more control. So we used database query and plotly to show the history data instead. Here is a screen shot of the history data:
The data query from InfluxDB can also be exported to a user's computer in CSV format. We found that the CSV node from Node-RED is little bit slow, so we write our our CSV format conversion, which only does the job of converting InfluxDB query payload to CSV format. Then you can save the payload into a file. Here is the function in case that somebody needs it.
function ConvertToCSV(objArray) {
var array = typeof objArray != 'object' ? JSON.parse(objArray) : objArray;
var str = '';
for (var i = 0; i < array.length; i++) {
var line = '';
for (var index in array[i]) {
if (line != '') line += ','
line += array[i][index];
}
str += line + '\r\n';
}
return str;
}
To call the function, one can simply take the database query as the input to the function:
msg.payload=ConvertToCSV(msg.payload);