Quotidien Shaarli

Tous les liens d'un jour sur une page.

February 21, 2024

https://github.com/pvvx/ATC_MiThermometer/tree/master/python-interface#python-interfacing-methods-and-data-representation-model
thumbnail

import asyncio
from bleak import BleakScanner
from functools import partial
from atc_mi_interface import general_format, atc_mi_advertising_format

bindkey = {
}

async def ble_coro():
count = [0]
stop_event = asyncio.Event()

def detection_callback(count, device, advertisement_data):
    format_label, adv_data = atc_mi_advertising_format(advertisement_data)
    if not adv_data:
        return
    mac_address = bytes.fromhex(device.address.replace(":", ""))
    atc_mi_data = general_format.parse(
        adv_data,
        mac_address=mac_address,
        bindkey=(
            bindkey[device.address] if device.address in bindkey else None
        )
    )
    # print(f"{count[0]}. {format_label} advertisement: {atc_mi_data}. "
        # f"RSSI: {advertisement_data.rssi}")
    if atc_mi_data.search_all("^MAC")[0] == 'A4:C1:38:79:A9:41':
        print(atc_mi_data.search_all("^temperature")[0])
        print("battery_level:", atc_mi_data.search_all("^battery_level"))
    # count[0] += 1
    # if count[0] == 5:
        # stop_event.set()

async with BleakScanner(
    detection_callback=partial(detection_callback, count)
) as scanner:
    await stop_event.wait()
print("Stopped")

asyncio.run(ble_coro())