DPHacks / picow-air

Pico W Air Quality Monitoring w/ PM 2.5 Sensor
MIT License
36 stars 6 forks source link

Exception when trying to decode data #6

Open webdeck opened 1 month ago

webdeck commented 1 month ago

I have a python script that is subscribing to the MQTT topic that the picow-air is publishing to, and occasionally (a couple of times an hour), it fails to decode the payload. I am using the paho mqtt library.

Here is the code I am using:

def onMessage(client, userdata, msg):
  try:
    s = str(msg.payload.decode())
    // [omitted - do stuff with s]
  except Exception as e:
    print(f"Exception decoding payload: {msg.payload}")
    print(e)

Here is the error:

Sep 30 14:57:28 Exception decoding payload: b'0\x8d\x03\x00\x16picowair/masterbedroom0\x8d\x03\x00\x16picowair/masterbedroom{"pm10 standard": 1.5, "temperature": 74.38, "aqi": 11, "pm25 standard": 2.7, "particles 03um": 423.6, "particles 100um": 0.0, "particles 50um": 0.0, "color": "Green", "humidity": 55.11, "pm100 standard": 2.7, "particles 05um": 119.2, "particles 10um": 21.3, "particles 25um": 1.5, "category": "Good", "rgb": [0, 228, 0'
Sep 30 14:57:28 'utf-8' codec can't decode byte 0x8d in position 1: invalid start byte

The invalid start byte is different each time.