@@ -68,32 +68,24 @@ def connect(client, userdata, flags, rc):
6868 print ('Flags: {0}\n RC: {1}' .format (flags , rc ))
6969 # Subscribes to commands/# topic
7070 google_mqtt .subscribe_to_all_commands ()
71- return
72-
7371
7472def disconnect (client , userdata , rc ):
7573 # This method is called when the client disconnects
7674 # from the broker.
7775 print ('Disconnected from Google Cloud IoT!' )
78- return
79-
8076
8177def subscribe (client , userdata , topic , granted_qos ):
8278 # This method is called when the client subscribes to a new topic.
8379 print ('Subscribed to {0} with QOS level {1}' .format (topic , granted_qos ))
84- return
85-
8680
8781def unsubscribe (client , userdata , topic , pid ):
8882 # This method is called when the client unsubscribes from a topic.
8983 print ('Unsubscribed from {0} with PID {1}' .format (topic , pid ))
9084
91-
9285def publish (client , userdata , topic , pid ):
9386 # This method is called when the client publishes data to a topic.
9487 print ('Published to {0} with PID {1}' .format (topic , pid ))
9588
96-
9789def message (client , topic , msg ):
9890 # This method is called when the client receives data from a topic.
9991 # Check if command is about the water pump
@@ -103,12 +95,12 @@ def message(client, topic, msg):
10395 except :
10496 print ("Message from {}: {}" .format (topic , msg ))
10597
106-
10798def handle_pump (command ):
10899 """Handles command about the planter's
109100 watering pump from Google Core IoT.
110101 :param json command: Message from device/commands#
111102 """
103+ print ("handling pump..." )
112104 # Parse the pump command message
113105 # Expected format: {"power": true, "pump_time":3}
114106 pump_time = command ['pump_time' ]
@@ -174,6 +166,8 @@ def handle_pump(command):
174166 # TODO: Add water status?
175167 print ('Sending data to GCP IoT Core' )
176168 gfx .show_gcp_status ('Sending data...' )
169+ google_mqtt .publish (temperature ,'events' , qos = 1 )
170+ google_mqtt .publish (moisture_level ,'events' , qos = 1 )
177171 gfx .show_gcp_status ('Data sent!' )
178172 print ('Data sent!' )
179173 # Reset timer
0 commit comments