我正在尝试构建一个基本的 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)
有人可以解决这个问题,提前谢谢。