AWS IOT JS device SDK not connecting and keep on r

2019-06-06 00:51发布

问题:

var awsIot = require('aws-iot-device-sdk');
var uuid = require('uuid');
var device = awsIot.device({
    keyPath: "<path>-private.pem.key",
    certPath: "<path>-certificate.pem.crt",
    caPath: "<path>-root-CA.key",
    clientId: uuid.v4(),
    debug:true,
    host: <hostId>,
    will:{
        topic:"blahblahblah",
        payload:"disconnecting",
        qos:0,
        retain:false
    }
});

device
    .on('connect', function() {
        console.log('connect');
        device.subscribe('cgw/devices/register');
    });

device.on('message', (topic, payload, message) => {
    console.log(topic);
    console.log(payload);
    console.log(message);
});

   device
      .on('close', function() {
         console.log('close');
      });
   device
      .on('reconnect', function() {
         console.log('reconnect');
      });
   device
      .on('offline', function() {
         console.log('offline');
      });
   device
      .on('error', function(error) {
         console.log('error', error);
      });

I am trying to run the sample code above but the device is not getting connected. I have also tried passing

retain param as false

as per https://github.com/aws/aws-iot-device-sdk-js/issues/61

but still the program is not running and shows

offline close reconnecting close reconnecting close reconnecting close reconnecting