Python - ruuvitag_sensor package


#14

The new version is working as expected. Thanks!


#15

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?


#16

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.


#17

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:


#18

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


#22

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?


#23

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…


#24

Thanks for the info! I’ll check newer version of Bluez and maybe modify BLE communication to use bluetoothctl and btmgmt. At least I will try to find some solution for BLE communication that would work with all different distros.


#25

Are you @ttu having any plans on adding support for the new RuuviTag sensor packet format (Data Format 3)? I’ve hacked your code a bit to get some data out but I have not put much effort into it.


#26

I was planning to check it this weekend as we have a 4 day holiday in Finland, so it’s a perfect time to do some coding :slight_smile: I created a new branch for it (https://github.com/ttu/ruuvitag-sensor/tree/experimental-weatherstation), so if you have some code ready you and you want to publish it, you can create a pull request there.


Test of humidity in closed versus open enclosure
#27

Ok, it was a small fix, so made it already. At least it looks like it is working. Still need to update README etc. so it will take some time and then will publish new version to pypi. Now the development version from the experimental-weatherstation branch can be installed with pip:

$ pip3 install git+https://github.com/ttu/ruuvitag-sensor@experimental-weatherstation

Added identifier to sensor data. Older weatherstations will have it None.

{
'CA:F7:44:DE:EB:E1': {'temperature': 22.0, 'humidity': 28.0, 'pressure': 991.0, 'identifier': None}, 
'F4:A5:74:89:16:57': {'temperature': 23.24, 'humidity': 29.0, 'pressure': 991.0, 'identifier': '0'}
}

#28

Nice, it works as it should for the Eddystone URL.
But I must have been a bit confused before because what I had been doing was to add a interpreter for the Eddystone protocol (the GAP manufacturer specific data), i.e. when the RuuviTag is in red-blinking-mode. I’ll continue on this work some more.


#29

Sorry my bad. Somehow mixed numbers 3 and 4 in my head…

Data Format 4 is now on main branch, but not yet released.

I committed initial implementation of Data Format 3 to GitHub (https://github.com/ttu/ruuvitag-sensor/tree/data-format-3). Humidity, pressure, temperature and battery seem to show correct values, but acceleration calculation still needs a correct implementation.


#30

Ok, I’ll have a look at that!
In the longer run I’m aiming to connect the tags to Home Assistant (or similar Home automation software). For HA it exists a BLE tracker component but not a component for BLE sensors. I guess it would be nice to have a standardised packet format for sensor data to make it easy to connect various types of BLE sensors. The unencrypted Eddystone-TLM packet does only include temperature and battery voltage unfortunately. The encrypted TLM version has however 12 bytes of Encrypted TLM data available. Have you used any Home automation software or have any other thoughts on this @ttu?


#31

Last summer I was checking Home Assistant and because of that I decided to make this Python package :slight_smile:

I made some fixes for HA’s Sony Bravia component, so I had some minor understanding how HA works, but in the end didn’t have time to start figuring out how to properly get data from BLE sensors.

One way to use RuuviTags with Home Assistant would be running a HTTP Server and getting values with a web request. I made similiar thing with Arduino’s weather board and Home Assistan’s REST platform. Not pretty, but works.


#32

I have been using Domoticz for many years and it’s been working alright but it is a nightmare to make your own fixes for. HA seems much more promising.
I have now made a simple parser that uses your Python sensor package to get sensor data (format 3, not url) and stores them in an InfluxDB. Then I use Grafana to display the data from the database. There exist two InfluxDB components for HA already so I will look more into that.


#33

That InfluxDB solution with HA is much better. Have to check that also. Thanks for the tip.


#34

Hi,
Thanks for sharing this library but I have encountered some issues. I have just followed the install notes for ruuvitag_sensor.ble_communication.
before doing so I checked sudo hcitool lescan which listed addresses and names of devices such as Ruuvitags and puck.js decices I have localy
eg
sudo apt-get install bluez-hcidump
pip3 install --user ruuvitag-sensor
some warnings but notthing critical
python3 /home/pi/.local/lib/python3.4/site-packages/ruuvitag_sensor -h
respond with : usage: ruuvitag_sensor [-h] [-g MAC_ADDRESS] [-f] [-l] [-s] [–version] …

python3 /home/pi/.local/lib/python3.4/site-packages/ruuvitag_sensor -f
<No devices detected here so ended with ctrl+c>
Finding RuuviTags. Stop with Ctrl+C.
Start receiving broadcasts
^CStop receiving broadcasts
I then had the same result eg No output using python3 tag_test.py

I then tried the print_ble.py code you suggested on 28 April:
from ruuvitag_sensor.ble_communication import BleCommunicationNix
ble = BleCommunicationNix()
for ble_data in ble.get_datas():
print(ble_data)

This displayed lots of data such as
(‘C5:60:B7:C1:xx:xx’, ‘1702010504160918150E0952757576695461672034316437BF’)
(‘C5:60:B7:C1:xx:xx’, ‘1211079ECADC240EE5A9E093F3A3B50100406EBE’)

Then I saw that you provided advice to install from github so I tried:

pip3 install --user git+https://github.com/ttu/ruuvitag-sensor --upgrade
Downloading/unpacking git+https://github.com/ttu/ruuvitag-sensor
Cloning https://github.com/ttu/ruuvitag-sensor to /tmp/pip-6pvyjlve-build
Running setup.py (path:/tmp/pip-6pvyjlve-build/setup.py) egg_info for package from git+https://github.com/ttu/ruuvitag-sensor

Requirement already up-to-date: psutil in ./.local/lib/python3.4/site-packages (from ruuvitag-sensor==0.6.0)
Requirement already up-to-date: rx in ./.local/lib/python3.4/site-packages (from ruuvitag-sensor==0.6.0)
Installing collected packages: ruuvitag-sensor
Found existing installation: ruuvitag-sensor 0.6.0
Uninstalling ruuvitag-sensor:
Successfully uninstalled ruuvitag-sensor
Running setup.py install for ruuvitag-sensor

Successfully installed ruuvitag-sensor
Cleaning up…

After the above - no change in the output of python3 /home/pi/.local/lib/python3.4/site-packages/ruuvitag_sensor -f
Start receiving broadcasts
<>
python3 print_ble.py Still works as expected

I should add that I have 3 Ruu.vi sensorTags one running Weather Station, one running Eddystone and one running Espruino as well as several puck.js devices in the area.

I am running Python 3.4.2

Do you have any advice on how to resolve the above?

James

PS. I have subsequently seen advice to turn on logging to console. I have tried the following but no change in results.

tag_find.py:
from ruuvitag_sensor.ruuvi import RuuviTagSensor
import ruuvitag_sensor.log
ruuvitag_sensor.log.enable_console()
RuuviTagSensor.find_ruuvitags()


#35

Thanks for the bug report! Let’s try to figure out what is wrong.

print_ble.py prints all BLE devices that are found, not only RuuviTags, so are both of these RuuviTags?

('C5:60:B7:C1:xx:xx', '1702010504160918150E0952757576695461672034316437BF')
('C5:60:B7:C1:xx:xx', '1211079ECADC240EE5A9E093F3A3B50100406EBE')

Can you check if you have some info in ruuvitag_sensor.log file? All errors should be logged there.

I chaged logging and console print few days ago to match more Python best practices, so if you use the version from GitHub, then you need to enable console logging “manually”.


#36

Hi, Thanks for that.
Firstly, the library version 0.6.0 was downloaded yesterday 7 June. Initially installed using Pip and later installed from github.
$ python3 /home/pi/.local/lib/python3.4/site-packages/ruuvitag_sensor --version
ruuvitag_sensor 0.6.0

I am not sure what you mean by enable console manually.
That data was from a Ruu.vi tag with espruino installed.
The Weather Station Ruu.vi with firmware downloaded in May (April Code) advertisements as follows:
(‘FA:08:56:5C:XX:XX’, ‘1F0201060303AAFE1716AAFE10F9037275752E76692F2342474156414D435571BB’)

(‘FA:08:56:5C:XX:XX’, ‘1F0201060303AAFE1716AAFE10F9037275752E76692F2342474156414D435571BE’)

(‘FA:08:56:5C:XX:XX’, ‘1F0201060303AAFE1716AAFE10F9037275752E76692F2342474156414D435571BA’)

Does this narrow things down?

As for log - that’s empty!

However, I have just run the find code again ad its now reporting the weather station data… How weird is that? Maybe it was connected to something when I tried before. For the record it outputs as follows:
python3 tag_find.py
Finding RuuviTags. Stop with Ctrl+C.
Start receiving broadcasts
FA:08:56:5C:XX:XX
{‘temperature’: 21.0, ‘pressure’: 993.0, ‘humidity’: 48.0, ‘identifier’: ‘q’}