aws / aws-iot-device-sdk-js

SDK for connecting to AWS IoT from a device using JavaScript/Node.js
Apache License 2.0
964 stars 384 forks source link

Not connecting to the broker. Continuously in the loop of offline close reconnect close reconnect... #153

Closed anmolgupta closed 7 years ago

anmolgupta commented 7 years ago
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: <unique identifier >,
    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

but still the program shows

offline close reconnecting close reconnecting close reconnecting close reconnecting ....

anmolgupta commented 7 years ago

My bad. The policy ARN needs to be edited for the device.

Rajat07101994 commented 7 years ago

we change our policy of arn with new connection code and where is this uuid come from

runemadsen commented 6 years ago

I'm having the same issue. Can you please elaborate on what the solution is? Can you paste your policy here for reference?