项目作者: roinou

项目描述 :
Cast BlueMaestro BLE devices to MQTT
高级语言: JavaScript
项目地址: git://github.com/roinou/blueCast.git
创建时间: 2019-11-11T15:12:20Z
项目社区:https://github.com/roinou/blueCast

开源协议:

下载


BlueCast

BlueCast brings Blue Maestro sensors to MQTT.
It will discover BLE devices and report to MQTT valid readings.

Prerequisites

BlueCast depends on Noble and MQTT. Refer to Noble project for advance installation instructions.

How does it works?

In order to preserve resources, discovery of BLE devices is only run after a message is received on a control topic: $bluecastTopic/ctl.
Discovery will run for a certain amount of time, and all valid readings will be published to relevant topics.

Readings

Given Noble and BlueZ separate the scan request and scan response data, 2 types of messages can be read:

  • scan request: contains instant readings, such as temperature, humidity, dew point
  • scan response: contains statistic data, such as min/max and 24h average

Full reading will be published in a JSON object, e.g.:

  1. {
  2. "data": {
  3. "battery": 100,
  4. "breachCount": 0,
  5. "humidity": 92.3,
  6. "mode": 53,
  7. "temperature": 6.2,
  8. "timeInterval": 3600,
  9. "timeIntervalPosition": 6000,
  10. "version": 27
  11. },
  12. "name": "terasse",
  13. "timestamp": "2019-11-30T14:09:59.175Z",
  14. "version": 27
  15. }
  1. {
  2. "data": {
  3. "average24Temperature": 19.8,
  4. "average24humidity": 45.7,
  5. "globalIdentifier": 0,
  6. "highest24Humidity": 49.4,
  7. "highest24Temperature": 20.6,
  8. "highestHumidity": 79.8,
  9. "highestTemperature": 29.9,
  10. "lowest24Humidity": 41.7,
  11. "lowest24Temperature": 19.3,
  12. "lowestHumidity": 37,
  13. "lowestTemperature": 18,
  14. "referenceData": 1811072320
  15. },
  16. "name": "living",
  17. "timestamp": "2019-11-30T14:09:58.580Z",
  18. "version": 23
  19. }

But individual readings will be put in specific topics:
$bluecastTopic/$sensorName/temperature, $bluecastTopic/$sensorName/humidity, $bluecastTopic/$sensorName/battery

Configuration

The following environment properties configure BlueCast:

  • MQTT_HOST: the mqtt hostname
  • TOPIC_NAME: the base name for the MQTT topic
  • SCAN_TIME: the amount in time, in milliseconds, to run discovery when message received on topic
  • DEBUG info|debug: log level (comma separated)
  • NOBLE_REPORT_ALL_HCI_EVENTS: if 1, will report both scan request and scan response (needed on Raspberry Pi)

Installation

In order to install as service, create the following environment file /etc/default/bluecast:

  1. NOBLE_REPORT_ALL_HCI_EVENTS=1
  2. DEBUG=info
  3. ## Default values
  4. #MQTT_HOST=localhost
  5. #TOPIC_NAME=sensor
  6. #SCAN_TIME=5000

Create a system user: sudo useradd -m --system bluecast

And the following service file /etc/systemd/system/bluecast.service:

  1. [Unit]
  2. Description=BlueCast
  3. After=syslog.target network-online.target
  4. [Service]
  5. Type=simple
  6. User=bluecast
  7. EnvironmentFile=/etc/default/bluecast
  8. WorkingDirectory=/home/pi/project/bluecast
  9. ExecStart=/usr/bin/node index.js
  10. Restart=on-failure
  11. RestartSec=3
  12. KillMode=process
  13. [Install]
  14. WantedBy=multi-user.target

And enable the service: sudo systemctl daemon-reload; sudo systemctl enable bluecast; sudo systemctl start bluecast

And check the logs: sudo journalctl -f -n 200 -u bluecast

make sure to check Noble’s project for complete instalation procedure, e.g. sudo setcap cap_net_raw+eip $(eval readlink -fwhich node)

Application

This project can be used in conjunction with homebridge and plugins
homebridge-mqtt-temperature and
homebridge-mqtt-humidity with the following config:

  1. "accessories": [
  2. {
  3. "accessory": "mqtt-temperature",
  4. "name": "Pupuce Temperature",
  5. "url": "mqtt://centralpi",
  6. "topic": "sensor/pupuce/temperature",
  7. "batt_topic": "sensor/pupuce/battery",
  8. "refresh_topic": "sensor/ctl"
  9. },
  10. {
  11. "accessory": "mqtt-humidity",
  12. "name": "Studio Humidity",
  13. "url": "mqtt://centralpi",
  14. "topic": "sensor/studio/humidity",
  15. "batt_topic": "sensor/studio/battery",
  16. "refresh_topic": "sensor/ctl"
  17. },
  18. ]