Device stays offline after registration and while storing measurement

Product/components used and version/fix level:

Detailed explanation of the problem:

We are registering and creating device from our custom java microservice. Devices are sending measurements to our custom java microservice and from there we are sending measurements to cumulocity.
In cumulocity we are able to view measurements with correct timestamp, but in ‘Device Management’ devices are seems ‘Offline’ and ‘Last communication’ is also not getting updated.

Error messages / full error message screenshot / log file:

Question related to a free trial, or to a production (customer) instance?

production (customer)

Hi @gagan.shah,

check this Device connection and status - #2 by Reuben_Miller2 and this
Device not showing online - #2 by Stefan_Witschel

1 Like

Hi Stefan,

Thank you for your response.

  1. I tried sending the empty PUT request from postman, it worked, “c8y_Availability” is “AVAILABLE” but “c8y_Connection” is “DISCONNECTED”.

With Java SDK it didn’t work.
In below code snippet, I am updating managed object without any addition property but its not updating.

ManagedObjectRepresentation measurementUploadMetadata = new ManagedObjectRepresentation();
measurementUploadMetadata.setId(GId.asGId(id));
inventoryApi.update(measurementUploadMetadata);

We are not using RestTemplate, it will be great, if you share cumulocity java sdk code sample.

  1. For 2nd point I am confused, how can we disable the header in SDK since all the methods are predefined.

Thanks,
Gagan

1 Like

Hi @gagan.shah ,

to 1. The second c8y_connection is only “green” when subscribed for operations via REST API (long-polling) or you have a MQTT client connected which is subscribed to “s/ds”. See also here: Device management - Cumulocity IoT Guides

to 2: Use RestTemplate for the empty PUT request. Here are some nice example of Alex. You can see how to set the headers (authentication etc.), just adapt it to inventory API and you are fine.

1 Like

Hey @Stefan_Witschel , I have the same issue with Streaming analytics. Where i send a calculated data to a device using streaming analytics analytics builder, the measurement data received to the device successfully but the connection still shows offline, any idea?

Thanks,
Saif

Hi @saif.hasn

that is intended because streaming analytics should not influence the device connectivity status, only the agent should do this.
In other words: You can calculate values as you wish but if the device is not connected it should be stated as “offline”.

1 Like

Hi @Stefan_Witschel,

I have two questions:

  1. Is there any way to manipulate it from the streaming analytics or any managejObjects block so we can make this offline status work? Or do you have any workaround?

Our case is that we create a device in c8y just to received aggregated or average data from one or more device via streaming analytics and we would like the device to have availability status working.

  1. Do you know if any data committing from streaming analytics counts for MEA charges or not?

Thanks,
Saif

Hi @saif.hasn,

to 1: You cannot do this with Analytics Builder. If you send calculated data to a device using streaming analytics the device is considered to be offline which is correct because no other component is involved managing the connection status of the device. Actually in your case the connection status should be totally ignored. More precisely I assume when you do that you want to send data to an asset (which does not have any connectivity status) not to a device.

You can add an external component sending empty PUTs to the managed object / device within the defined required interval.
Please note that this has to be an external component not using the header X-Cumulocity-Application-Key in that PUT request otherwise it will be ignored again.

to 2: Again, it seems to me that it is not a device you are creating but assets where you are storing aggregated data on. It does not make sense to have the connection availability status working if you don’t have any real physical connection to that device which could be managed. Everything else would be just confusing simulating any connectivity status which is not existing.

I can’t answer your pricing conditions in regards of MEA charges because they really depend on your contract and you should clarify them with your Software AG Sales / Partner contact.

Thank you @Stefan_Witschel for all the information, really helpful. You suggest to add an external component sending empty PUTs to the managedObjects, do you know a way how to send this via streaming analytics? And can you also give me the empty PUT exampple?

Thanks,
Saif

@saif.hasn

It’s not possible using streaming analytics, as streaming analytics uses this header so it is not recognized as a “device request” updating the connectivity status.

Empty PUT:
https://cumulocity.com/api/core/#operation/putManagedObjectResource

Hi Saif, Stefan,

It’s true that Streaming Analytics by default will use the configured application key for all requests. However, you can create a custom connection to override that:

  • Create a Cumulocity_RequestInterface object as described in EPL Apps - Cumulocity IoT documentation
    CumulocityRequestInterface cumulocity := CumulocityRequestInterface.connectToCumulocity();
  • Override the appKey
    cumulocity.appKey := “”;
  • Create a request to the endpoint manually:
    Request r := cumulocity.createRequest(“PUT”, “/inventory/managedObjects/”+id, new any);
    r.execute(callbackAction);

This will avoid having to add an additional extra component.

1 Like

Hi @Matthew_Johnson

thx, I never stop learning! :smiley: I was not aware, that you can override the appKey header within EPL App.

@saif.hasn Still, you should ask yourself if this make sense in your use case. The intention of the connectivity status is to monitor the physical connection of a device to Cumulocity. If the device does not have any physical connection I would rather argue that this is an asset holding calculated data (without any connectivity status). The device that get’s the “raw” device data has a physical connection and therefor a connectivity status.

Hi @Stefan_Witschel,

Yes, it makes sense, and we are not going to apply this to all of our devices. These are just a few devices where we would like to verify if they are receiving data from the streaming analytics or not.

@Matthew_Johnson do we know if we can override the header from “Analytics builder” as well?

Thanks,
Saif

Hi @saif.hasn you would need a custom analytics builder output block for this. There’s no way to do it built-in, only via EPL Apps.