amazon-web-services - 如何使用 mqtt.js 连接到 AWS IoT
问题描述
以下代码报告握手超时错误。我没有在代码上提供确切的数据,而是根据我自己对这些参数的理解。我的理解有什么问题吗?
var options = {
clientId: a random String,
endpoint: the endpoint of AWS IoT Core,
accessKey: I generate this from IAM - > Dashboard - > My access Key - > Access key,
secretKey: I generate this from IAM - > Dashboard - > My access Key - > Access key,
regionName: i find this from endpoint,
debug: true
};
var client = mqtt.connect('ws://' + endpoint, options);
//var client = mqtt.connect('mqtt://test.mosquitto.org');
client.on('connect', function() {
alert("MQTT connected");
client.subscribe('topic_1')
client.publish('topic_1', 'Hello mqtt2')
})
client.on('message', function(topic, message) {
// message is Buffer
alert(message.toString())
client.end()
})
我想知道我是否误解了 connect 函数的第一个参数,但我不知道如何更改。
我的政策如下所示。
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "iot:*",
"Resource": "*"
}
]
}
我确信我已将此政策附加到我的证书中。
解决方案
推荐阅读
- c# - Web.Config 中的 Oracle.ManagedDataAccess TNS_ADMIN
- cloud-foundry - 如何在 pcf 命令中从特定应用程序获取路由?
- qt - 在 QML 中创建带有背景和垂直环绕的字幕
- spring-boot - 从命令行参数覆盖 Spring 中的应用程序属性值
- javascript - 在 Google 地图信息窗口中将 href 显示为图像
- android - 在 API 级别 26 上集成 Google Maps API v1
- android - 使用 Rxjava2 交错项目
- prolog - 使用 prolog 编码给定的输入
- sql - 案例陈述选择
- android - MutableLivedata 观察者触发