Skip to main content

MiFlora and LYWSD02 passive scanner

Project description

xiaomipassive

LYWSD02 and MiFlora passive scanner

Installation

git clone https://github.com/afer92/xiaomipassive.git
cd xiaomipassive
pip3 install .

class XiaomiPassiveScanner

loop = asyncio.get_event_loop()
scanner = XiaomiPassiveScanner(loop, callback, timeout_seconds=240)

callback

Function call at each received advertissement

def callback(self, data):
    print(self.dump_result(data))

Output:

mac: C4:7C:8D:65:xx:yy conductivity: 376 µS/cm
mac: 80:EA:CA:89:xx:yy light:        283 lux
mac: 15:03:10:12:xx:yy moisture:     47.0 %
mac: C4:7C:8D:65:xx:yy temperature:  20.8 °C
mac: E7:2E:01:71:xx:yy battery:      18 %

Function dump_result format the data decoded in an advertisement

Dictionnary data:

{'ok': True,
 'mac': 'C4:7C:8D:6C:xx:yy',
 'sensor': 4100,
 'stype': 'temperature',
 'svalue': ListContainer([123, 0]),
 'typeCst': ListContainer([113, 32, 152, 0]),
 'num': 247,
 'tab': 13,
 'name': 'Flower care',
 'rssi': -87,
 'value': 12.3
 }

timeout_seconds

Scan for timeout_seconds, default=240s

devices

After timeout_seconds scanning, data collected for each mac address

Function dump_device(mac) format the data for one mac address

E7:2E:01:71:xx:yy LYWSD02
=================
rssi:          -89 dBm
battery:      18 %
temperature:  20.9 °C
moisture:     49.0 %


C4:7C:8D:6C:xx:yy Flower care
=================
rssi:          -87 dBm
temperature:  12.4 °C
moisture:     28 %
light:        151 lux
conductivity: 432 µS/cm

Example

#!/usr/bin/python3

from xiaomipassive import xiaomipassive as xiaomi
import asyncio

def main():

    def callback(self, result):
        print(self.dump_result(result))

    def get_data():
        loop = asyncio.get_event_loop()
        scanner = xiaomi.XiaomiPassiveScanner
        miflora_scanner = scanner(loop, callback, timeout_seconds=240)
        try:
            loop.run_until_complete(miflora_scanner.run())
        except KeyboardInterrupt as err:
            print(err)

        for mac, device in miflora_scanner.devices.items():
            print(miflora_scanner.dump_device(mac))

    get_data()


if __name__ == '__main__':
    exit(main())

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

xiaomipassive-2023.2.1.dev0.tar.gz (5.7 kB view details)

Uploaded Source

Built Distribution

xiaomipassive-2023.2.1.dev0-py3-none-any.whl (6.4 kB view details)

Uploaded Python 3

File details

Details for the file xiaomipassive-2023.2.1.dev0.tar.gz.

File metadata

  • Download URL: xiaomipassive-2023.2.1.dev0.tar.gz
  • Upload date:
  • Size: 5.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.2

File hashes

Hashes for xiaomipassive-2023.2.1.dev0.tar.gz
Algorithm Hash digest
SHA256 06d73ab09bf996d619b2f05103fc596ab7a06cbb23dfef095ad548cd34f57014
MD5 a18b5481dcfb352c1712d8b8230c601c
BLAKE2b-256 39d8cfcc85804e22afe9cb53d10e421999fd16a2dbcc6cdb4adfefc80c62c0a8

See more details on using hashes here.

File details

Details for the file xiaomipassive-2023.2.1.dev0-py3-none-any.whl.

File metadata

File hashes

Hashes for xiaomipassive-2023.2.1.dev0-py3-none-any.whl
Algorithm Hash digest
SHA256 15414c7a6059aa8bf5abbfe6dc45530823678762fe2f398ae21f871c19d6111d
MD5 aa89d66884a80122bce9706ced7057c0
BLAKE2b-256 faf1c19944d661c97321af09771b4b410e18400a07407d61212c8c9dd8f0e763

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page