# BLE gateway

# Receiving signals from BLE beacon devices for Presence detection

Subscribe to all the messages with mosquitto or open your MQTT client software:

sudo mosquitto_sub -t +/# -v

NOTE: HM-10 or HM-11 module needed if you are not using ESP32; configure in user_config.h

The BT gateway module for OpenMQTTGateway enables the detection of BLE beacons and their signal strength. Generally BLE devices will not broadcast if they are paired so you may need to ensure your beacons is unpaired before it will be seen by the gateway.

If beacons are detected the gateway will periodically publish messages to MQTT (beacons must not be paired, see above):

home/OpenMQTTGateway/BTtoMQTT/45E174126E00 {"id":"45:e1:74:12:6e:00","rssi":-89,"distance":21.51847,"servicedata":"fe0000000000000000000000000000000000000000"}
1
home/OpenMQTTGateway/BTtoMQTT/C7FaaD132C00 {"id":"c7:fa:ad:13:2c:00","rssi":-68,"distance":2.799256,"servicedata":"drfgdrgdsrgesrdgdrgdregesrgtrhtyhtfyhdtyhh"}
1

The subtopic after home/BTtoMQTT/ is the MAC address of the Bluetooth low energy beacon. The rssi value is the RSSI signal level from which you may deduce the relative distance to the device. Consider the distance as a beta featuer as currently we are not retrieving the emitting power of the beacon to make it more accurate.

Note that you can find apps to simulate beacons and do some tests like Beacon simulator

IOS version >=10 devices advertise without an extra app a mac address, nevertheless this address changes randomly and cannot be used for presence detection. You must install an app to advertise a fixed MAC address.

# Receiving signals Mi Flora/ Mi jia device/ LYWDS02, ClearGrass or Mi scale

So as to receive BLE sensors data you need either a simple ESP32 either an ESP8266/arduino + HM10/11 with firmware >= v601 The mi flora supported firmware is >3.1.8

Verify that your sensor is working with the App and update it with the last software version. You should see in your MQTT broker the following data:

Note that the gateway return one or two measurement value each time. The different measures depending on the devices are:

  • Lux
  • Temperature
  • Moisture
  • Fertilization
  • Weight
  • Impedance
  • Battery (mi jia only)

The infos will appear like this on your MQTT broker:

home/OpenMQTTGateway/BTtoMQTT/4C33A6603C79 {"hum":"52.6","tem":"19.2"}

More info are available on my blog (especially about how it was implemented with HM10)

# Setting a white or black list

A black list is a list of mac adresses that will never be published by OMG to set black list mosquitto_pub -t home/OpenMQTTGateway/commands/MQTTtoBT/set -m '{"black-list":["012314551615","4C6577889C79","4C65A6663C79"]}'

A white list is a list of mac adresses permitted to be published by OMG to set white list mosquitto_pub -t home/OpenMQTTGateway/commands/MQTTtoBT/set -m '{"white-list":["012314551615","4C65A5553C79","4C65A6663C79"]}'

Note: if you want to filter (white or black list) on BLE sensors that are auto discovered, you need to wait for the discovery before applying the white or black list

# Setting the time between scans and force a scan

If you want to change the time between readings you can change the interval by MQTT, if you want the BLE scan every 66seconds:

mosquitto_pub -t home/OpenMQTTGateway/commands/MQTTtoBT/set -m '{"interval":66000}'

you can also force a scan to be done by the following command:

mosquitto_pub -t home/OpenMQTTGateway/commands/MQTTtoBT/set -m '{"interval":0}'

Once done the previous value of interval will be recovered.

# Other

To check your hm10 firmware version upload a serial sketch to the nodemcu (this will enable communication directly with the hm10) and launch the command: AT+VERR?

More info about HM-10 is available here