Skip to content

Commit 40553f1

Browse files
authored
mqtt-all.py example: use retained publications
Per [the change I suggested to the Pico-based Enviro code](pimoroni/enviro#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](mhawkshaw/homebridge-enviroplus#2 (comment)) 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.
1 parent f1b2820 commit 40553f1

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

examples/mqtt-all.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ def main():
262262
values.update(pms_values)
263263
values["serial"] = device_serial_number
264264
print(values)
265-
mqtt_client.publish(args.topic, json.dumps(values))
265+
mqtt_client.publish(args.topic, json.dumps(values), retain=True)
266266
display_status(disp, args.broker)
267267
time.sleep(args.interval)
268268
except Exception as e:

0 commit comments

Comments
 (0)