Reputation: 2857
I've have a list of 30 IOT devices, I'm trying to show the status of each device in a web page as the page loads. I'm using AWS IOT Device SDK(https://github.com/aws/aws-iot-device-sdk-js) for this one.
I've created the thing shadow at first. And then I'm running a loop with the deviceId array trying to register each device to the thing shadow using the unique deviceId as thing name and then in the register callback I'm trying to call the get method with the thing name to get the initial status. And I've added a listener to the status event.
This works fine for few devices and the get method returns valid client token, but then after 10-12 devices I'm getting null as response of the get method and thus the status event is also not fired for the devices.
My code is like:
for (var i = 0; i < me.deviceList.length; i++) {
var deviceId = me.deviceList[i].DeviceId;
awsIotThing.register(deviceId, {}, function() {
var token = client.thing.get(deviceId);
console.log('thingName', thingName, token);
});
}
I also tried with some timeout here, if it's some asynchronous method call issue.
for (var i = 0; i < me.deviceList.length; i++) {
var deviceId = me.deviceList[i].DeviceId;
$timeout(function(){
awsIotThing.register(deviceId, {}, function() {
var token = client.thing.get(deviceId);
console.log('thingName', thingName, token);
});
}, 1000*i);
}
But still I got the same error.
I've attached the screenshot of the browser console where you'll see initially it got the client token, it listens to the status event and the device status is also modified in the app but then after few devices, it starts getting null as a response of the get event thus the status event is also not fired.
Upvotes: 0
Views: 752
Reputation: 887
You can use Fleet Indexing with enabled Connectivity Indexing https://docs.aws.amazon.com/iot/latest/developerguide/managing-index.html and do search for your deviceId. In results you can check connectivity.
Also you can search for all connected devices by using search with query connectivity.connected:true
Upvotes: 1