How to get realtime data in c8y_Availability from inventory managed Objects

Hi,
Whenever I’m pushing the data using data injection into measurement objects, I need to get Realtime Device status in c8y_Availability from inventory managed Objects.

Ex:
Once I had pushed the data using data injection into a measurement object , I wanted to get the device’s status Realtime, but i couldn’t be able to get the status.
UNAVAILABLE or AVAILABLE form c8y_Availability

“c8y_Availability”: {
“lastMessage”: “2023-10-12T12:21:16.132Z”,
“status”: “UNAVAILABLE”
}
I tired like this.
fetchRealtimeMeasurements() {
this.realtime.subscribe(
/measurements/${this.deviceId},
(measurementNotification) => {
const measurement: IMeasurement = measurementNotification.data.data;
if (measurement) {
this.getDeviceStatus();
}
}
);
}

async getDeviceStatus(){
  let { data, res } = await this.inventoryService.detail(this.deviceId);        
 if (data.hasOwnProperty("c8y_Availability") && data.hasOwnProperty("sol_sys")) {
            this.AVAILABLE = data['c8y_Availability']['status'];
}

}

Could please help and resolve the issue?

Hi,

can you elaborate a bit more what exactly the issue is?
Is the c8y_Availability attribute missing? Does it still have the old status?

Why do you subscribe on measurement realtime updates if you are actually interested in updates of the managedObject in the inventory?
The update of the c8y_Availability status is happening in an async process, so just because you received a measurement this may not directly be visible in the c8y_Availability attribute.

Regards,
Tristan

Hi @Tristan_Bastian ,

In a Navbar-header I want to display the device’s status as available or unavailable in real time.
The above example is that I tried to get device status in Realtime, but the inventory management object received its old status. After referring to the page, I can see the status unavailable into available.

I’m consider device status.
Available as Online
Unavailable as Offline

Could please tell me how to show the device status Realtime?

Please check the sample provided in the tutorial application on how to subscribe for realtime updates of managedObjects.
The tutorial application can be scaffolded using e.g. c8ycli new tutorial tutorial as described multiple times in the documentation: Tutorials - Cumulocity IoT Guides

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.