Device availability status not changing when measurments created using sdk api

The first things, we are using the cumulocity sdk API to insert a measurement to the device as given the code below

			MeasurementRepresentation createMr = new MeasurementRepresentation();
			createMr.set("measurement",xyz);
			createMr.setSource(xxx);
			createMr.setType(xxx);
			createMr.setDateTime(dateTime);
			measurementApi.create(createMr);

We are inserting every minute. But the device status in the manged object of the device is shown as unavilable

"c8y_Availability": {
    "status": "UNAVAILABLE"
}   


But for the same device if we insert the measurement through restapi at the same interval we get the device status as available
The insertion is done as given below
https://dev1.iot-dev.solenis.com/measurement/measurements
{
"fragment1": {        
    "Measurement1": {
        "unit": "upm",
        "value": 39
    }
},
"time": ",
"source": {
    "id": <<deviceId>>
},
"type": "fragment1"
}

Can somebody please let me know what could be the issue with creating measurements for a device using cumulocity sdk api

Hi @mohanbp

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

Basically you need to remove the X-Cumulocity-Application-Key header from the request or sending additional empty PUT requests (without the header) to update the status manually.

1 Like

Hi @Stefan_Witschel , Thanks for the reply.

I could not find any API method in sdk API’s to remove or exclude a particular header while creating or updating a measurement

I still tried the following code to send an empty update request to the managed object after creating

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

But this did not work

Can you please let me know if you have a piece of code to remove a particular header or exclude an header in sdk MeasurementApi or InventoryApi.

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