Iot connectivity.connected always false

0

I'm running about 20 different devices in my dev environment using Iot and the javascript device sdk (the device is running a node process). The devices connect fine, they receive shadow document updates, they receive jobs, they can post to topics, etc. I've enabled fleet indexing with thing connectivity enabled. When I run the query "connectivity.connected:true", the query always returns no devices. When I run the query "connectivity.connected:false", the query always returns all devices. I know the devices are connected, so I was wondering if I was missing something in my code that would make that connectivity value change to true. Code is below (with handlers for events removed):

        const name = this.getName();

        const thingShadowParams = {
            privateKey: privatekeyBuffer,
            clientCert: clientCertBuffer,
            caCert: caCertBuffer,
            clientId: name + '_s',
            host: this.config.aws.iotEndpoint,
        };

        // awsIot.thingShadow modifies the params object in place!
        const jobShadowParams = _.cloneDeep(thingShadowParams);
        jobShadowParams.clientId = name + '_j';

        const d = this.shadow = awsIot.thingShadow(thingShadowParams);
        const sensorTopic = this.config.aws.sensorValueTopic + name;
        const imageTopic = this.config.aws.imageTopic + name;

        d.on('connect', () => {
            d.register(name, {}, () => {
                d.subscribe([ sensorTopic, imageTopic ]);
                d.get(name);
            });
        });

        d.on('status', (thingName, stat, clientToken, stateObject) => {
			// do some work
        });

        d.on('delta', (thingName, stateObject) => {
			// do some work
        });

        d.on('error', (error) => {
			// report error
        });

        const j = this.job = awsIot.jobs(jobShadowParams);

        j.subscribeToJobs(name, function(err, job) {
            if (err) { return console.log(err); }
            instance.runJob(job);
        });

        j.startJobNotifications(name, function(err) {
            if (err) { return console.log(err); }
        });

        j.on('error', (error) => {
			// report error
        });

Edited by: AndyA on Jan 9, 2019 2:34 PM

AndyA
asked 5 years ago178 views
7 Answers
0

Hello Andy,

Just wanted to confirm - are your devices have corresponding things in the registry? [1] Fleet indexing only indexes information for things that are present in the registry.

[1] https://docs.aws.amazon.com/iot/latest/developerguide/thing-registry.html

answered 5 years ago
0

Yes, all of my devices have thing representations in the registry. They have shadow state that goes back and forth correctly, etc.

Edited by: AndyA on Jan 10, 2019 7:56 AM

AndyA
answered 5 years ago
0

Please share your account #, region and time frame where you were doing tests, we'll take a look. You can send these via PM.

answered 5 years ago
0

ok, finally looked through the logs, sorry for this taking so long! The problem is that clientId for devices that are being connected are plain seemingly random UUIDs, and Registry does not have things with such names.

You need to check client creation code to see if clientId is initialized correctly.

answered 5 years ago
0

Mismatch in client id with thing name causes connection events ignored.

answered 5 years ago
0

Alex@AWS wrote:
Mismatch in client id with thing name causes connection events ignored.
Alex@AWS wrote:
Mismatch in client id with thing name causes connection events ignored.
So this is a great clue. Looks like if I set the clientId to the thingName it starts working. So then I have another question. Since the clientId has to be unique on the connections, how do I start a thingShadow and a jobs refrences with the same clientId. If I use the same client id, both instances seem to connect / disconnect / and reconnect endlessly. So when I do the following:

const thingShadowParams = {
privateKey: <key>
clientCert: <cert>
caCert: <cert2>
clientId: name,
host: this.config.aws.iotEndpoint,
};

const jobShadowParams= {
privateKey: <key>
clientCert: <cert>
caCert: <cert2>
clientId: name,
host: this.config.aws.iotEndpoint,
};

this.shadow = awsIot.thingShadow(thingShadowParams);
this.job = awsIot.jobs(jobShadowParams);

I get continuous reconnection issues. If I change the jobShadowParams clientId to be something else (for example by appending "_j"), the system seems to be working right. But that seems the be a wrong usage of the clientId, which seems to need to be the same as the thingName (otherwise the jobs connection will not notice that it reconnected). How do I create both refrences to the same object, so I can manage shadow changes and respond to jobs?

Also, the documentation for the sdk states the following about clientID:
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.

It doesn't say anything about it matching the thingName. So maybe the documentation needs to be updated in the sdk?

Edited by: AndyA on Mar 15, 2019 2:13 PM

AndyA
answered 5 years ago
0

Multiple AWS IoT services could work via a single connection. I'm more familiar with Python SDK, it allows to specify pre-connected MQTT client when constructing shadow / jobs client, other SDKs should have similar capability.

Regarding matching clientId with thingName - it is not required to use most of AWS IoT capabilities (except few, like connectivity indexing for Fleet Indexing or applying policies on thing groups).

answered 5 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions