Issue with measurement creation

I am using below code snippet to insert multiple measurement in a device.

Map<String, Object> attributeMap = new HashMap<String, Object>();
attributeMap.put("sol_Measurement", measurmentMap);
MeasurementRepresentation createMr = new MeasurementRepresentation();
createMr.setAttrs(attributeMap);
createMr.setSource(manageObjectResponse);
createMr.setType("sol_Measurement");
createMr.setDateTime(measurement.getDateTime());
measurementApi.create(createMr);

attributeMap is a map with multiple measurement.
like below

{"M1":{"unit":"GPM","value":95},"M2":{"unit":"GPM","value":90},"M3":{"unit":"inches of airspace","value":85}}}

Data is not inserted in the respective device and i don’t get any error as well.

Could you point the possible issue in this.

Thanks

Regards/-Prakash

Before I answer, please use proper formatting when posting anything.
Code block should be added in code blocks like this using “```”

This is code

Now to your question:
Instead using Map<String, Object> you should use a Map<String, MeasurementValue>
Also you can just use “set”. Here is an example:

HashMap<String, MeasurementValue> mvMap = new HashMap<>();

MeasurementValue mvx = new MeasurementValue();
mvx.setValue(xValue);
mvx.setUnit("g");
mvMap.put(sensorTypeX, mvx);
MeasurementValue mvy = new MeasurementValue();
mvy.setValue(yValue);
mvy.setUnit("g");
mvMap.put(sensorTypeY, mvy);
MeasurementValue mvz = new MeasurementValue();
mvz.setValue(zValue);
mvz.setUnit("g");

MeasurementRepresentation measurementRepresentation = new MeasurementRepresentation();
measurementRepresentation.set(mvMap, name);
measurementRepresentation.setType(type);
measurementRepresentation.setSource(mor);
measurementRepresentation.setDateTime(dateTime);
measurementApi.create(measurementRepresentation);

Also make sure that your Timestamp is a UTC formatted joda.DateTime and most possible not in the future (this is often the reason measurements are not visible in the UI but can be retrieved via API). Just check the MeasurementAPI if the measurement has been created, with the ID returned from the MeasurementAPI in java.

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