Greengrass edge device with mqtt pub/sub connections keep dropping when running separate pub and sub py files.

0

I am using this repo and specifically this file: https://github.com/aws/aws-iot-device-sdk-python-v2/blob/main/samples/basic_discovery.py

Everything works fine, but when i separate the pub and sub into separate py files and run them individually from 2 different terminal sessions, the connections keep dropping on both of them, and it happens constantly. If I switch back to a single file (the example), it works just fine.

I am using this client component in my deployment: aws.greengrass.clientdevices.mqtt.Moquette

Anyone know why? Thanks.

asked 3 months ago118 views
1 Answer
0
Accepted Answer

Hi. Are you using the same client ID in each? You can't make multiple connections with the same client ID. If you do, you'll keep suffering DUPLICATE_CLIENTID disconnections: https://docs.aws.amazon.com/iot/latest/developerguide/life-cycle-events.html#connect-disconnect

profile pictureAWS
EXPERT
Greg_B
answered 3 months ago
profile picture
EXPERT
reviewed 3 months ago
  • I am using the same client ID. When I used separate it didn't work. I'll try again, if it fails I'll post the error and code. Thank you !

  • the deploy i tried using thingname_publisher and thingname_subscriber and it always gets this error any time the client id is not just thingname, so obviously I can use this on both my pub.py and sub.py any time i do this i get:

    trying core arn:aws:iot:us-east-1:account_id:thing/GreengrassCoreDevice1 at host local_ip port 8883 [ERROR] [2024-07-17T17:34:40Z] [0000772ef28fd640] [mqtt-client] - id=0x615c6c9abba0: invalid connect return code 4, disconnecting Connection failed with exception AWS_ERROR_MQTT_PROTOCOL_ERROR: Protocol error occurred. Trying core arn:aws:iot:us-east-1:account_id:thing/GreengrassQuickStartCore-190714f0a37 at host 192.168.50.190 port 8883 [ERROR] [2024-07-17T17:34:40Z] [0000772ef4d501c0] [mqtt-client] - id=0x615c6c9abba0: Connection is not open, and may not be closed [ERROR] [2024-07-17T17:34:41Z] [0000772ef28fd640] [mqtt-client] - id=0x615c6ca652c0: invalid connect return code 4, disconnecting Connection failed with exception AWS_ERROR_MQTT_PROTOCOL_ERROR: Protocol error occurred. Trying core arn:aws:iot:us-east-1:account_id:thing/GreengrassQuickStartCore-190bdcfbf05 at host local_ip port 8883 [ERROR] [2024-07-17T17:34:41Z] [0000772ef4d501c0] [mqtt-client] - id=0x615c6ca652c0: Connection is not open, and may not be closed [ERROR] [2024-07-17T17:34:42Z] [0000772ef20fc640] [mqtt-client] - id=0x615c6ca4e980: invalid connect return code 4, disconnecting Connection failed with exception AWS_ERROR_MQTT_PROTOCOL_ERROR: Protocol error occurred.

  • The client names you use have to match the things you associated with the device: https://docs.aws.amazon.com/greengrass/v2/developerguide/client-devices-tutorial.html#enable-client-device-support

  • It seems I have been going about this all wrong. I setup GG on a docker container, and then outside of the docker had a python script to subscribe and publish. I seems I need more than one thing (for the gg), if I use the same py file for pub sub then one more will do, otherwise separate files means 2 extra things. I think this is correct, will update later. I was also using the crt and pem file from the main thing that gets created when gg install, in my pub/sub so that's probably a probably also, they need their own thing/keys. Thanks.

  • one of many of things I was doing wrong.

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions