【问题标题】:AWS IOT Error: premature close at onclosenexttickAWS IOT 错误:在 onclosenexttick 过早关闭
【发布时间】:2020-01-09 12:50:32
【问题描述】:

我正在尝试构建一个基本的 AWS IOT Javascript 应用程序,下面是源代码

var awsIot = require('aws-iot-device-sdk');

var device = awsIot.device({
keyPath: 'xxx-private.pem.key',
certPath: 'xxx-certificate.pem.crt',
caPath: 'AmazonRootCA1.pem',
clientId: 'xxx_policy',
host: 'xxxxx.amazonaws.com'
});

device.on('connect', function() {
console.log('connect');
//device.subscribe('topic_1');
device.publish('MyConnectPolicy', JSON.stringify({ test_data: 'NodeJS server connected...'}));
});

device.on('message', function(topic, payload) {
console.log('message', topic, payload.toString());
});

在运行这个项目时,我遇到了错误

events.js:200
throw er; // Unhandled 'error' event
^
Error: premature close
at onclosenexttick (xxx/node_modules/end-of-stream/index.js:54:86)
at processTicksAndRejections (internal/process/task_queues.js:76:11)

Emitted 'error' event on DeviceClient instance at:
at MqttClient. (xxx/node_modules/aws-iot-device-sdk/device/index.js:772:15)
at MqttClient.emit (events.js:228:7)
at TLSSocket.f (xxx/node_modules/once/once.js:25:25)
at onclosenexttick (xxx/node_modules/end-of-stream/index.js:54:73)
at processTicksAndRejections (internal/process/task_queues.js:76:11)

有人可以解决这个问题吗,在此先感谢。

【问题讨论】:

  • 当我使用 openssl 检查连接时它工作正常,openssl s_client -connect xxxxEP:8883 -CAfile xxxAmazonRootCA1.pem -cert xxx.pem.crt -key xxx-private.pem。键已连接(00000003)

标签: javascript amazon-web-services iot aws-iot aws-sdk-ios


【解决方案1】:

我最近在尝试使用适用于节点的 AWS-IoT-SDK 连接到 AWS 上的 thing 时遇到了同样的问题。我终于在这个 [Github issue][https://github.com/aws/aws-iot-device-sdk-js/issues/304#issuecomment-608500683].

上找到了我的解决方案

我没有为我的thing 附加政策。

要为您的 thing 创建新策略,您可以在创建事物时执行此操作或

In the left navigation pane, choose Secure, and then choose Policies. On the You don't have a policy yet page, choose Create a policy.

On the Create a policy page, in the Name field, enter a name for the policy (for example, MyIotPolicy). Do not use personally identifiable information in your policy names.

Further reading

【讨论】:

  • 如果您将所需的步骤直接添加到您的答案中,那就太好了。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-09-30
  • 2019-05-15
  • 1970-01-01
  • 2021-11-10
  • 1970-01-01
相关资源
最近更新 更多