How to set the c8y_Position fragment using microservice

I wanted to create a device with initial position such as
c8y_position:{
“lat”:34.
“lon”:23,
“alt”:0
}
Code snippet is as follows

import c8y.Position;

ManagedObjectRepresentation managedObjectRepresentation = new ManagedObjectRepresentation();
        managedObjectRepresentation.setName(device.getName());
        managedObjectRepresentation.setType(device.getType());
        managedObjectRepresentation.set(new IsDevice());
        managedObjectRepresentation.set(new Agent());
        managedObjectRepresentation.set(new Position[]);

As the Position array is not taking multiple values,what are the possible ways of doing it ?

Hi @rushikesh_n ,

why do you want to use an array, can you elaborate on your use case?

  • Instead of using the set method I recommend using the setProperty method, as it is a bit more convenient to use,
    in general your usage of set is also fine though.
  • In the Position object it is “lng” and not “lon” for your information.
    Like this you can set the position:
import c8y.Position;

Position position = new Position();
position.setAlt(BigDecimal.valueOf(0));
position.setLat(BigDecimal.valueOf(34));
position.setLng(BigDecimal.valueOf(23));
...		
managedObjectRepresentation.setProperty("c8y_Position", position);

Regards
Kai

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