- Newest
- Most votes
- Most comments
Hi,
Thanks for reaching out. Can you kindly send a link of the documentation that you are following to connect to AWS IoT using M2Mqtt? I've tried checking it in github but I cannot seem to find a similar constructor as the one in the above code. Though please note that I am not familiar with M2Mqtt.
Based on the below code, the private key file seems to be missing when trying to connect to AWS IoT
var client = new MqttClient(awsEndpoint.Text, brokerPort, true, caCert, clientCert, MqttSslProtocols.TLSv1_2);
In terms of certificates, you would need normally need to specify the following:
- The
cafile
which is the path to the trusted CA certificate. This is AmazonRootCA1.pem - The
cert
file which is client certificate. This is[bunch of number removed]-certificate.pem.crt
when creating the device via the AWS IoT console - The
key
file which is the client private key. This is[bunch of number removed]-private.pem.key
when creating the device via the AWS IoT console
Here is an example when using mosquitto_pub:
$ mosquitto_pub -t 'topic_1' -m "Hello from Mosquitto" --id "basicPubSub" --cert [bunch of number removed]-certificate.pem.crt --key [bunch of number removed]-private.pem.key --cafile AmazonRootCA1.pem -h [ATS_ENDPOINT] -p 8883
You can use the above command with mosquitto_pub to confirm if your certificates can connect to IoT. You can use the IoT console to subscribe to topic_1
and then run the above snippet. Please do note that the policy should allow publishing to topic_1 and the clientid to be "basicPubSub".
Here is another sample publish example(In Python) that can be seen from our documentation -> https://docs.aws.amazon.com/iot/latest/developerguide/sdk-tutorials.html#sdk-tutorials-experiment. Again, we can see the above 3 files are required.
Please review the M2Mqtt documentation and check why it seems there are only 2 files provide in the arguments, specifically caCert
and clientCert
.
Hi,
here is a working sample to connect to AWS IoT using the C# M2MQTT library:
https://github.com/aws-samples/iot-dotnet-publisher-consumer
The main difference compared to your code is that the client credentials (certificate and private key) must be bundled in a PFX file.
Check also that you are NOT using the .NET micro framework since it only supports TLSv1.
Relevant content
- asked 6 years ago
- asked 9 months ago
- asked 5 years ago
- asked 4 months ago
- AWS OFFICIALUpdated 3 years ago
- AWS OFFICIALUpdated 2 years ago
- AWS OFFICIALUpdated 3 years ago
- AWS OFFICIALUpdated 5 months ago
Can you confirm you are using the
XXXXXX-ats.iot.REGION.amazonaws.com
endpoint? Also, is your certificate activated in IoT Core and does it have an IoT policy allowing theiot:Connect
action?Good thoughts.
Yes, I have the correct endpoint and it is being used by my connect command.
The certificate attached to that thing is active.
The policy allows publish and subscribe to any topic.