This project is intended to be simple application used to acquire various sensor data (mainly weather data, i.e. temperature, humidity, pressure) from Bluetooth (BLE) devices and publish them to configured MQTT broker for further processing.
Supported and tested devices are:
Application uses on-board bluetooth device (hci0) in scanning mode to listen for advertisement packets from devices. When packet is received it is parsed and sent to configured MQTT broker (so far only brokers with TLS connectivity are supported).
adv packet device present packet successfully
received in config parsed
┌──────┐ ┌───────────────────────┐ ┌─────────────────────┐ ┌─────────────────┐
│ │ │ │ │ │ │ │
│ hci0 ├──────►│ check configuration ├─────►│ parse device packet ├────►│ publish to MQTT │
│ │ │ for device │ │ │ │ │
└──────┘ └───────────────────────┘ └─────────────────────┘ └─────────────────┘
Usage of ./ble-sensor-mqtt:
-V print broadcasted messages
-as
acitve scan
-c string
config file (yaml format) (default "ble-sensor-mqtt.yml")
-pass string
mqtt password
-pfx string
topic prefix. Full topic will be {topicPre}/{deviceName} (default "/ble-sensor")
-url string
mqtt host url, e.g. ssl://host.com:8883
-user string
mqtt user name
Application looks for ble-sensor-mqtt.yml
file with all the devices configured. Example file is:
devices:
# BLE MAC address of the device
"01:02:03:04:05:06":
type: ATC # can be ATC or inode
name: room # human readable name
"02:03:04:05:06:07":
type: inode
name: second_room
options:
url: ssl://mqtt.broker.com:8883
user: username
pass: password
topicPrefix: /my-topic-prefix
activeScan: off
verbose: off
Where:
ATC
or inode
. Others will be ignored.{topicPrefix}/{name}
.Alternatively, these options could be overriden by using environment variables.
BLE_MQTT_URL
- url of mqtt host, e.g. ssl://mqtt.host.com:8883BLE_MQTT_USER
- user for mqtt host authBLE_MQTT_PASS
- pass for mqtt host authBLE_MQTT_PFX
- MQTT topicPrefix. Full topic will be {pfx}/{deviceName}
BLE_DEVICE_#
- device to add to config file, format is mac,type,name
, e.g. BLE_DEVICE_0=aa:bb:cc:dd:ee:ff,ATC,example
, #
is a number.In the easiest way, just do go build
. Golang is required (tested on Linux).
Additionally, ko is used to create minimal container with the application. To build your own container:
# install ko
go install github.com/google/ko@latest
# build image and publish to local docker
VERSION=devel ko build -L
Please see the ko documentation for additional options and how to build for other platforms.
Currently images are being built and deployed automatically to gitlab registry available here.
The images are built in several flavours: multi-platform manifest (latest and without architecture specific tags), for x86, armv6 (e.g. rpi zero), armv7 (e.g. rpi2), arm64 (e.g. rpi4).
In order to use them simply use this command:
docker pull registry.gitlab.com/mek_x/ble-sensor-mqtt:latest