Listen for device connection in managedObjects

What product/components do you use and which version/fix level are you on?

Cumulocity 10.6.0

Is your question related to the free trial, or to a production (customer) instance?

Produciton

What are you trying to achieve? Please describe it in detail.

Looking to understand whether there is a a bulletproof event from the namagedObject side of c8y where we know the device has just connected.

I have a microservice that listens for events in real time and I want to trigger a process once we know a device has connected to send its payload.

We have used:

“c8y_Connection”: {“status”:“CONNECTED”}

We have had the microservice log to Slack all events from managedObjects where we saw for three days the "status":"CONNECTED" value in the payload of our demo devices at reporting times.

But after three days, we see no more this “CONNECTED” state (all payloads showing “DISCONNECTED”).

What is the way to reliably determine when the device has first connected?

Do you get any error messages? Please provide a full error message screenshot and log file.

No errors, just not reliably seeing the CONNECTED status manageObject event payload.

Have you installed all the latest fixes for the products and systems you are using?

Not needed

The connection status in the c8y_Connection fragment refers to connection monitoring for devices (see: Device Management - Cumulocity IoT Guides). This status changes with a device’s push connection becoming active or inactive. It is not a way to determine when a device was registered.

Usually we use the creation date of a managed object as registration date.

Hi Philipp,
Thank you for your reply.

What I am trying to achieve from the inventoryObject event is to understand when a device had connected and sent payload to know when data had arrived. I then go get the data and process it externally. This is post registration and as part of the daily data send cycle for my type of device.

I am doing this in a microservice. I understand the lastMessage field can be checked but I would need its prior state.

What would you suggest is the best way to understand when a device has sent payload in a microservice? I want to notify an external application with either “data is arriving for id 35213” or even better, “data has arrived for device 35213, and here’s the $payload”.

I guess what you could do as well is using the new Notification 2.0 API.
While subscribing to Measurements/Events/Alarms of that device you would basically get notified whenever there is something send from that particular device and use that trigger for your microservice logic.

Hi Murat, thanks for the reply.

We are using Notification 2.0 in our Microservice to listen to Alarms, ManagedObject and DataReadings events.

For our specific use case, I want the microservice to detect when data received for a device, then send that data to a serverless application (using Lambda).

We want to be able to identify a device that has just communicated a payload, then forward it to Lambda.

Having used the “c8y_Connection”: {“status”:“CONNECTED”} key seemed to work for the first few days but then it stopped being received regularly (we send all event data from the three channels to Slack, and do not filter it). I understand this key is set based on a per minute heartbeat check for a device being connected, so if the device connects for 30 secs right after the heartbeat, we would not see this state being changed.

Is there an event / key/value that signals “data received and device disconnected” that I can use? As in in any of the channels (Alarms, ManagedObjects, DataReadings). A key/value within one of the objects that signifies this event without having to remember the previous state of the key (e.g.: LastMessage in ManagedObject).

Thank you so much!

Hi Marc,

I would argue this is an issue of data design of the device agent.
To work with historical data the managed Object is the wrong object to do this. Most likely you should work with events of a specific type you subscribe on. So each time you receive an event of a specific type you know that the device is online and sent payload (as part of this event).
You can also register on managed object updates but then need to figure out what has been actually changed.

Hi Stefan, awesome! What specific event type would you suggest to look at to understand data arrival from the device?

We currently reverted to lastMessage and we use the external app to confirm this date has changed. If we could confirm the data arrival in the microservice we would avoid a bunch of useless (and costly) traffic between c8y and our app.

Thanks again.

Thanks.

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