@@ -107,22 +107,21 @@ def message(client, topic, msg):
107107def handle_pump (command ):
108108 """Handles command about the planter's
109109 watering pump from Google Core IoT.
110- Expected command format: {"pump": 1, "pump_time":3}
111110 :param json command: Message from device/commands#
112111 """
112+ # Parse the pump command message
113+ # Expected format: {"pump": 1, "pump_time":3}
113114 pump_time = command ['pump_time' ]
114115 pump_status = command ['pump' ]
115116 if pump_status == 1 :
116117 print ("Turning pump on for {} seconds..." .format (pump_time ))
117118 start_pump = time .monotonic ()
118119 while True :
119- now = time .monotonic ()
120- if now - start_pump > pump_time :
120+ cur_time = time .monotonic ()
121+ if cur_time - start_pump > pump_time :
121122 # Timer expired, leave the loop
122123 print ("Plant watered!" )
123124 break
124- else :
125- initial = now
126125 print ("Turning pump off" )
127126 water_pump .value = False
128127
@@ -168,9 +167,10 @@ def handle_pump(command):
168167 moisture_level = ss .moisture_read ()
169168 # read temperature
170169 temperature = ss .get_temp ()
171- # display soil sensor values on pyportal
172- gfx .show_water_level (moisture_level )
170+ # Display Soil Sensor values on pyportal
173171 temperature = gfx .show_temp (temperature )
172+ gfx .show_water_level (moisture_level )
173+ # TODO: Add water status?
174174 print ('Sending data to GCP IoT Core' )
175175 gfx .show_gcp_status ('Sending data...' )
176176 gfx .show_gcp_status ('Data sent!' )
0 commit comments