Python - ruuvitag_sensor package

Python library for communicating with RuuviTag BLE Sensor Beacons and for decoding sensor data from broadcasted eddystone-url.

Package: PyPI
Source code and instructions: GitHub

CHANGELOG

3 Likes

Awesome, well done.

Would love to see a tutorial how to setup a Raspberry Pi 3 to run this :innocent:

2 Likes

Added an installation guide to GitHub.

Raspberry Pi & Raspbian installation guide

4 Likes

Works great! :smile:

1 Like

Great instuctions!
I got some problems when trying to find beacons with tag_test.py, it says Set scan parameters failed: Input/output error. Using

hcitool lescan

pi finds beacon’s mac address. Any ideas what might be wrong? (double checked typos and packages already)

Did this work?

$ python3 /home/pi/.local/lib/python3.4/site-packages/ruuvitag_sensor -f

I wouldn’t be surprised if sometimes RuuviTagSensor won’t kill itself properly when using Crl+C and is still using bluetooth. If you see python3 in the list, kill it.

$ ps
$ kill -9 [PID]

If that is not the problem, let’s continue with these. Can you see hci0 with this command?

$ hcitool dev

Try to restart all devices

$ sudo service bluetooth restart
$ sudo service dbus restart
$ sudo hciconfig hci0 restart

Maybe some other application is accessing bluetooth, try reboot

$ reboot

As you see we follow basic it-support guideline: have you tried turning it off and on again? :slight_smile:

Great library! However, I’m also having some problems. I have three RuuviTags but the library is only able to find one or two (varies between restarts). hcitool shows all the tags and I have verified that the tags are working properly. I’m running the lib on Raspberry Pi 3.

Can you create this file and name it e.g. print_ble.py

from ruuvitag_sensor.ble_communication import BleCommunicationNix

ble = BleCommunicationNix()

for ble_data in ble.get_datas():
    print(ble_data)

Execute it and you should see all your bluetooth devices and data they are broadcasting

$ python3 print_ble.py

Can you see all your RuuviTags in the output?

If yes, can you send me the data they are broadcasting so I can check what I have wrong in the code.

Hi!
I’m new to Ruuvi and quite new to Python as well. I have successfully tried most of the examples but today when I tried the “http_server_asyncio_rx.py” by “ttu” I get the following error:

ModuleNotFoundError: No module named ‘ruuvitag_sensor.ruuvi_rx’

Is the ruuvi_rx module not included in the ruuvitag_sensor package? Or how do I install it?
Just to be clear, the ruuvitag_sensor package works as intended (both in Python 3.4 and 3.6), e.g. “ruuvitag_sensor -f” finds my sensors.

ruuvi_rx is not yet in the version 0.4.0 that can be installed from PyPI.

You can install developement version straight from the GitHub instead of from the Python Package Index. Upgrade parameter is needed so it will uninstall already installed version.

$ pip3 install --user git+https://github.com/ttu/ruuvitag-sensor --upgrade

I will add the link to the changelog to the first post, so it is little bit easier to see what is released to PyPI and what can be found only from development version.

Good to hear that everything else was working and hope you get some nice development ideas from the examples :slight_smile:

Edit: version 0.5.0 with ruuvi_rx is in pypi

1 Like

Now it works like a charm. Thanks!
My plan is to make a component for Home Assistant to get temp+humidity sensor data. I’m a bit surprised that no one has made an Eddystone TLM component yet (just BLE tracking).

ble.get_datas() seems to find all my tags. I sent you the log.

Thanks for the log! Made a fix for data decode based on those datas. Released a new version with a fix, so upgrade from pypi.

The new version is working as expected. Thanks!

Sorry to bother about this again but I tried a clean installation on a new RPi today and installed Python3.6 and ruuvitag-sensor 0.5. But when I run the “http_server_asyncio_rx.py” on the new machine I get the old error?

$ python3 http_server_asyncio_rx.py 
Traceback (most recent call last):
  File "http_server_asyncio_rx.py", line 14, in <module>
from ruuvitag_sensor.ruuvi_rx import RuuviTagReactive
  File "/home/pi/.local/lib/python3.6/site-packages/ruuvitag_sensor/ruuvi_rx.py", line 6, in <module>
from rx.subjects import Subject
  File "/home/pi/ruuvi/rx.py", line 6, in <module>
from ruuvitag_sensor.ruuvi_rx import RuuviTagReactive
ImportError: cannot import name 'RuuviTagReactive'

Checking version:

$ python3 /home/pi/.local/lib/python3.6/site-packages/ruuvitag_sensor --version
ruuvitag_sensor 0.5.0

Isn’t this a bit weird?

Rename rx.py from the examples folder to e.g. reactive_extensions.py. Because rx.py is in the same folder with http_server_asyncio_rx.py that you are executing, it is messing up with import from rx.subjects. Renamed that file also from the GitHub repository, so that won’t happen again.

1 Like

Thank you very much, but I didn’t get to work with these or tons of other tips. I finally installed the latest version of Raspbian and got it to work :slight_smile:

I played a bit with the Ruuvitag, my new Pi Zero W and a blinkt! HAT.
I used your code from the print_to_screen example.
You may find more details here: https://www.instructables.com/id/RuuviTag-and-PiZero-W-And-Blinkt/
Regards, H

1 Like

I’ve got the information that the Pi Zero W uses a different bluetooth hardware (4.0). Any problems setting it up to communicate with the RuuviTag?

I had a struggle while I was trying to get this work on Arch Linux. It seems that since bluez 5.44, hcitools as well as some other tools are deprecated and are no longer included in current version of bluez-utils. This will eventually apply to other distros as well. Thus, some other tools such as bluetoothctl or btmgmt should be used instead…