How to use Python to read logged data from the Tag,

Is that even possible ?

Hello,

It is possible but takes a lot of development effort.

You’ll need to implement logic for scanning and connecting to your Tags and then request for data as described in Bluetooth connection - docs

1 Like

I have not played around much with the Ruuvi GW, but is that something its capable to do ?

Ruuvi Gateway cannot run Python, and at least right now we don’t have reading logged history in our roadmap

This is a very interesting question. I just started using bleak · PyPI
and it seems, making a connection is not too complicated. What maybe complicated, what to do with the connection.

I think in my project RuuviTag Sensor Python Package I have to start strugling with this, because I want to control a thermostat, which has bluetooth connection.

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Wed Jun  8 14:10:18 2022

@author: heikki
"""

import asyncio
from bleak import BleakScanner, BleakClient


async def main():
    devices = await BleakScanner.discover()
    for d in devices:
        props = d.details['props']
        if 'Name' in props.keys():
            if props['Name'] == 'Ruuvi B599':
                print('\nprops:\n', props)
                sensor_data = props['ManufacturerData'][1177]
                print('\nsensor data:\n', sensor_data)

                address = str(props['Address'])
                async with BleakClient(address) as client:
                    services = await client.get_services()
                    print("\nServices:")
                    for service in services:
                        print(service)
                    print('\ncharacteristics:\n')
                    for handle in services.characteristics:
                        print(handle, services.get_characteristic(handle))


asyncio.run(main())

 python3 bleak_connect.py 

props:
 {'Address': 'C6:EB:E5:62:B5:99', 'AddressType': 'random', 'Name': 'Ruuvi B599', 'Alias': 'Ruuvi B599', 'Paired': False, 'Trusted': False, 'Blocked': False, 'LegacyPairing': False, 'RSSI': -61, 'Connected': False, 'UUIDs': ['6e400001-b5a3-f393-e0a9-e50e24dcca9e'], 'Adapter': '/org/bluez/hci0', 'ManufacturerData': {1177: b'\x05\x12\x03XF\xc7B\x00`\x00\x04\x04\x08\xa8\xd6\r\x84\x97\xc6\xeb\xe5b\xb5\x99'}, 'ServicesResolved': False}

sensor data:
 b'\x05\x12\x03XF\xc7B\x00`\x00\x04\x04\x08\xa8\xd6\r\x84\x97\xc6\xeb\xe5b\xb5\x99'

Services:
00001801-0000-1000-8000-00805f9b34fb (Handle: 10): Generic Attribute Profile
0000180a-0000-1000-8000-00805f9b34fb (Handle: 14): Device Information
6e400001-b5a3-f393-e0a9-e50e24dcca9e (Handle: 23): Nordic UART Service
11 00002a05-0000-1000-8000-00805f9b34fb (Handle: 11): Service Changed
15 00002a29-0000-1000-8000-00805f9b34fb (Handle: 15): Manufacturer Name String
17 00002a24-0000-1000-8000-00805f9b34fb (Handle: 17): Model Number String
19 00002a27-0000-1000-8000-00805f9b34fb (Handle: 19): Hardware Revision String
21 00002a26-0000-1000-8000-00805f9b34fb (Handle: 21): Firmware Revision String
24 6e400002-b5a3-f393-e0a9-e50e24dcca9e (Handle: 24): Nordic UART RX
26 6e400003-b5a3-f393-e0a9-e50e24dcca9e (Handle: 26): Nordic UART TX
(venv310) heikki@speedy:~/0Pilvi/mokki_pi> python3 bleak_connect.py 

props:
 {'Address': 'C6:EB:E5:62:B5:99', 'AddressType': 'random', 'Name': 'Ruuvi B599', 'Alias': 'Ruuvi B599', 'Paired': False, 'Trusted': False, 'Blocked': False, 'LegacyPairing': False, 'RSSI': -58, 'Connected': False, 'UUIDs': ['6e400001-b5a3-f393-e0a9-e50e24dcca9e'], 'Adapter': '/org/bluez/hci0', 'ManufacturerData': {1177: b'\x05\x12\x01XG\xc7B\x00`\x00\x0c\x04\x00\xa7\x16\r\x84\xb5\xc6\xeb\xe5b\xb5\x99'}, 'ServicesResolved': False}

sensor data:
 b'\x05\x12\x01XG\xc7B\x00`\x00\x0c\x04\x00\xa7\x16\r\x84\xb5\xc6\xeb\xe5b\xb5\x99'

Services:
00001801-0000-1000-8000-00805f9b34fb (Handle: 10): Generic Attribute Profile
0000180a-0000-1000-8000-00805f9b34fb (Handle: 14): Device Information
6e400001-b5a3-f393-e0a9-e50e24dcca9e (Handle: 23): Nordic UART Service

characteristics:

11 00002a05-0000-1000-8000-00805f9b34fb (Handle: 11): Service Changed
15 00002a29-0000-1000-8000-00805f9b34fb (Handle: 15): Manufacturer Name String
17 00002a24-0000-1000-8000-00805f9b34fb (Handle: 17): Model Number String
19 00002a27-0000-1000-8000-00805f9b34fb (Handle: 19): Hardware Revision String
21 00002a26-0000-1000-8000-00805f9b34fb (Handle: 21): Firmware Revision String
24 6e400002-b5a3-f393-e0a9-e50e24dcca9e (Handle: 24): Nordic UART RX
26 6e400003-b5a3-f393-e0a9-e50e24dcca9e (Handle: 26): Nordic UART TX