HarisH Sharma
HarisH Sharma

Reputation: 1257

How to use MQTT-JS or JS AWS-SDK (node JS/JS) to send and receive data to a topic of AWS IoT

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: enter image description here

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:

enter image description here

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: enter image description here

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. enter image description here

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. enter image description here

Upvotes: 0

Views: 2637

Answers (1)

sokkasokka
sokkasokka

Reputation: 38

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

Upvotes: 1

Related Questions