RuuviTag BLE Sensor Beacon scanner.
Project description
Harvest data from RuuviTag BLE Sensor Beacon with MicroPython Bluetooth enabled micro controller like the pycom devices.
micropython-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
The easiest way to install the package is via upip:
>>> import upip >>> upip.install('micropython-ruuvitag')
For manual installation copy the ruuvitag directory with all files to your device lib directory.
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:
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.
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.
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.blacklist
Named tuple formats
Format 2 and 4 (Eddystone-URL)
RuuviTagURL = namedtuple('RuuviTagURL', (
'mac',
'rssi',
'format',
'humidity',
'temperature',
'pressure',
'id',
))
Format 3 and 5 (RAW)
RuuviTagRAW = namedtuple('RuuviTagRAW', (
'mac',
'rssi',
'format',
'humidity',
'temperature',
'pressure',
'acceleration_x',
'acceleration_y',
'acceleration_z',
'battery_voltage',
'power_info',
'movement_counter',
'measurement_sequence',
))
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Hashes for micropython-ruuvitag-0.5.2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 49f803e9c3f778708580cde6ffa1a8482a409f5e998624e5bb73112399b0cecf |
|
MD5 | be46eb870c80781afd384cab231f4338 |
|
BLAKE2b-256 | 876fc0f0cf76bc8a9e356fbdb805adf4866ffef003b8215267c6618307219749 |