BLE to MQTT Application - Python

Hey All,

I created some Python modules and an application to leverage them to create a useful ble gateway.

The application works great on Linux PC’s ranging from more powerful laptops to Raspberry Pi’s.

The application decodes and sends Ruuvi RAW v1 and RAWv2 data, as well as Eddystone TLM data.

The code and instructions can be found at:

Any feedback would be greatly appreciated.

1 Like

Hey All,

Updated the above application so it now supports http and influxDB endpoints, It should be a drop in replacement for ruuvicollecor if you are unable to get it work on a device like a RPI Zero which I was having issues building it on.

It is able to send data to multiple endpoints at once.

Any feedback would be great.

1 Like

Followed your instructions as best as I could on a brand new raspberry pi 4 with current raspbian buster freshly installed.

First attempt with python3 main.py gave:

FileNotFoundError: [Errno 2] No such file or directory: ‘config/testblegateway.json’

So I copied my editted blegateway.json to testblegateway.json.

Then trying to start again by

Running python3 main.py gives the following errors:

Traceback (most recent call last):
File “/home/pi/ble-gateway/config.py”, line 5, in
config = json.load(open(‘config/testblegateway.json’,))
File “/usr/lib/python3.7/json/init.py”, line 296, in load
parse_constant=parse_constant, object_pairs_hook=object_pairs_hook, **kw)
File “/usr/lib/python3.7/json/init.py”, line 348, in loads
return _default_decoder.decode(s)
File “/usr/lib/python3.7/json/decoder.py”, line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File “/usr/lib/python3.7/json/decoder.py”, line 353, in raw_decode
obj, end = self.scan_once(s, idx)
json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 25 column 3 (char 481)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “main.py”, line 4, in
import blegateway
File “/home/pi/ble-gateway/blegateway.py”, line 4, in
import config
File “/home/pi/ble-gateway/config.py”, line 7, in
config = json.load(open(‘config/blegateway.json’,))
File “/usr/lib/python3.7/json/init.py”, line 296, in load
parse_constant=parse_constant, object_pairs_hook=object_pairs_hook, **kw)
File “/usr/lib/python3.7/json/init.py”, line 348, in loads
return _default_decoder.decode(s)
File “/usr/lib/python3.7/json/decoder.py”, line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File “/usr/lib/python3.7/json/decoder.py”, line 353, in raw_decode
obj, end = self.scan_once(s, idx)
json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 25 column 3 (char 481)

At this point my poor python understanding was overwhelmed and I gave up.

Just trying to use the built-in BLE chip in the raspberry pi4 to read my brand new ruuvitag.

Thanks in advance for any help!

Hey,

You only need to edit blegateway.json. The below should work with mqtt and the onboard RPI ble.

{
  "bleDevice" : {
    "bleDevice" : 0
  },
  "filters" : {
    "eddystone" : false,
    "ibeacon" : false,
    "ruuvi" : true,
    "ruuviPlus" : true,
    "unknown" : false,
    "rssiThreshold" : false,
    "rssi" : -60,
    "macFilterEnabled" : false,
    "macFilter" : [
      "FFFF96C5A1EE",
      "D8FFFFFFFD7A",
      "FFFFFF284268"
    ]
  },
  "names" : {
    "ENTERMAC" : "My Ruuvi"
  },
  "identifiers" : {
    "interface" : "wlan0",
    "location" : "home",
    "zone" : "rpi4",
    "gatewayType" : "Pi4"
  },
  "endpoints" : {
      "mqttEnabled" : true,
      "httpEnabled" : false,
      "influxEnabled" : false
  },
  "mqtt" : {
    "host" : "127.0.0.1",
    "port" : 1883,
    "user" : null,
    "password" : null,
    "ssl" : false,
    "ca" : null,
    "cert" : null,
    "key" : null
  },
  "http" : {
    "host" : "127.0.0.1",
    "port" : 443,
    "user" : null,
    "password" : null,
    "ca" : null,
    "cert" : null,
    "key" : null
  },
  "influx" : {
    "host" : "127.0.0.1",
    "port" : 8086,
    "database" : "ruuvi",
    "user" : null,
    "password" : null
  }
}