Scanning near RuuviTag beacons with python on Raspberry Pi3


#1

Hi;
I am trying to implement program with python on Raspberry Pi 3. Purpose is to scan near RuuviTag beacons automatically without hardcoding MAC addresses in code. I have studied https://github.com/ttu/ruuvitag-sensor and have been able to get data from beacon when MAC address is hardcoded.

Currently I’m wondering what would be best way to scan near beacons automatically and use their addresses. I have noticed that with command ruuvitag -l I can get MAC address and data of beacon. It seems I can’t use commands like ruuvitag -l | awk … or grep to get lines with json and mac address. Any ideas how to proceed with this? My purpose is to create app that automatically saves data from nearest beacons to text file.


#2
import ruuvitag_sensor
from ruuvitag_sensor.log import log
from ruuvitag_sensor.ruuvi import RuuviTagSensor
from ruuvitag_sensor.ruuvitag import RuuviTag

ruuvitag_sensor.log.enable_console()

datas = RuuviTagSensor.get_data_for_sensors(bt_device='')
log.info(datas)

for key, value in datas.items():
    # Beacon mac address
    sensor = RuuviTag(key)

   ....

key is the mac address


#3

You may also try aioblescan

https://github.com/frawau/aioblescan

You can install it from pip, but it requires python >=3.5 (The github version requires >=3.4)