pimoroni / enviro

MIT License
105 stars 85 forks source link

MQTT broken in latest versions of the firmware #49

Closed peter-mount closed 2 years ago

peter-mount commented 2 years ago

Having updated the firmware to a latest release (yes I know it's not final yet) on my Enviro Urban board I found that it stopped sending to my MQTT broker.

After some digging I found in enviro/destinations/mqtt.py you have

    mqtt_client.publish(f"enviro/{nickname}", reading, retain=True)

This fails as reading is not a json object.

By changing it to the following

    mqtt_client.publish(f"enviro/{nickname}", ujson.dumps(reading), retain=True)

and adding import ujson to the top of the script fixes it so that the reading is sent correctly to the broker.

Side note for anyone else trying to debug MQTT: Because you have the try block written with:

  except:
    pass

hid the error so the log just said it failed. Changing it to:

  except Exception as e:
      print(e)

at least allowed the error to be visible and enabled me to find this.

lowfatcode commented 2 years ago

Hey @peter-mount thanks for the pointer! Fixed in https://github.com/pimoroni/enviro/commit/871d94b0fb3174770adc2c1beea41396b3242f86