Ernst79 / bleparser

Parser for passive BLE advertisements
MIT License
29 stars 15 forks source link

Petoneer Smart Odor Eliminator Pro SU001-T - none sensor data #41

Open sienikam opened 1 year ago

sienikam commented 1 year ago

Hello,

I'm trying to use bleparser to read sensor data from SU001-T device but it looks like I'm only getting tracker basic data and sensor data with motion etc is empty for whatever reason..

here is code which I'm using:

import aioblescan as aiobs
from bleparser import BleParser

SENSORS = [
    "DC:23:4D:2D:69:A7"
    ]
TRACKERS = [
    "DC:23:4D:2D:69:A7"
    ]
## Setup parser
parser = BleParser(
    discovery=False,
    filter_duplicates=True,
    sensor_whitelist=[bytes.fromhex(mac.replace(":", "").lower()) for mac in SENSORS],
    tracker_whitelist=[bytes.fromhex(mac.replace(":", "").lower()) for mac in TRACKERS]
)

## Define callback
def process_hci_events(data):
    sensor_data, tracker_data = parser.parse_raw_data(data)

    if tracker_data:
        print("Tracker: ", tracker_data)
        print("Sensor: ", sensor_data)

    if sensor_data:
        print("Sensor: ", sensor_data)

## Get everything connected
loop = asyncio.get_event_loop()

#### Setup socket and controller
socket = aiobs.create_bt_socket(0)
fac = getattr(loop, "_create_connection_transport")(socket, aiobs.BLEScanRequester, None, None)
conn, btctrl = loop.run_until_complete(fac)

#### Attach callback
btctrl.process = process_hci_events
loop.run_until_complete(btctrl.send_scan_request(0))

## Run forever
loop.run_forever()

Output is always:

root@raspberrypi:/home/pi# python3.8 petoneer.py
Tracker:  {'is connected': True, 'mac': 'DC234D2D69A7', 'rssi': -80}
Sensor:  None

any idea what might be wrong with my code?

Ernst79 commented 1 year ago

I can think of two reasons

  1. Did you add it to MiHome. This is often needed before Xiaomi MiBeacon sensors start to broadcast data
  2. Did you provide the encryption key somewhere in your code? This device is encrypted, so you will need to set an encryption key to decode the data.
sienikam commented 1 year ago

I can think of two reasons

1. Did you add it to MiHome. This is often needed before Xiaomi MiBeacon sensors start to broadcast data

2. Did you provide the encryption key somewhere in your code? This device is encrypted, so you will need to set an encryption key to decode the data.
  1. It's not using MiHome app - it's using Petoneer app - https://play.google.com/store/apps/details?id=com.petoneer.pet&hl=en&gl=US

  2. No I didn't provide encryption key because I have no idea how to get that encryption key - any idea how to get encryption key for that specific device ?

Ernst79 commented 1 year ago

I can't find back who has requested support for this device, both here and in BLE monitor (can't find any issue when searching for Petoneer or SU001-T). But it is added in the Xiaomi parser, so I would expect that it can be added to MiHome, and that you can get the encryption key with one of the methods as described in the BLE monitor documentation.

https://custom-components.github.io/ble_monitor/faq#how-to-get-the-mibeacon-v4v5-encryption-key

I'm not sure how the app is working, sometimes a sensor supports different formats. Like Qingping sensors, which switch to Xiaomi format after adding it to MiHome, and will switch back to Qingping format after resetting it. Could be that the Petoneer has a similar mechanism

sienikam commented 1 year ago

I can't find back who has requested support for this device, both here and in BLE monitor (can't find any issue when searching for Petoneer or SU001-T). But it is added in the Xiaomi parser, so I would expect that it can be added to MiHome, and that you can get the encryption key with one of the methods as described in the BLE monitor documentation.

https://custom-components.github.io/ble_monitor/faq#how-to-get-the-mibeacon-v4v5-encryption-key

I'm not sure how the app is working, sometimes a sensor supports different formats. Like Qingping sensors, which switch to Xiaomi format after adding it to MiHome, and will switch back to Qingping format after resetting it. Could be that the Petoneer has a similar mechanism

made a quick research and it looks like it's using Tuya Cloud not Xiaomi.. I was able to get something called "local_key" directly from Tuya Cloud but I think this is not aeskeys that I need.. any example how that aeskeys should look like ?

response from Tuya Cloud API:

{
  "result": {
    "active_time": 1666623069,
    "category": "cwjwq",
    "category_name": "Pet Odor Remover",
    "create_time": 1666623069,
    "gateway_id": "",
    "icon": "smart/icon/ay1541381385946hoIoV/82d2454ec801d80f2550fc1d752a7338.png",
    "id": "bf9e3bjoa0mg<HIDDEN>",
    "ip": "",
    "lat": "53.4516",
    "local_key": "01eea53a36db<HIDDEN>",
    "lon": "14.5387",
    "model": "",
    "name": "Smart Odor Eliminator-Pro",
    "online": false,
    "owner_id": "25787440",
    "product_id": "d8anh8og",
    "product_name": "Smart Odor Eliminator-Pro",
    "sub": false,
    "time_zone": "+02:00",
    "update_time": 1666623070,
    "uuid": "d35d684a431833ed"
  },
  "success": true,
  "t": 1666623959696,
  "tid": "5e6539ee53ad11ed9fc122dacb9008b9"
}
Ernst79 commented 1 year ago

It should be 16 bytes long (32 characters)