From 40553f165647d7bd73594ef92544de528e09a5eb Mon Sep 17 00:00:00 2001 From: Andy Piper Date: Thu, 18 Aug 2022 11:32:21 +0100 Subject: [PATCH] mqtt-all.py example: use retained publications Per [the change I suggested to the Pico-based Enviro code](https://github.com/pimoroni/enviro/pull/2), with this change, the MQTT messages will be published with the retain flag set, so that if a consumer is not subscribed, the most recent set of readings can still be read by a future subscriber later. This supports the [homebridge-enviroplus plugin](https://github.com/mhawkshaw/homebridge-enviroplus/issues/2#issuecomment-1215872947) better, so that a publication is more likely to exist on the topic even if the Pi with Enviroplus / this example code is not running at the time. Additional update to consider would be to align the message data formats between this sample and the newer Enviro product line. --- examples/mqtt-all.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/mqtt-all.py b/examples/mqtt-all.py index 8220c67..2338f0f 100755 --- a/examples/mqtt-all.py +++ b/examples/mqtt-all.py @@ -262,7 +262,7 @@ def main(): values.update(pms_values) values["serial"] = device_serial_number print(values) - mqtt_client.publish(args.topic, json.dumps(values)) + mqtt_client.publish(args.topic, json.dumps(values), retain=True) display_status(disp, args.broker) time.sleep(args.interval) except Exception as e: