https://github.com/rroemhild/pycom-ruuvitag
Pycom MicroPython RuuviTag BLE Sensor Beacon scanner
https://github.com/rroemhild/pycom-ruuvitag
bluetooth esp32 iot micropython pycom ruuvitag
Last synced: about 2 months ago
JSON representation
Pycom MicroPython RuuviTag BLE Sensor Beacon scanner
- Host: GitHub
- URL: https://github.com/rroemhild/pycom-ruuvitag
- Owner: rroemhild
- License: mit
- Created: 2018-01-11T16:44:25.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2021-02-15T20:23:23.000Z (about 4 years ago)
- Last Synced: 2025-03-15T00:47:52.616Z (about 2 months ago)
- Topics: bluetooth, esp32, iot, micropython, pycom, ruuvitag
- Language: Python
- Homepage:
- Size: 48.8 KB
- Stars: 23
- Watchers: 7
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.rst
- License: LICENSE.md
Awesome Lists containing this project
README
==================================
Pycom MicroPython RuuviTag Scanner
==================================Harvest data from `RuuviTag BLE Sensor Beacon `_ with the `Pycom `_ devices.
**This repository was renamend from ``micropython-ruuvitag`` to ``pycom-ruuvitag`` as for this version only works on the Pycom devices and to use the namespace ``micropython-ruuvitag`` for the upstream MicroPython version.**
pycom-ruuvitag supports `Data Format 2, 3, 4 and 5 `_.
This package comes with a scanner and a tracker. The scanner scans for RuuviTags in a pre defined time and return the result. The tracker continuously scans for RuuviTags and call a callback for each tag found.
Installation
------------With Pymakr you can upload the project to your pycom device. ``pymakr.conf`` makes sure that only the relevant files are copied to your device.
Scanner
-------``RuuviTagScanner`` scans for RuuviTags and decode the data format. The result is a list with named tuples.
Scan 10 seconds for RuuviTag sensors and print the result:
.. code-block:: python
from ruuvitag.scanner import RuuviTagScanner
rts = RuuviTagScanner()
for ruuvitag in rts.find_ruuvitags(timeout=10):
print(ruuvitag)Tracker
-------``RuuviTagTracker`` scans for RuuviTags, decode the data format and call a callback with a named tuple if recieved data from tag.
.. code-block:: python
from ruuvitag.tracker import RuuviTagTracker
def cb(ruuvitag):
print(ruuvitag)rtt = RuuviTagTracker()
rtt.track_ruuvitags(cb)Whitelist devices
-----------------You can collect data from only the devices you want by define a whitelist with mac addresses. Other Devices then will be ignored. Whitelists can be used with RuuviTagScanner and RuuviTagTracker.
.. code-block:: python
whitelist = (b'aa:bb:cc:dd:ee:21', b'aa:bb:cc:dd:ee:42',)
rts = RuuviTagScanner(whitelist)Blacklist persistence
---------------------If the data from a Bluetooth device can not be decoded, the device get on a blacklist as long the MicroPython device is not resetted. For a persistent device blacklist the list should be saved and reloaded.
>>> from ruuvitag import RuuviTagScanner
>>> rts = RuuviTagScanner()
>>> # add back blacklisted devices
>>> rts.blacklist = [b'aa:bb:cc:dd:ee:21', b'aa:bb:cc:dd:ee:42']
>>> # run a new scan
>>> rts.find_ruuvitags(timeout=10)
>>> # get blacklisted devices
>>> rts.blacklistNamed tuple formats
-------------------Data Format 2 and 4 (Eddystone-URL)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~.. code-block:: python
RuuviTagURL = namedtuple('RuuviTagURL', (
'mac',
'rssi',
'format',
'humidity',
'temperature',
'pressure',
'id',
))Data Format 3 (RAWv1) and 5 (RAWv2)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~.. code-block:: python
RuuviTagRAW = namedtuple('RuuviTagRAW', (
'mac',
'rssi',
'format',
'humidity',
'temperature',
'pressure',
'acceleration_x',
'acceleration_y',
'acceleration_z',
'battery_voltage',
'power_info',
'movement_counter',
'measurement_sequence',
)).. |pypi| image:: https://img.shields.io/pypi/v/micropython-ruuvitag.svg
:target: https://pypi.python.org/pypi/micropython-ruuvitag/
:alt: PyPi Status