Gateway to connect BLE sensors to Thingsboard. BLE sensors are detected via Eddystene Beacon-URI. The data is processed and formed into a JSON file compatible with the Thingsboard MQTT Gateway API.
The python script is based on the BlueZ D-Bus API. It prints the JSON data to stdout and debug information to stderr. The following commands executes the script pipes the output from stdout to data.out, it pipes the debug information from stderr to ts which creates a timestamp and finally stores the logging information in gateway.log.
$ ./gateway.py 2>&1 >> data.out | ts "%Y-%m-%d %T" >> gateway.logThe content from data.out is piped to mosquitto_pub to transfer the data to a MQTT broker. The log output is piped to ts and stored in mosquitto_pub.log.
mosquitto_pub -d -h "${MQTT_HOST}" -p "${MQTT_PORT}" -t "${MQTT_TOPIC}" -u "${MQTT_USER}" -l < data.out 2>&1 | ts "%Y-%m-%d %T" >> mosquitto_pub.logA docker image is provided to run the following script.
apt-get install docker.io
In order to install the gateway docker image, you need to create/modify a config file, build and run the docker image.
cat > config << EOF
MQTT_HOST=tba.tba.tba
MQTT_PORT=1883
MQTT_USER=TBA
MQTT_TOPIC=path/to/topic
EOF
docker build -t thingsboard_gateway .Run it, autostart enabled:
docker run -d --env-file config --privileged -v /var/run/dbus:/var/run/dbus thingsboard_gateway:latestAlternatively, you can use docker-compose to build and run the docker image in the background:
docker-compose up -d