【问题标题】:Nuxt + IOT (aws-iot-device-sdk)Nuxt + IOT (aws-iot-device-sdk)
【发布时间】:2018-09-26 04:37:18
【问题描述】:

我创建了一个这样的插件:

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 is not a function at webpackJsonp../nodemodules/aws- iot-device-sdk/common/lib/tls-reader.js.module.exports

我该如何解决这个问题?

【问题讨论】:

    标签: aws-iot nuxt.js


    【解决方案1】:
    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());
      });
    

    【讨论】:

      【解决方案2】:

      这个错误有两个可能的原因,即,

      1. Angular 版本 > 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: "******" 
      });
      

      【讨论】:

        猜你喜欢
        • 2021-09-01
        • 1970-01-01
        • 2020-07-24
        • 2016-05-07
        • 1970-01-01
        • 2018-06-07
        • 2018-09-09
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多