From c262f7dff074f3e96b3e30b95e43297bbb6eca36 Mon Sep 17 00:00:00 2001 From: Lars Wander Date: Fri, 8 Feb 2019 13:30:36 -0500 Subject: [PATCH 1/2] Print client_id when creating MQTT client I wound up spending a lot of time trying to figure out why every call to `client.loop()` was disconnecting with ERR_NOMEM. The cause was an error in my `--project_id` flag, which would have been made clear had the client_id been logged. --- iot/api-client/mqtt_example/cloudiot_mqtt_example.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/iot/api-client/mqtt_example/cloudiot_mqtt_example.py b/iot/api-client/mqtt_example/cloudiot_mqtt_example.py index ed273d7f780..7d973ddd015 100644 --- a/iot/api-client/mqtt_example/cloudiot_mqtt_example.py +++ b/iot/api-client/mqtt_example/cloudiot_mqtt_example.py @@ -126,13 +126,11 @@ def get_client( algorithm, ca_certs, mqtt_bridge_hostname, mqtt_bridge_port): """Create our MQTT client. The client_id is a unique string that identifies this device. For Google Cloud IoT Core, it must be in the format below.""" - client = mqtt.Client( - client_id=('projects/{}/locations/{}/registries/{}/devices/{}' - .format( - project_id, - cloud_region, - registry_id, - device_id))) + client_id = 'projects/{}/locations/{}/registries/{}/devices/{}'.format( + project_id, cloud_region, registry_id, device_id) + print('Device client_id is \'{}\''.format(client_id)) + + client = mqtt.Client(client_id=client_id) # With Google Cloud IoT Core, the username field is ignored, and the # password field is used to transmit a JWT to authorize the device. From 25bdd87e71fa9728bbba1ff90ffdf76db4fa8946 Mon Sep 17 00:00:00 2001 From: Lars Wander Date: Fri, 8 Feb 2019 13:39:02 -0500 Subject: [PATCH 2/2] Clear whitespace on empty line --- iot/api-client/mqtt_example/cloudiot_mqtt_example.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iot/api-client/mqtt_example/cloudiot_mqtt_example.py b/iot/api-client/mqtt_example/cloudiot_mqtt_example.py index 7d973ddd015..40b00210c59 100644 --- a/iot/api-client/mqtt_example/cloudiot_mqtt_example.py +++ b/iot/api-client/mqtt_example/cloudiot_mqtt_example.py @@ -129,7 +129,7 @@ def get_client( client_id = 'projects/{}/locations/{}/registries/{}/devices/{}'.format( project_id, cloud_region, registry_id, device_id) print('Device client_id is \'{}\''.format(client_id)) - + client = mqtt.Client(client_id=client_id) # With Google Cloud IoT Core, the username field is ignored, and the