README ¶
ble-sensor-mqtt
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 devices
Supported and tested devices are:
- iNode Care Sensor PHT
- ATC firmware for Xiaomi Miija (LYWSD03MMC) device
Basis of operation
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
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
Configuration
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:
- type -
ATC
orinode
. Others will be ignored. - name - friendly name, used in mqtt topic: Full topic is
{topicPrefix}/{name}
. - topicPrefix - MQTT prefix. Name has to contain only characters supported by MQTT topics.
Alternatively, these options could be overriden by using environment variables.
Supported 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 ismac,type,name
, e.g.BLE_DEVICE_0=aa:bb:cc:dd:ee:ff,ATC,example
,#
is a number.
Building
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.
Ready to use docker images
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
License
- MIT
Dependencies
Documentation ¶
There is no documentation for this package.