Receiving BLE advertisements from RuuviTags with OpenMQTTGateway

One of my favourite Bluetooth Low Energy devices is the RuuviTag. It's a sleek environmental sensor measuring temperature, air humidity, air pressure and motion, broadcasting their values every second as BLE advertisements. Its firmware, hardware schematics and mobile apps for Android and iOS are all open source. And the company Ruuvi offers extensive developer documentation.

/images/ruuvitag.jpg

I'm also a fan of the MQTT protocol for IoT messaging. While writing my book Control Your Home with Raspberry Pi, which is all about creating a home automation gateway for Bluetooth Low Energy, Zigbee, Z-Wave and other protocols, I contributed support for the RuuviTag to bt-mqtt-gateway, a BLE to MQTT gateway I covered in the book.

Recently I have been writing a new book, about Bluetooth Low Energy programming, and as part of this endeavour I contributed support for the RuuviTag to Theengs Decoder, an efficient, portable and lightweight C++ library for BLE payload decoding. The RuuviTag RAWv1 and RAWv2 decoders have been added in Theengs Decoder v0.1.7. As Theengs Decoder is now used in OpenMQTTGateway, a gateway for various wireless protocols that you can install on an ESP32 or other devices, this means that OpenMQTTGateway v0.9.10 also detects RuuviTag advertisements.

/images/BOX-ESP32-GATEWAY-EA.jpg

To give an example, my Olimex ESP32-Gateway 1 running OpenMQTTGateway v0.9.10 detects my RuuviTag running the RAWv1 firmware and converts its BLE advertisements to the following JSON payload on MQTT: 2

{
  "id": "D7:C1:A2:D6:43:61",
  "mac_type": 1,
  "rssi": -90,
  "brand": "Ruuvi",
  "model": "RuuviTag",
  "model_id": "RuuviTag_RAWv1",
  "hum": 100,
  "tempc": 4.82,
  "tempf": 40.676,
  "pres": 1022.51,
  "accx": 0.178,
  "accy": -0.349,
  "accz": 0.96,
  "volt": 2.833
}

Another RuuviTag running the RAWv2 firmware is detected like this:

{
  "id": "C8:03:24:74:7E:0E",
  "mac_type": 1,
  "name": "Ruuvi 7E0E",
  "rssi": -88,
  "brand": "Ruuvi",
  "model": "RuuviTag",
  "model_id": "RuuviTag_RAWv2",
  "tempc": 21.165,
  "tempf": 70.097,
  "hum": 48.715,
  "pres": 1022.89,
  "accx": 0.04,
  "accy": -0.036,
  "accz": 1.036,
  "volt": 3.02,
  "tx": 4,
  "mov": 63,
  "seq": 17181
}

This is quite a straightforward format to further process these measurements in an MQTT-centric home automation system. And because Home Assistant discovery is enabled by default in OpenMQTTGateway, your RuuviTags are automatically detected in Home Assistant if you have added the MQTT integration:

/images/ruuvitag-openmqtt-gateway-ha.png
1

The Olimex ESP32-Gateway is a great board to use as a BLE gateway: it has an external antenna for a better range and it has an Ethernet port for better reliability. There's also a sleek metal box for it. And the hardware schematics of the board are open source.

2

I pretty-printed the JSON payloads with the jq command for clarity in this blog post.