MQTT broker and Bluetooth (LE) MQTT gateway, that is for the messages transportation between camper's sensors and actuators, is extremely lightweight and can be deployed on any single-board computer that in the camper's network. This can be computer works for Camper assistant itself, or be computer works for a video recorder and streamer (USB camera), for the camper's NAS, etc. What important is to set a static IP for this computer in the camper's network, and to make this computer not sleep, not hibernate.
Bluetooth USB dongle on Qualcomm CSR8510 A10 was used (Hama H-49218 for example). Here the list of other Bluetooth 4.0/4.1 USB adapters that can be used in this case (being integrated on the single-board computer, or within USB dongle).
All settings were made via Windows PC. In some cases will need switch off the PC firewall while settings. Broker's computer was available in the PC terminal via PuTTY over IP on port 22 under root user.
To install Mosquitto MQTT broker, was entered from PC via PuTTY terminal:
apt-get install mosquitto
apt-get install mosquitto-clients
sudo service mosquitto stop
sudo systemctl stop mosquitto.service
In the opened file was entered strings:
Ctrl+O, Enter, Ctrl+X
nohup mosquitto -c /etc/mosquitto/conf.d/ca.conf >> /dev/null 2>&1 &
From this point any Wi-Fi and wired sensors and actuators can be served by MQTT broker and be discoverables to each other, for the Camper assistant and for the camper's crew gadgets, but no Bluetooth sensors and actuators.
All of the Camper assistant sensors and actuators can be realized like Wi-Fi devices, but it is not effective. If two Wi-Fi devices within network, then divides Wi-Fi range in half, if three devices, then at three equal parts, if four - then at four equal parts, etc, no matter if one device transfer a full-HD video while another device transfer 4 bytes per hour.
More effective is use a Bluetooth device for transfer small amounts of data, and not utilize resources of Wi-Fi network for this.
In order for Bluetooth sensors and actuators can be served by MQTT broker, the Node.js was installed (under root user):
apt-get install gcc g++
apt-get install bluetooth bluez libbluetooth-dev libudev-dev
ln -s /usr/bin/nodejs /usr/bin/node
curl -sL https://deb.nodesource.com/setup_8.x | bash -
apt-get install -y nodejs
apt-get install libcap2-bin
setcap cap_net_raw+eip $(eval readlink -f `which node`)
curl -sL https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
apt-get update && apt-get install yarn
Note: it is not necessary to deploy the Node.js on same computer where MQTT broker was installed. It is possible to make on any computer within the camper's network (more then - on few computers). But the Bluetooth USB dongle or integrated Bluetooth adapter (described above), must be connected to the same computer, where Node.js has been deployed.
Next under ordinary (not a root) user, was entered from PC via PuTTY terminal:
sudo yarn add node-gyp
sudo yarn add bluetooth-hci-socket
sudo yarn add noble
sudo yarn add prettyjson
sudo yarn add net
sudo yarn add bleno
sudo yarn add async
sudo yarn add mqtt
sudo yarn add node-bluetooth
sudo yarn add socket.io
sudo yarn add firstname.lastname@example.org
sudo yarn add tcp-port-used
sudo yarn add mathjs
sudo yarn install
Note: if some of yarn packages listed above was installed with any errors, that mean the version of Node.js was choosed can't work under this Linux version. In this case some lower Node.js version can be installed. But before this, the ready installed version of Node.js need to purge under root user by commands "apt-get remove --purge nodejs", then "rm -r /usr/bin/node_modules". After this purge, new version of Node.js can be installed like described above, starting with command "curl -sL https://deb.nodesource.com/setup_8.x | bash -" (but with choosed version pointed), and then all listed above yarn packages need to add one more time.
From this point any Bluetooth sensors and actuators being customized as describes in this series of articles will be served by MQTT broker and be discoverables for the Camper assistant and for the camper's crew gadgets.
All Bluetooth devices within the camper's network devides in two classes:
- Bluetooth sensors, that only publish messages ("advertise" in Bluetooth terms) about camper's parameters had measured. This messages can be based on MQTT standard or not;
- Bluetooth actuators, that makes some works in physical world, reacting on commands that can be based on MQTT standard or not.
Because not so much but only 5-6 Bluetooth devices can be connected at one time to the Bluetooth dongle, camper's Bluetooth actuators not attached to the dongle permanently. Instead this, for each actuator makes "avatar" process on any computer in the camper's network, that parses messages from sensors (with no need establish "connection" in Bluetooth terms to this sensors), it makes the temporary Bluetooth connect and send commands (MQTT based or not standard messages) to the its appropriate actuator, no occupies the Bluetooth dongle for long time. Same or other one "avatar" process makes MQTT standard messages in to the camper's network about parameters of Bluetooth sensor, had been parsed based on the sensor's Bluetooth advertising data.