【发布时间】:2021-07-17 09:55:18
【问题描述】:
我使用 AWS Nodejs cli 在 AWS 上创建东西(使用 api 创建的东西 + 证书)
我有一个测试脚本可以连接到mqqtt服务器并发送心跳消息,一切都很好。
我移除设备(非活动证书、分离证书、分离策略和删除事物)以测试意外删除。
我尝试使用以前的名称创建东西,但我没有创建新证书,而是上传原始证书.pem(完全相同的证书.pem),附加策略和设备(与最初相同)并最终激活证书.这里没有错误,在 IoT 控制台上似乎一切正常。
但是当我运行测试脚本时无法连接到 mqtt 服务器(当设备没有证书或被删除时,行为相同):
2021-04-23T15:02:51.204 DEBUG Device:indoor-summer connecting...
{
privateKey: <Buffer 2d 2d 2d 2d 2d 42 45 47 49 4e 20 52 53 41 20 50 52 49 56 41 54 45 20 4b 45 59 2d 2d 2d 2d 2d 0a 4d 49 49 45 70 51 49 42 41 41 4b 43 41 51 45 41 71 46 ... 1629 more bytes>,
clientCert: <Buffer 2d 2d 2d 2d 2d 42 45 47 49 4e 20 43 45 52 54 49 46 49 43 41 54 45 2d 2d 2d 2d 2d 0a 4d 49 49 44 57 54 43 43 41 6b 47 67 41 77 49 42 41 67 49 55 65 58 ... 1170 more bytes>,
caCert: <Buffer 2d 2d 2d 2d 2d 42 45 47 49 4e 20 43 45 52 54 49 46 49 43 41 54 45 2d 2d 2d 2d 2d 0a 4d 49 49 44 51 54 43 43 41 69 6d 67 41 77 49 42 41 67 49 54 42 6d ... 1138 more bytes>,
clientId: 'indoor-summer',
host: 'XXXXXXXXXX.iot.ap-southeast-1.amazonaws.com',
debug: true,
keepalive: 300,
username: '?SDK=JavaScript&Version=2.2.6',
reconnectPeriod: 1000,
fastDisconnectDetection: true,
resubscribe: false,
protocol: 'mqtts',
port: 8883,
ca: <Buffer 2d 2d 2d 2d 2d 42 45 47 49 4e 20 43 45 52 54 49 46 49 43 41 54 45 2d 2d 2d 2d 2d 0a 4d 49 49 44 51 54 43 43 41 69 6d 67 41 77 49 42 41 67 49 54 42 6d ... 1138 more bytes>,
key: <Buffer 2d 2d 2d 2d 2d 42 45 47 49 4e 20 52 53 41 20 50 52 49 56 41 54 45 20 4b 45 59 2d 2d 2d 2d 2d 0a 4d 49 49 45 70 51 49 42 41 41 4b 43 41 51 45 41 71 46 ... 1629 more bytes>,
cert: <Buffer 2d 2d 2d 2d 2d 42 45 47 49 4e 20 43 45 52 54 49 46 49 43 41 54 45 2d 2d 2d 2d 2d 0a 4d 49 49 44 57 54 43 43 41 6b 47 67 41 77 49 42 41 67 49 55 65 58 ... 1170 more bytes>,
requestCert: true,
rejectUnauthorized: true
}
attempting new mqtt connection...
connection lost - will attempt reconnection in 1 seconds...
2021-04-23T15:02:52.456 DEBUG Device:indoor-summer reconnect
connection lost - will attempt reconnection in 2 seconds...
2021-04-23T15:02:54.617 DEBUG Device:indoor-summer reconnect
connection lost - will attempt reconnection in 4 seconds...
2021-04-23T15:02:58.778 DEBUG Device:indoor-summer reconnect
connection lost - will attempt reconnection in 8 seconds...
2021-04-23T15:03:06.945 DEBUG Device:indoor-summer reconnect
connection lost - will attempt reconnection in 16 seconds...
2021-04-23T15:03:23.145 DEBUG Device:indoor-summer reconnect
connection lost - will attempt reconnection in 32 seconds...
2021-04-23T15:03:55.309 DEBUG Device:indoor-summer reconnect
connection lost - will attempt reconnection in 64 seconds...
要恢复我关注的证书:https://docs.aws.amazon.com/iot/latest/developerguide/manual-cert-registration.html (Register a client certificate without a registered CA (CLI) )
编辑: 现在使用 AWS 控制台:
- 创建事物
- 创建证书(一键)
- 激活
- 附加政策
- 测试 mqtt 连接:一切正常
现在:
- 删除证书
- 上传相同的
00000000-certificate.pem文件 - 激活
- 测试 mqtt 连接:失败(与原始消息相同)
我错过了一步?
【问题讨论】:
标签: node.js amazon-web-services aws-cli aws-iot