我尝试连接到 Google 云 IOT MQTT Brocker。我在 Java 客户端中收到未授权连接 (5) 异常。
device_id和其他详细信息正确。云物联网中设备的公钥设置。
使用以下存储库的示例代码。 https://github.com/GoogleCloudPlatform/java-docs-samples/tree/master/iot/api-client/mqtt_example
最佳答案
另一点需要注意的是配置的 GCP IoT Core 云区域。
也有类似的问题。我将 GCP IoT Core 云区域配置为“asia-east1”,而在客户端应用程序端,其默认云区域为“us-central1”。
如果云区域配置不正确,python/NodeJS IoT Core 示例(mqtt、http、end2end)将返回如下错误
Creating JWT using RS256 from private key file rsa_private.pem
Publishing message 1/100: 'test/test_1-payload-1'
('on_connect', 'Connection Refused: not authorised.')
('on_disconnect', '5: The connection was refused.')
要解决此问题,只需将正确的云区域参数传递给命令--cloud_region=asia-east1
示例:
python cloudiot_mqtt_example.py --project_id=project_id --registry_id=registry_id --device_id=device_id --private_key_file=rsa_private.pem --algorithm=RS256 --cloud_region=asia-east1
关于java - 未授权连接(五)——MQTT google cloud IOT,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46708675/