Integrate multiple devices from Azure IoT Hub

118 Views Asked by At

I followed the tutorial from your help site: https://thingsboard.io/docs/user-guide/integrations/azure-iot-hub/

It works well so far. However, I can only use one integration for a single device (as I can only add credentials for a single device per integration). I cannot find a way to add credentials for another device except for adding another integration (which is not intended, I guess). So this is what I tried: adding another integration. However, I can only add 20 integrations which amounts to 20 sensors. Am I supposed to add a new integration for each of my IoT Hub devices? Or is it possible to channel multiple devices through a single integration?

Thank you.

Best, Andy

1

There are 1 best solutions below

2
Sampath On

Schedule and broadcast jobs is used for update millions of devices . Use Azure IoT Hub to schedule and track jobs that update millions of devices.The below code is for Node.js to interact with Azure IoT Hub and schedule jobs for device methods and twin updates.

I followed DOC scheduling and broadcasting jobs using Node.js with Azure IoT Hub.

Code:


var methodParams = {
    methodName: 'lockDoor',
    payload: null,
    responseTimeoutInSeconds: 15
};

var methodJobId = uuid.v4();
console.log('scheduling Device Method job with id: ' + methodJobId);
jobClient.scheduleDeviceMethod(methodJobId,
                                queryCondition,
                                methodParams,
                                startTime,
                                maxExecutionTimeInSeconds,
                                function(err) {
    if (err) {
        console.error('Could not schedule device method job: ' + err.message);
    } else {
        monitorJob(methodJobId, function(err, result) {
            if (err) {
                console.error('Could not monitor device method job: ' + err.message);
            } else {
                console.log(JSON.stringify(result, null, 2));
            }
        });
    }
});

var twinPatch = {
    etag: '*',
    properties: {
        desired: {
            building: '43',
            floor: 3
        }
    }
};

Output:

enter image description here

Azure:

enter image description here

Updated:

You can integrate more than one device by adjusting the queryCondition parameter. Here's how you can modify the queryCondition to target multiple devices:

var deviceIds = ['deviceId1', 'deviceId2', 'deviceId3']; // Add the IDs of your devices here
var queryCondition = "deviceId IN ['" + deviceIds.join("', '") + "']";

Replace 'device1', 'device2', 'device3' with the IDs of the devices you want to target. You can list as many device IDs as needed, separated by commas inside the square brackets.

enter image description here