Є Bluetooth BLE термометр Xiaomi Mijia (LYWSD03MMC) з альтернативною прошивкою PVVX.
Xiaomi Mijia (LYWSD03MMC) |
Написаний простий скрипт (Python) що сканує мережу Bluetooth BLE на наявність broadcasting advertising packets.
Якщо назва пристрою починається з 'ATC' то виводяться декодовані данні телеметрії в консоль.
Код
import asyncio import datetime from bleak import BleakScanner #MiTermometerPVVX" async def main(): print("Scanning BLE devices of type 'ATC_MiThermometer (PVVX)', please wait...") stop_event = asyncio.Event() ATC_COUNTERS={} ATC_DATE={} def callback(_device, advertising_data): name=advertising_data.local_name if name and name[0:3]=="ATC" : advatc=advertising_data.service_data['0000181a-0000-1000-8000-00805f9b34fb'] count=int.from_bytes(advatc[13:14], byteorder='little', signed=False) if ATC_COUNTERS.get(name) != count : ATC_COUNTERS.update({name: count}) datenow=datetime.datetime.now() dateprev=ATC_DATE.get(name) if dateprev: datediff=datenow-dateprev datediff=datetime.timedelta(seconds=round(datediff.total_seconds())) else: datediff=0 ATC_DATE.update({name: datenow}) temp=int.from_bytes(advatc[6:8], byteorder='little', signed=True)/100.0 humidity=int.from_bytes(advatc[8:10], byteorder='little', signed=True)/100.0 batteryv=int.from_bytes(advatc[10:12], byteorder='little', signed=False) battery=int.from_bytes(advatc[12:13], byteorder='little', signed=False) flag=int.from_bytes(advatc[14:15], byteorder='little', signed=False) print() print("device:\t ", name) namelen=len(str(name))+10 print("-" * namelen) print(f"temp:\t {temp}\xB0C") print(f'humidity: {humidity}%') print(f'batteryv: {batteryv} mV') print(f'battery: {battery}%') print(f'count:\t {count}') if datediff: datedifftext=', duration: ' + str(datediff) else: datedifftext="" print(f'time now: {datenow.strftime("%H:%M:%S")}{datedifftext}') try: async with BleakScanner(callback) as scanner: await stop_event.wait() except asyncio.CancelledError as ex: print('**** task scanner cancelled') stop_event.set() if __name__ == '__main__': try: asyncio.run(main()) except Exception as e: print(str(e))
https://github.com/lexxai/Show_temperature_from_BLE_ADV_ATC_MiThermometer
Результат роботи MiTermometerPVVX |
Custom format (all data little-endian):
UUID 0x181A - size 19: Custom extended format in 0.01 units (all data little-endian):
uint8_t MAC[6]; // [0] - lo, .. [6] - hi digits int16_t temperature; // x 0.01 degree uint16_t humidity; // x 0.01 % uint16_t battery_mv; // mV uint8_t battery_level; // 0..100 % uint8_t counter; // measurement count uint8_t flags; // GPIO_TRG pin (marking "reset" on circuit board) flags: // bit0: Reed Switch, input // bit1: GPIO_TRG pin output value (pull Up/Down) // bit2: Output GPIO_TRG pin is controlled according to the set parameters // bit3: Temperature trigger event // bit4: Humidity trigger event
Немає коментарів:
Дописати коментар