I am using the MQTT protocol to connect with the cumulocity platform and connect it with my application. Once I connected to the platform the parent device is automatically created and but I am facing an issue while creating child devices via MQTT protocol.
Suppose I have a list of devices and I want to add these devices as child devices in my parent device on Cumulocity IoT. So, I used the below command to register the parent device and child device:
Now, when I was creating many child devices at the same time, then sometimes the child devices are not created on Cumulocity IoT and once a child device is failed to create then none of the operations happens with it means unable to perform any operation on that device and we have used setTimout as well but it doesnât create any difference.
Only the parent device is displayed in device management â Devices â All devices.
did you subscribe on âs/eâ to check if there any errors during creation of the child devices?
Also kind of best practice is actually to make sure the devices are created in the platform before performing or sending any additional data to the platform. Otherwise it leads to race conditions and the operation is sent even the device havenât been created yet. (Most likely results in an âMQTT DeviceâŚâ created and not the MyChildDevice name is used).
You can achieve that by using QoS 2 and âwait_for_publishâ.
So for device creation you need something like this with QoS 2 (exactly once):
what do you mean with MQTT npm? This package mqtt - npm? In case yes, the package provides the possibilities to subscribe for topics (e.g. s/e) to check for errors. As per documentation, you can define a QoS level for each publish as well. In combination with a callback on your publish, you can wait until your ParentDevice has been created and afterwards create the corresponding child devices. I highly advice to follow @Stefan_Witschel recommendations.
Here you can find the official documentation about device integration using MQTT. A code example for integration via MQTT using nodejs is available here. Looks like the example uses the same library you might be using.
the serial must be an unique identifier which isnât used by any other device and possibly not in any other tenants.
â105â is not a good serial number and might exist in your tenant already. Might be also a bug that you are sending 101 with wrong parameters and 105 following (to get child devices)
I would prefer to combine uid of parent and child devices to the serial especially when the child device does not have any identifier like â105â e.g.
{parentUniqueIdentifier}_{childUniqueIdentifier} â 23sfhhhsd45f2345_105`