Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » OM2M » How to send sensor value to actuator plug-in
How to send sensor value to actuator plug-in [message #1737076] Tue, 05 July 2016 14:12 Go to next message
Trung Luu is currently offline Trung LuuFriend
Messages: 32
Registered: June 2016
Member
Hi,
I created 2 different plug-in sensor and actuator, in sensor plug-in, I random the sensor value and I want to send those value to actuator plug-in, can anyone suggest me how to do it in java? Thanks alot.

Best Regards,

Trung
Re: How to send sensor value to actuator plug-in [message #1737162 is a reply to message #1737076] Wed, 06 July 2016 07:56 Go to previous messageGo to next message
Dorian Kurzaj is currently offline Dorian KurzajFriend
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 Smile
Re: How to send sensor value to actuator plug-in [message #1737168 is a reply to message #1737162] Wed, 06 July 2016 08:19 Go to previous messageGo to next message
Trung Luu is currently offline Trung LuuFriend
Messages: 32
Registered: June 2016
Member
Hi Dorian,

Thanks for your help, but I have one more question that if the sensor and the actuator are in different plug-in, how can they communicate to get value from each other?

Best Regards,

Trung
Re: How to send sensor value to actuator plug-in [message #1737170 is a reply to message #1737168] Wed, 06 July 2016 08:27 Go to previous messageGo to next message
Dorian Kurzaj is currently offline Dorian KurzajFriend
Messages: 16
Registered: May 2016
Junior Member
You welcome.
I don't really understand what would be the problem if they are in different plugins, you can send requests to OM2M from where ever you want.

Regards,
Dorian
Re: How to send sensor value to actuator plug-in [message #1737173 is a reply to message #1737170] Wed, 06 July 2016 08:39 Go to previous messageGo to next message
Trung Luu is currently offline Trung LuuFriend
Messages: 32
Registered: June 2016
Member
Thank you for your answer, I'm quite new with OM2M so I still get something to consider, Would you mind if you add my e-mail and I can ask you directly about this problem? my e-mail: baotrung1309@gmail.com

Regards,

Trung
Re: How to send sensor value to actuator plug-in [message #1737174 is a reply to message #1737173] Wed, 06 July 2016 08:45 Go to previous messageGo to next message
Dorian Kurzaj is currently offline Dorian KurzajFriend
Messages: 16
Registered: May 2016
Junior Member
Actually I'm quite new at using OM2M too, I am not sure I will be a great help to you ^^
I think it's better that you detail your question here to see if other people can also answer Confused

Regards,
Dorian

[Updated on: Wed, 06 July 2016 08:52]

Report message to a moderator

Re: How to send sensor value to actuator plug-in [message #1737213 is a reply to message #1737174] Wed, 06 July 2016 12:53 Go to previous message
Mahdi Ben Alaya is currently offline Mahdi Ben AlayaFriend
Messages: 229
Registered: November 2013
Senior Member
Hello

Thank you Dorian. Your support is much appreciated.
Trung, you are welcome to detail your issue in this topic.
Previous Topic:HTTP Error 404 when running om2m on Ubuntu 12.04
Next Topic:Create your own Plugin
Goto Forum:
  


Current Time: Tue Apr 23 17:29:41 GMT 2024

Powered by FUDForum. Page generated in 0.03123 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top