Anrijs / Aranet4-Python

Aranet4, Aranet2 and Aranet Radiation Python client
MIT License
219 stars 19 forks source link

Decode manufacturer-specific data in advertisements #25

Closed elyscape closed 2 years ago

elyscape commented 2 years ago

I see that you added some code to process the advertisement data. It would be nice if it also decoded the manufacturer-specific data present in ad_data.manufacturer_data[1794]. It is structured as follows:

┌ A┐B┐ C┐D───┐E┐ F┐
│ 210a 0400 000c 0f
└ │ │  │ │    │  │
  21│──│─│────│──│─── device state
                      └ 0010 0001
                        ││││ │ │└ device is disconnected
                        ││││ │ └  unknown
                        ││││ └    calibration state:
                        ││││          00: not active
                        ││││          01: "end request"
                        ││││          10: in progress
                        ││││          11: error
                        │││└      DFU mode active
                        ││└       "Smart Home Integration" (i.e. 0x0038 handle) is enabled
                        │└        unknown
                        └         unknown
    0a─│─│────│──│─── patch version number
       04│────│──│─── minor version number
          0000│──│─── major version number (uLE16)
              0c─│─── hardware revision
                 0f── unknown

If DFU mode is not active, the version numbers correspond to the firmware version. If DFU mode is active, the version numbers correspond to the bootloader version.

As an aside, the Bleak documentation notes that register_detection_callback is deprecated. As such, this code should be updated: https://github.com/Anrijs/Aranet4-Python/blob/613bc120add2bc1179d57567b93cfcb9cfd8205e/aranet4/client.py#L496-L497 To something like this:

self.scanner = BleakScanner(self._process_advertisement)

As a fun side bonus, you could use the service_uuids parameter to let Bleak do the device filtering for you:

self.scanner = BleakScanner(self._process_advertisement, [Aranet4.AR4_SERVICE, Aranet4.AR4_OLD_SERVICE]))
Anrijs commented 2 years ago

Thanks for the tip. I will try to update scanner code at some point.

Anrijs commented 2 years ago

Updated library to v2.1.0 with manufacturer data decoding. This also includes support for measurement decoding from v1.2.0 beacons.