make your own website for free

MQTT broker and Bluetooth (LE) MQTT gateway

what makes adding or removing electronic assistants (Bluetooth, Wi-Fi and wired) easy


Main components:
- any single-board computer, Armbian (Debian) based in this case,
- 4.0 Bluetooth USB dongle,
- the camper’s router.

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

nano /etc/mosquitto/conf.d/ca.conf

In the opened file was entered strings:

listener 1883

protocol mqtt

listener 9001

protocol websockets

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++ make

apt-get install bluetooth bluez libbluetooth-dev libudev-dev

ln -s /usr/bin/nodejs /usr/bin/node

curl -sL | bash -

apt-get install -y nodejs

apt-get install libcap2-bin

setcap cap_net_raw+eip $(eval readlink -f `which node`)

curl -sL | sudo apt-key add -

echo "deb 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:

cd /usr/bin/

sudo yarn add node-gyp

sudo yarn add bluetooth-hci-socket@npm:@abandonware/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

sudo yarn add express@4.15.2

sudo yarn add tcp-port-used

sudo yarn add mathjs

sudo yarn install

Note: if some of yarn packages listed above could not install successed (critical errors occurs), 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 | 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.


A software you can load from this site is free for a non-commercial use except for components for which their owners declared their own rights. Can be limited by local laws.

No your data will be collected with a software you can load from this site.


Get updates