@@ -87,6 +87,13 @@ def on_publish(unused_client, unused_userdata, unused_mid):
87
87
print ('on_publish' )
88
88
89
89
90
+ def on_message (unused_client , unused_userdata , message ):
91
+ """Callback when the device receives a message on a subscription."""
92
+ payload = str (message .payload )
93
+ print ('Received message \' {}\' on topic \' {}\' with Qos {}' .format (
94
+ payload , message .topic , str (message .qos )))
95
+
96
+
90
97
def get_client (
91
98
project_id , cloud_region , registry_id , device_id , private_key_file ,
92
99
algorithm , ca_certs , mqtt_bridge_hostname , mqtt_bridge_port ):
@@ -116,10 +123,17 @@ def get_client(
116
123
client .on_connect = on_connect
117
124
client .on_publish = on_publish
118
125
client .on_disconnect = on_disconnect
126
+ client .on_message = on_message
119
127
120
128
# Connect to the Google MQTT bridge.
121
129
client .connect (mqtt_bridge_hostname , mqtt_bridge_port )
122
130
131
+ # This is the topic that the device will receive configuration updates on.
132
+ mqtt_config_topic = '/devices/{}/config' .format (device_id )
133
+
134
+ # Subscribe to the config topic.
135
+ client .subscribe (mqtt_config_topic , qos = 1 )
136
+
123
137
# Start the network loop.
124
138
client .loop_start ()
125
139
0 commit comments