Nuxt + IOT (aws-iot-device-sdk)

柔情痞子 提交于 2021-02-10 19:57:25

问题


I create a plugin like this:

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'
})

It works, but displays an error message:

C:\Sistemas\AM\nodemodules\aws-iot-device-sdk\common\lib\tls-reader.js:89 Uncaught TypeError: filesys.existsSync is not a function at webpackJsonp../nodemodules/aws-iot-device-sdk/common/lib/tls-reader.js.module.exports

How can I fix this?


回答1:


There are 2 possible reasons of this error, i.e., 1. Angular version > 4 or not and 2. Indenting alignment problem in the 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: "******" 
});



回答2:


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());
  });


来源:https://stackoverflow.com/questions/49857300/nuxt-iot-aws-iot-device-sdk

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!