Python: no tags found

I have a few Ruuvitags around the house. They work fine with the official iOS app and I see all data without issues, although the range is pretty bad. So the tags are fine. I want to collect some data (like everyone else) automatically and be able to draw some nice charts and correlate stuff with our solar panel data.

So, I have an Intel NUC and installed a fresh Ubuntu 22.04 (23.04 required too much memory and the installer died). I’m using the Python library at https://github.com/ttu/ruuvitag-sensor. When trying to find the sensors none are ever found.

% pip install ruuvitag-sensor
...
% python
Python 3.10.6 (main, Mar 10 2023, 10:55:28) [GCC 11.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import ruuvitag_sensor.log
>>> from ruuvitag_sensor.ruuvi import RuuviTagSensor
>>> ruuvitag_sensor.log.enable_console()
>>> RuuviTagSensor.find_ruuvitags()
Finding RuuviTags. Stop with Ctrl+C.
Start receiving broadcasts (device hci0)
FYI: Calling a process with sudo: hciconfig hci0 reset
FYI: Spawning process with sudo: hcitool -i hci0 lescan2 --duplicates --passive
FYI: Spawning process with sudo: hcidump -i hci0 --raw
Listening lines
^CStop receiving broadcasts
{}

I left it running for a while and nothing was ever found. Some setup data:

% hciconfig
hci0:	Type: Primary  Bus: USB
	BD Address: 30:E3:7A:D3:47:C5  ACL MTU: 1021:4  SCO MTU: 96:6
	UP RUNNING
	RX bytes:536079 acl:0 sco:0 events:19871 errors:0
	TX bytes:54775 acl:0 sco:0 commands:742 errors:0

Doing a manual scan does find a lot of stuff and also the sensors:

% sudo hcitool lescan
LE Scan ...
75:C8:08:40:32:C8 (unknown)
75:C8:08:40:32:C8 (unknown)
46:E2:9E:AE:C2:59 (unknown)
46:E2:9E:AE:C2:59 (unknown)
59:26:89:62:AD:D7 (unknown)
59:26:89:62:AD:D7 (unknown)
F0:B3:EC:01:51:10 (unknown)
F0:B3:EC:01:51:10 (unknown)
...

If I use the nicer library simple-ruuvitag from https://github.com/ruuvi-friends/simple-ruuvitag:

% pip install simple_ruuvitag
Collecting simple_ruuvitag
  Downloading simple_ruuvitag-0.0.8-py3-none-any.whl (9.9 kB)
Collecting bleson==0.1.8
  Downloading bleson-0.1.8.tar.gz (25 kB)
  Preparing metadata (setup.py) ... done
Using legacy 'setup.py install' for bleson, since package 'wheel' is not installed.
Installing collected packages: bleson, simple_ruuvitag
  Running setup.py install for bleson ... done
Successfully installed bleson-0.1.8 simple_ruuvitag-0.0.8

With this library I can create a small app that’s pretty similar to the official one:

import datetime
from time import sleep
from simple_ruuvitag import RuuviTagClient

macs = ["dc:2c:0d:0d:db:9a",
        "fd:07:ae:49:b0:bc",
        "FF:28:1A:19:B1:98"]

def handle_callback(mac_address, data):
    mac = data["mac"]
    temperature = data["temperature"]
    humidity = data["humidity"]
    pressure = data["pressure"]

    print(f"{datetime.datetime.now()} {mac}: temperature: {temperature}, hum: {humidity}, pressure: {pressure}")

def main():
    ruuvi_client = RuuviTagClient(callback=handle_callback, mac_addresses=macs)
    ruuvi_client.start()

    while True:
        ruuvi_client.rescan()
        sleep(5)

if __name__ == '__main__':
    main()

This app gives me:

% (venv) sudo ./ruuvi-server.py
2023-06-02 08:11:21,250   INFO -                bleson.py: 49 -                 __init__(): Observing broadcasts (device 0)
2023-06-02 08:11:21.374440 dc2c0d0ddb9a: temperature: 21.11, hum: 31.95, pressure: 1012.79
2023-06-02 08:11:21.602240 fd07ae49b0bc: temperature: 9.43, hum: 64.41, pressure: 1012.76
2023-06-02 08:11:21.700142 ff281a19b198: temperature: 21.12, hum: 38.49, pressure: 1011.59
2023-06-02 08:11:22.893090 fd07ae49b0bc: temperature: 9.43, hum: 64.41, pressure: 1012.76
2023-06-02 08:11:22.990085 ff281a19b198: temperature: 21.12, hum: 38.49, pressure: 1011.59
2023-06-02 08:11:24.173102 fd07ae49b0bc: temperature: 9.41, hum: 64.38, pressure: 1012.76
2023-06-02 08:11:24.269107 ff281a19b198: temperature: 21.12, hum: 38.49, pressure: 1011.59
...

It seems to catch all the announcements and the data looks sane (assuming you think 9.43C in June is sane). So clearly the machine is able to get all data, but why would the official API not be able to do anything useful? The simple-ruuvitag library works fine, but it hasn’t been updated in three years and it’ll likely break sooner or later and I would rather be riding the official train.

Any ideas?

Maybe @otso would have some ideas regarding this.

Hello,

It seems that the simple-ruuvitag uses Bleson as Bluetooth backend, you could try using ruuvitag-sensor with Bleson too: GitHub - ttu/ruuvitag-sensor: Python package for communicating with RuuviTag BLE Sensor and for decoding sensor data from broadcasted data

My guess is that something has broken in the default HCI-backend. which is why the ruuvitag-sensor does not receive data.

Well, for now simple-ruuvitag does seem to work fine without any real issues so I’ll stick with that. The official package doesn’t seem to offer any real benefits and the API is more or less identical too.
But someone may at some point want to check out the Python package to see that it still works as expected.