|
Re: How to send sensor value to actuator plug-in [message #1737162 is a reply to message #1737076] |
Wed, 06 July 2016 07:56 |
Dorian Kurzaj Messages: 16 Registered: May 2016 |
Junior Member |
|
|
Hi,
Using the IPE sample of the lamps, I wanted to get the OM2M values of the lamps in order to update the GUI (because in the given code, if you modify the OM2M values without using the IPE's specific requests, but the classic CRUD requests, the GUI is not updated), so here is the method I used to retrieve the value of the lamp:
public static boolean getLampOM2MState(String lampId){
// We forge the URI of the last cin
String targetID = SampleConstants.CSE_PREFIX + "/" + lampId + "/" + SampleConstants.DATA + "/" + SampleConstants.LA;
// We get the last cin
ContentInstance cin = (ContentInstance)RequestSender.getRequest(targetID).getContent();
// And we extract the value from the cin
return ((Bool)(ObixDecoder.fromString(cin.getContent()).getObjGroup().get(3))).getVal();
}
For your sensor, you should probably just change the Obix cast if you are using the Obix convention too.
And to set the value, let's take the exact code given in the sample IPE lamps example too:
public static void setLampState(String lampId, boolean value){
// Set the value in the "real world" model
SampleModel.setLampState(lampId, value);
// Send the information to the CSE
String targetID = SampleConstants.CSE_PREFIX + "/" + lampId + "/" + SampleConstants.DATA;
ContentInstance cin = new ContentInstance();
cin.setContent(ObixUtil.getStateRep(lampId, value));
cin.setContentInfo(MimeMediaType.OBIX + ":" + MimeMediaType.ENCOD_PLAIN);
RequestSender.createContentInstance(targetID, null, cin);
}
And you just have to do something like this:
boolean lamp0State = SampleController.getLampOM2MState("LAMP_0");
setLampState("LAMP_1", lamp0State)
This code should reproduce the value from the LAMP_0 to the LAMP_1, you just have to adapt it to your sensor and actuator with the right types
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03826 seconds