I am new to Cumulocity and trying to write a microservice for Cumulocity platform in C#.
I cloned Cumulocity.SDK.Client REST examples from here: https://bitbucket.org/m2m/cumulocity-sdk-cs/src/master/
I created some devices through InventoryApi and added some attributes at the creation(c8y_Hardware, c8y_RequiredAvailability, c8y_Position). When I try to add a measurement to the device I am lost.
I tried adding measurement as an attribute.
My code looks like this:
MeasurementRepresentation measurement = new MeasurementRepresentation();
measurement.DateTime = DateTime.Now.ToUniversalTime();
measurement.Source = InventoryAPI.Get(new GId(deviceId));
measurement.Type = "Temperature";
JObject T = new JObject();
T.Add("value", 90);
T.Add("unit","C");
measurement.Attrs.Add("Temperature", T);
MeasurementApi.Create(measurement);
With this, I want a Temperature type measurement for the device. It doesn't throw an error but It also doesn't create any measurement.
First I thought I was wrong with Json nesting so added one more layer under attribute before "T".
Like this:
JObject T = new JObject();
T.Add("value", 90);
T.Add("unit","C");
JObject temperatureMeasurement = new JObject();
temperatureMeasurement.Add("T",T);
measurement.Attrs.Add("Temperature", temperatureMeasurement);
This too didn't work.
When I looked at test files, I saw some Set() method being used. Should I create a measurement object and then pass it with Set() method?
Since the Fragment classes in the test files are empty I don't know how the object should look.
Am I completely off or just some minor thing that I miss?
What is the correct method of creating a measurement for a device?