GoogleCloudPlatform / python-docs-samples

Code samples used on cloud.google.com
Apache License 2.0
7.34k stars 6.39k forks source link

unable to connect to devices in the End-to-end example #4135

Closed Kyle0936 closed 4 years ago

Kyle0936 commented 4 years ago

In which file did you encounter the issue?

python-docs-samples/iot/api-client/end_to_end_example/cloudiot_pubsub_example_mqtt_device.py

Did you change the file? If so, how?

No

Describe the issue

I used exactly the same command as provided in the tutorial to try to set up a device. However, I got this error:

Creating JWT using RS256 from private key file rsa_private.pem
Disconnected: 1: Out of memory.
Disconnected: 1: Out of memory.
Disconnected: 1: Out of memory.
Traceback (most recent call last):
  File "cloudiot_pubsub_example_mqtt_device.py", line 259, in <module>
    main()
  File "cloudiot_pubsub_example_mqtt_device.py", line 234, in main
    device.wait_for_connection(5)
  File "cloudiot_pubsub_example_mqtt_device.py", line 100, in wait_for_connection
    raise RuntimeError('Could not connect to MQTT bridge.')
RuntimeError: Could not connect to MQTT bridge.

I've googled it and there's not much info. I tried creating new service key and adding --mqtt_bridge_port=443 and --cloud_region=us-central1. I also tried changing regions as suggested in the troubleshooting section. None of them works.

I'm not sure if I should create a new device using GCP's GUI or using the iot/api-client/manager/manager.py script to create a new device. I used the GUI to get the error described above. I wasn't able to create one with manager.py due to another issue I just proposed.

gguuss commented 4 years ago

The "Out of memory" error generally occurs when you have a misconfigured device. Please ensure that you have correctly registered your device and added authentication for it. Sometimes a stale public/private key can be mixed in with your correct keys and prevent auth from succeeding.

Kyle0936 commented 4 years ago

Gotcha. Sorry that I got lost in the documentation and missed the step to generate key pairs.

Actually, I found it a little bit difficult to follow the tutorial w/o familiarities with IoT Core. I am guessing it might be nice to provide the command-line version of creating new devices directly instead of the link to codes in device management samples at the Creating the devices section. Probably something like:

  1. Go to the manager folder iot/api-client/manager
  2. Create a public/private key pair
  3. Run the script to create the device. Take creating a device with RSA credentials for example: python manager.py --project_id=_projectID_ --cloud_region=_cloud_region_ --service_account_json=_service_account.json_ --rsa_certificate_file=./rsa_cert.pem --device_id=_deviceID_ --registry_id=_registryID_ create-rsa256

I know it might be redundant but I think it might be more friendly to beginners to IoT Core like me.

gguuss commented 4 years ago

Thank you @KKKKKyle for the feedback, adding issue internally with this feedback