I am working on a project, in which I need to connect my devices via MQTT protocol to AWS IoT, to send and receive data.
So first I got my endpoint from the AWS Portal. Please check below screenshot:
Then I tried using AWS Lambda
for RnD purpose, and it is working as expected. Please check below screenshot, what code I did at AWS Lambda
:
But now I want to integrate this at the device end.
I tried MQTT JS to connect devices to AWS IoT data. Please check below code:
But this code is not working, no error I got in the output, Its just waiting.
In this code, I used the accessKey and secretKey, which I got after creating a user in AWS-IAM
, with permission AWSIoTDataAccess
.
I tried AWS-SDK also with the same IAM credentials. Please check below code.
But unfortunately, it is also not working.
Note: My device is just a Windows system, which will send and receive data for a topic at AWS IoT.
Please help me to solve this. Don't know what I missed. Any suggestion will be helpful for me. Thanks,
EDIT:
After followed the steps mentioned here https://docs.aws.amazon.com/iot/latest/developerguide/device-certs-create.html, suggested in answer by @sokkasokka. Finally getting some error at least. Please check below screenshot for the edited code and error.
Try creating AWS IoT Thing with proper permissions and use the certificates to authenticate your MQTT device.
https://docs.aws.amazon.com/iot/latest/developerguide/device-certs-create.html
And see this issue as well: Fail to connect to AWS IoT via mqtt.js