Search code examples
azureiotazure-iot-hubazure-iot-edgeazure-iot-sdk

Azure IoT edge programmatically[NodeJS] create parent child relation between edge and leaf device


I have found links from Azure GitHub repo that we can create relationship of parent child between Edge device and leaf device using Java and Python language but I have not found the api/interface to that in NodeJS sdk provided by Azure. Has anyone implemented this in NodeJS?


Solution

  • According to the REST API there is the deviceScope property:

    The scope of the device. Auto generated and immutable for edge devices and modifiable in leaf devices to create child/parent relationship.

    So try providing this property in the device object as e.g. here that is used for registry.create()

    UPDATE: so this code works:

      var device = {
        deviceId: '<MY DEVICE ID>',
        deviceScope: 'ms-azure-iot-edge://<MY EDGE DEVICE ID>-xxxxxxxx'
      };
    
      registry.update(device, printAndContinue('update', function next(){...});
    

    You can find the value of the deviceScope of your Edge Device in its Device Twin:

    enter image description here

    UPDATE

    If you want to remove the parent/child relationship set deviceScope: null in your request