A middleware architecture on Raspberry Pi - archetag/smart-water-quality-monitoring GitHub Wiki

Wiki: A middleware architecture on Raspberry Pi

Finally, once collected by the Raspberry Pi, the data must be correctly sorted and filtered before being sent to the user. A middleware architecture will be used (ROS melodic).

Table of contents

Material needed

  • 1 Computer with Linux OS
  • An Arduino IDE on your computer
  • 1 Arduino Bluno (DFRobot Bluno = Uno + BLE integrated module) ready to communicate through Bluetooth
  • 1 USB-micro USB cable which ALLOWS data transmission
  • 1 Raspberry Pi 3B+, working on a Linux Kernel, with python 2.7, bluepy library installed and Bluetooth enabled
  • 1 Micro-SD card for the Raspberry Pi
  • 1 Power supply for the Raspberry Pi (cable, battery, etc.)

This wiki assumes you have already read the BLE communication between an Arduino Bluno and a Raspberry Pi wiki section.

1. Topics and nodes presentation

The ROS architecture is deployed in the bluetooth_sensors package, and needs to take into account Bluetooth data reception, Kalman filtering applied to the raw data, and data transmission to the user. Python 2.7 was chosen for better stability.

Nodes

Three nodes are used to separate each step:

Node File Mission
ble_interface_node ble_interface_node.py connects to the device via BLE, collects notifications, and sorts the data
kalman_node kalman_node.py filters the raw data, and allows graphical debugging
user_interface_node user_interface_node.py receives the filtered data and displays it to the user

Topics and messages


Two topics insure the flow of information, for each a custom message of type SensorsData is carried:

Structure of SensorsData.msg :

 float64 ph
 float64 conductivity
 float64 temperature
 float64 dissolved_oxygen
 float64 redox_potential
 string  date
 bool    is_connected

2. Launch ROS on the Raspberry Pi

Make sure to have already ROS for python enabled on the Raspberry Pi. To install all dependencies (like ropsy), this website may help: Install ROS on Raspberry Pi 3.

Create your own workspace

Download to clone the git project, and set up your workspace in the catkin_ws directory.

$ cd RaspberryBleRos/catkin_ws
$ echo "source ./devel/setup.bash" >> ~/.bashrc
$ source ~/.bashrc
$ catkin_make                // build the files in the workspace
$ roscore                    // to verify the correct installation

Launch ROS

  1. Power on the Arduino Bluno, which is ready to communicate via BLE. The WaterMonitor.ino file from WaterMonitor folder, with Bluetooth sending debugging code copy-paste in the main loop(), must be uploaded.
  2. Open the Arduino BLE Serial Monitor to start data transmission.
  3. Complete the ble_interface_node.py, in the src folder from the bluetooth_sensor package, with the correct parameters to allows BLE connection (In connectToBLE() method, indicate the correct MAC address of your Arduino in Peripheral("MAC-ADDRESS", "public"), the correct service in bluno.getServiceByUUID("service-name"), and the correct characteristic to use in svc.getCharacteristics("characteristic-name")[0])
  4. In the catkin_ws directory :
$ catkin_make
$ roslaunch bluetooth_sensors launcher.launch
  1. Final filtered data should appear on the screen as:

  1. Press Ctrl+C to properly disconnect all devices and kill all nodes.

3. Tools proposed

Some additional programs are available inside the bluetooth_sensors package, in the tools folder.

  • ble_interface.py: to check the good connection between Bluetooth devices apart from the ROS structure. A tutorial is available in BLE communication between an Arduino Bluno and a Raspberry Pi Wiki.
  • kalman.py: to validate parameters (covariance matrixes Gx, Ga, Gb) chosen for Kalman filter with simulated values, apart from the ROS structure. A graph with simulated, measured, and estimated values is produced.

  • plot_kalman_graph.py: to produce graphical results of Kalman filtering (plots raw and filtered data) from the kalman_graph.txt generated from a roslaunch. You may have to uncomment and modify the file-related functions in kalman_node.py script (opening in the main loop, writing in the callback() method, and closing in the signalHandler() method.

4. Common problems

  • "This file is not a launch file or a ROS directory". Try to refresh the ROS source in the catkin_ws directory with:
$ echo "source ./devel/setup.bash" >> ~/.bashrc
$ source ~/.bashrc
  • "The custom message SensorsData cannot be found". Try to proceed as described in the previous point.
  • "Device not connected": ROS stops immediately after the roslaunch command. This is a problem due to the Bluetooth connection between the Arduino Bluno and the Raspberry Pi. See Common problems in the associated wiki. Otherwise, make sure all parameters are correctly set following the tutorial described in the Bluetooth connection wiki page.
  • "SyntaxError: invalid syntax" with scripts from tools folder: Use python3 instead of python2.
  • "[kalman_filter_node-3] process has died": check if the path chosen for kalman_graph.txt in kalman_node.py script exits.
⚠️ **GitHub.com Fallback** ⚠️