Can't get C++ client to connect #766
-
I've been tasked with evaluating IoT Core to see if it will work for our needs. I downloaded and tried the 'pubsub' Python client sample which is able to connect and transmit to the server. Next I downloaded the C++ client and compiled with 'basic_pubsub' sample. I ran the executable with the same parameters as the Python code (endpoint, certificate, key, topic, etc.), but the client will not connect and transmit. The error code is "AWS_ERROR_MQTT_UNEXPECTED_HANGUP" Trying to debug the code, I think it is connecting but then the server immediately disconnects. The exact output is... Connecting... What am I doing wrong, why won't the C++ pubsub sample work like the Python pubsub sample? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Please take a look at our FAQ, and let me know if you still have any questions: I keep getting AWS_ERROR_MQTT_UNEXPECTED_HANGUPThis could be many different things but it most likely is a policy issue. Start with using a super permissive IAM policy called AWSIOTFullAccess which looks like this: {
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"iot:*"
],
"Resource": "*"
}
]
} After getting it working make sure to only allow the actions and resources that you need. More info about IoT IAM policies can be found here. |
Beta Was this translation helpful? Give feedback.
I figured it out once I enabled logging on the server. The Python sample uses the client Id of "basicPubSub" whereas the C++ sample uses "test-" followed by a GUID. Checking the policy on the server I see...
If I either add a fourth connection string, or use the command line of the C++ app to override the default clientId then the C++ client is able to connect.
You should consider changing the default clientId in the C++ code to something that works out of the box, or add anot…