File tree Expand file tree Collapse file tree 1 file changed +10
-5
lines changed Expand file tree Collapse file tree 1 file changed +10
-5
lines changed Original file line number Diff line number Diff line change @@ -252,6 +252,9 @@ def main():
252252 print ("Wi-Fi: {}\n " .format ("connected" if check_wifi () else "disconnected" ))
253253 print ("MQTT broker IP: {}" .format (args .broker ))
254254
255+ # Set an initial update time
256+ update_time = time .time ()
257+
255258 # Main loop to read data, display, and send over mqtt
256259 mqtt_client .loop_start ()
257260 while True :
@@ -260,11 +263,13 @@ def main():
260263 if HAS_PMS :
261264 pms_values = read_pms5003 (pms5003 )
262265 values .update (pms_values )
263- values ["serial" ] = device_serial_number
264- print (values )
265- mqtt_client .publish (args .topic , json .dumps (values ), retain = True )
266- display_status (disp , args .broker )
267- time .sleep (args .interval )
266+ time_since_update = time .time () - update_time
267+ if time_since_update >= args .interval :
268+ update_time = time .time ()
269+ values ["serial" ] = device_serial_number
270+ print (values )
271+ mqtt_client .publish (args .topic , json .dumps (values ), retain = True )
272+ display_status (disp , args .broker )
268273 except Exception as e :
269274 print (e )
270275
You can’t perform that action at this time.
0 commit comments