Skip to content

Commit

Permalink
Merge pull request #121 from jspauley/fix_pms_buffer
Browse files Browse the repository at this point in the history
Adjust Script To Prevent PMS Sensor Buffering
  • Loading branch information
Gadgetoid authored Jul 26, 2023
2 parents 9fa03de + 39d365f commit 37252b6
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions examples/mqtt-all.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,9 @@ def main():
print("Wi-Fi: {}\n".format("connected" if check_wifi() else "disconnected"))
print("MQTT broker IP: {}".format(args.broker))

# Set an initial update time
update_time = time.time()

# Main loop to read data, display, and send over mqtt
mqtt_client.loop_start()
while True:
Expand All @@ -260,11 +263,13 @@ def main():
if HAS_PMS:
pms_values = read_pms5003(pms5003)
values.update(pms_values)
values["serial"] = device_serial_number
print(values)
mqtt_client.publish(args.topic, json.dumps(values), retain=True)
display_status(disp, args.broker)
time.sleep(args.interval)
time_since_update = time.time() - update_time
if time_since_update >= args.interval:
update_time = time.time()
values["serial"] = device_serial_number
print(values)
mqtt_client.publish(args.topic, json.dumps(values), retain=True)
display_status(disp, args.broker)
except Exception as e:
print(e)

Expand Down

0 comments on commit 37252b6

Please sign in to comment.