我创建了一个这样的插件:
var awsIot = require('aws-iot-device-sdk')
var device = awsIot.device({
keyPath: 'xxxxxx,
certPath: 'xxxxxx,
caPath: 'xxxxxx',
clientId: 'xxxxx',
region: 'xxxxxx',
host: 'xxxxxxxxxx.amazonaws.com'
})
可行,但会显示错误消息:
C:\ Sistemas \ AM \ nodemodules \ aws-iot-device-sdk \ common \ lib \ tls-reader.js:89 Uncaught TypeError:filesys.existsSync不是webpackJsonp的函数../ nodemodules / aws- IOT装置-SDK /普通/ LIB / TLS-reader.js.module.exports
我该如何解决这个问题?
答案 0 :(得分:0)
此错误有两个可能的原因,即 1.角版本是否大于4,并且 2.在JsonP中缩进对齐问题
var awsIot = require('aws-iot-device-sdk');
var device = awsIot.device({
endpoint: 'https://******************.iot.eu-central-1.amazonaws.com',
keyPath: '../aws/************-private.pem.key',
certPath: '../aws/***********-certificate.pem.crt',
caPath: '../aws/***********-public.pem.key',
clientId: "******************",
region: "******"
});
答案 1 :(得分:0)
var awsIot = require('aws-iot-device-sdk');
//
// Replace the values of '<YourUniqueClientIdentifier>' and '<YourCustomEndpoint>'
// with a unique client identifier and custom host endpoint provided in AWS IoT.
// NOTE: client identifiers must be unique within your AWS account; if a client attempts
// to connect with a client identifier which is already in use, the existing
// connection will be terminated.
//
var device = awsIot.device({
keyPath: 'xxxxxxxxx-private.pem.key',
certPath: 'xxxxxxxxx-certificate.pem.crt',
caPath: 'rootCA.pem',
clientId: 'MyConnect',
host: 'xxxxxxx.iot.ap-southeast-1.amazonaws.com'
});
//
// Device is an instance returned by mqtt.Client(), see mqtt.js for full
// documentation.
//
device
.on('connect', function() {
console.log('connect');
//device.subscribe('topic_1');
device.publish('MyConnectPolicy', JSON.stringify({ test_data: 'NodeJS server connected...'}));
});
device`enter code here`
.on('message', function(topic, payload) {
console.log('message', topic, payload.toString());
});