Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » OM2M » Subscriptions(How To Subscribe to GSCL resources)  () 1 Vote
Subscriptions [message #1393947] Fri, 04 July 2014 14:27 Go to next message
Prem Vaithilingam is currently offline Prem VaithilingamFriend
Messages: 4
Registered: July 2014
Junior Member
How can the Network Application subscribe to GA resources ? Is this supported in the current implementation ? Can you please share code level details.

Also, what is the use of SubscriptionController in the Router and what functionality does it provide ?
Re: Subscriptions [message #1396457 is a reply to message #1393947] Tue, 08 July 2014 10:22 Go to previous messageGo to next message
Mahdi Ben Alaya is currently offline Mahdi Ben AlayaFriend
Messages: 229
Registered: November 2013
Senior Member
Hello Prem,

OM2M implements two subscription/notification scenarios:

Scenario 1: Notify a server-capable application:
A detailed example is available on our wiki here: https://wiki.eclipse.org/OM2M/REST_API

Scenario 2: Notify a non-server-capable application by redirecting notifications to one of its container.

Let's keep working on the same example described on the first scenario.
We have the "MY_SENSOR" application with its corresponding "DATA" containers deployed on the GSCL.
Now, create on the NSCL a new application "MONITOR" with its corresponding container "NOTIFICATION".
Then, subscribe the "MONITOR/containers/NOTIFICATION/contentInstances" resource to "MY_SENSOR/containers/DATA/contentInstances" resource using the following request:

POST 127.0.0.1:8080/om2m/gscl/applications/MY_SENSOR/containers/DATA/contentInstances/subscriptions

<?xml version="1.0" encoding="UTF-8"?>
<om2m:subscription xmlns:tns="http://uri.etsi.org/m2m" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >
<om2m:contact>nscl/applications/MONITOR/containers/NOTIFICATION/contentInstances</om2m:contact>
</om2m:subscription>

To check this, you can create a new contentInstance event on the GSCL on "MY_SENSOR/containers/DATA/contentInstances". The new event should be automatically forwarded to to the NSCL and stored on "MONITOR/containers/NOTIFICATION/contentInstances".


The ETSI M2M specification defines a third subscription/notification based for non-server-capable application based on the long polling mechanism (Not yet implemented in OM2M).

Don't hesitate to contact us if you have any question or remark.
Re: Subscriptions [message #1403941 is a reply to message #1396457] Mon, 28 July 2014 16:25 Go to previous messageGo to next message
Mahdi Ben Alaya is currently offline Mahdi Ben AlayaFriend
Messages: 229
Registered: November 2013
Senior Member
The source code of the monitor server and more details related to the Notify resource representation are now availables on the wiki:
https://wiki.eclipse.org/OM2M/REST_API#Subscribe_to_MY_SENSOR_data

[Updated on: Mon, 28 July 2014 16:25]

Report message to a moderator

Re: Subscriptions [message #1593363 is a reply to message #1403941] Fri, 30 January 2015 15:36 Go to previous messageGo to next message
dboy devzFriend
Messages: 7
Registered: November 2014
Junior Member
Hi, just wanted to get somethings clear.
The monitor server application described on the REST_API page
is a "server-capable application" right?
This does not appear in the resource tree, as it is not created on neither the NSCL nor on the GSCL.
The other type of application is the one you create on the NSCL in your response. Is this what you call scenario 2?
Re: Subscriptions [message #1597840 is a reply to message #1593363] Mon, 02 February 2015 15:46 Go to previous messageGo to next message
Mahdi Ben Alaya is currently offline Mahdi Ben AlayaFriend
Messages: 229
Registered: November 2013
Senior Member
Hello Daniel,

1) Yes, the monitor server application described on the REST_API page is a "server-capable application".
You can create an application resource for it if you want to use a specific requesting entity or to create some container sub resources.
We did not created an application resource for the monitor in the tutorial in order to make it simple.

2) Yes, the other type of application is created on the NSCL. A specific container of this applications is used as CotnactURI for the subscription.
And, this is what I called scenario 2 in my response.

Hope this can help.
Re: Subscriptions [message #1599904 is a reply to message #1597840] Tue, 03 February 2015 23:58 Go to previous messageGo to next message
dboy devzFriend
Messages: 7
Registered: November 2014
Junior Member
Hi, thanks for the response. It helped me.
Somethingelse!
Just wanted to say that i think something is wrong with the setState function in the Sensor class.
First the comment "Gets SensorState" and secondly the parameter passed to the function is not used.
This function is not used as I expected in the doRetrieve method of the IpuController class.
Could it be that the method should be called "getState" with the following signature " int getState(String appId) ", with the integer returned beeing Sensor.state?
Re: Subscriptions [message #1600706 is a reply to message #1599904] Wed, 04 February 2015 12:29 Go to previous messageGo to next message
Ghada Gharbi is currently offline Ghada GharbiFriend
Messages: 4
Registered: July 2014
Junior Member
Hello,

You are right. Indeed, the "setState" method of the Sensor class is not correct.
I made the following changes on the wiki:
- In Sensor class: the setState(String appId) method was removed and replaced with the getState() that returns a random value to simulate a sensor measurement. The appId parameter is useless here.
- In Lamp class: the appId parameter is also removed from the getState(String appId) method like this: boolean getState().
- In IpuControlor class: Now, in the doRetrieve() method we get the value of the sensor from Sensor.getState(), then it is converted to an oBIX represented.

Thank you,
Ghada

[Updated on: Wed, 04 February 2015 12:43]

Report message to a moderator

Re: Subscriptions [message #1700437 is a reply to message #1600706] Thu, 02 July 2015 14:50 Go to previous messageGo to next message
Mariem CH is currently offline Mariem CHFriend
Messages: 2
Registered: July 2015
Junior Member
Hello
How can i Create a new event content instance resource under the "DATA" container?
Re: Subscriptions [message #1701261 is a reply to message #1700437] Fri, 10 July 2015 10:26 Go to previous messageGo to next message
Mahdi Ben Alaya is currently offline Mahdi Ben AlayaFriend
Messages: 229
Registered: November 2013
Senior Member
Hello Mariem,

Please check the following tutorial http://wiki.eclipse.org/OM2M/REST_API section "Create a data contentInstance"



Re: Subscriptions [message #1702412 is a reply to message #1701261] Wed, 22 July 2015 08:31 Go to previous messageGo to next message
Mariem CH is currently offline Mariem CHFriend
Messages: 2
Registered: July 2015
Junior Member
Thank you Mahdi.
Re: Subscriptions [message #1703547 is a reply to message #1702412] Mon, 03 August 2015 00:27 Go to previous messageGo to next message
Mahdi Ben Alaya is currently offline Mahdi Ben AlayaFriend
Messages: 229
Registered: November 2013
Senior Member
You are welcome !
Re: Subscriptions [message #1737188 is a reply to message #1703547] Wed, 06 July 2016 09:50 Go to previous messageGo to next message
Trung Luu is currently offline Trung LuuFriend
Messages: 32
Registered: June 2016
Member
I try the scencario 2 on OM2M version for oneM2M, however, it return the 404 notfound in OSGi. Does anyone meet the same problem with me?
Re: Subscriptions [message #1737211 is a reply to message #1737188] Wed, 06 July 2016 12:50 Go to previous messageGo to next message
Mahdi Ben Alaya is currently offline Mahdi Ben AlayaFriend
Messages: 229
Registered: November 2013
Senior Member
Dear Trung,

Scenario 2 feature was provided only in OM2M 0.8 (SmartM2M-based) but not yet implemented in OM2M 1.0 (oneM2M-based).

Regards,
Mahdi
Re: Subscriptions [message #1737219 is a reply to message #1737211] Wed, 06 July 2016 13:02 Go to previous messageGo to next message
Trung Luu is currently offline Trung LuuFriend
Messages: 32
Registered: June 2016
Member
Dear Mahdi,

So if I want to build a Subscribe/notify scenario such as the actuator in IN-CSE send subscribe message to sensor in MN-CSE and sensor in MN-CSE notify sensor value back to actuator, Can I build it in Java? and how can I do that? Thanks for your support.

Best Regards,

Trung
Re: Subscriptions [message #1737311 is a reply to message #1737219] Thu, 07 July 2016 08:45 Go to previous messageGo to next message
Can LIU is currently offline Can LIUFriend
Messages: 29
Registered: May 2016
Junior Member
Hello mahdi,
I am doing the same thing as Trung, and i already write some lines of code. I pasted it below, i juste don't know how to give the notificationURI to this function? Could you help me and Trung for this?
Code in my RequestSender:
private RequestSender(){}

public static ResponsePrimitive createResource(String targetId, String name, Resource resource, int resourceType){
RequestPrimitive request = new RequestPrimitive();
request.setFrom(Constants.ADMIN_REQUESTING_ENTITY);
request.setTargetId(targetId);
request.setResourceType(BigInteger.valueOf(resourceType));
request.setRequestContentType(MimeMediaType.OBJ);
request.setReturnContentType(MimeMediaType.OBJ);
request.setContent(resource);
request.setName(name);
request.setOperation(Operation.CREATE);
return CSE.doRequest(request);
}

///////////////////request for subscription////////////////////
public static ResponsePrimitive createSubscription(String targetId, String name, Subscription resource){

return createResource(targetId, name, resource, ResourceType.SUBSCRIPTION);
}
//////////////////////////////////////////////////////////////

relative Code in my monitor():
public void createSensorResources(){
String targetId, content;

targetId = "/" + CSE_ID + "/" + CSE_NAME;
AE ae = new AE();
ae.setRequestReachability(true);
ae.setAppID(ipeId);
ae.getPointOfAccess().add(ipeId);
ResponsePrimitive response = RequestSender.createAE(ae, sensorId);

if(response.getResponseStatusCode().equals(ResponseStatusCode.CREATED)){
// Create the subscription for the monitor in IN
targetId = "/" + CSE_ID + "/" + CSE_NAME + "/" + sensorId + "/" + DATA;
ContentInstance sub = new ContentInstance();
sub.setContent(content);
sub.setContentInfo(MimeMediaType.OBIX);
RequestSender.createSubscription(targetId,); (here i don't know how to give the "nu"!!!!)

///////////////////////////////////////

Recording to my understand, create a subscription is just like to create a contentinstance in DATA container? but where should i give my value of "nu" to this function?

Thanks in advance.

Can

[Updated on: Thu, 07 July 2016 08:50]

Report message to a moderator

Re: Subscriptions [message #1737318 is a reply to message #1737311] Thu, 07 July 2016 09:35 Go to previous messageGo to next message
Trung Luu is currently offline Trung LuuFriend
Messages: 32
Registered: June 2016
Member
Dear Can LIU,
I think in monitor, you can replace ContentIntance sub = new ContentInstance(); by Subscription sub = new Subscription(); because OM2M supports this class.

Best Regards,
Trung
Re: Subscriptions [message #1737391 is a reply to message #1737318] Thu, 07 July 2016 17:29 Go to previous messageGo to next message
Mahdi Ben Alaya is currently offline Mahdi Ben AlayaFriend
Messages: 229
Registered: November 2013
Senior Member
Dear Can LIU,

Trung is right. You should use the resource type "Subscription".
By the way, you can find all resource types on the plugin "org.eclipse.om2m.commons" under the "resources" folder.

Example:
Subscription sub = new Subscription();
sub.getNotificationURI().add("http://192.168.0.10:1400/monitor");
sub.setNotificationContentType(BigInteger.valueOf(2));

You can also set your "AE resourceID" as NotificationURI in your Subscription (e.g. /cse-id/cse-name/ae-id) instead of setting a protocol-dependent URI.
Then, you have to set the protocol-dependent URI "http://192.168.0.10:1400/monitor" as PoA in your AE resource and so keep your subscription clean.
The event will be re targeted from CSE to another based on the AE resourceID, and the final CSE will check the hosted AE resource and notification the PoA.

Regards,
Mahdi

[Updated on: Thu, 07 July 2016 17:30]

Report message to a moderator

Re: Subscriptions [message #1737395 is a reply to message #1737391] Thu, 07 July 2016 18:09 Go to previous messageGo to next message
Mahdi Ben Alaya is currently offline Mahdi Ben AlayaFriend
Messages: 229
Registered: November 2013
Senior Member
@Trung

Your question is independent of oneM2M stantard and is related to pure HTTP client/server.

For HTTP server you can use "com.sun.net.httpserver"
Example:
http://www.rgagnon.com/javadetails/java-have-a-simple-http-server.html

For HTTP client you can the Apache library
Example:
https://hc.apache.org/httpcomponents-client-ga/quickstart.html

Hope this can help
Re: Subscriptions [message #1738068 is a reply to message #1737391] Fri, 15 July 2016 14:13 Go to previous message
Can LIU is currently offline Can LIUFriend
Messages: 29
Registered: May 2016
Junior Member
Hi Mahdi,
Thank you very much.
I changed my code like this:

targetId = "/" + CSE_ID + "/" + CSE_NAME + "/" + sensorId + "/"
					+ DATA;
			Subscription sub = new Subscription();
			sub.getNotificationURI().add("http://XX.XX.XX.223:1400/Monitor");
			sub.setNotificationContentType(BigInteger.valueOf(2));
			RequestSender.createSubscription(targetId,SUB,sub);

And in my requestsender:
public static ResponsePrimitive createSubscription(String targetId, String name, Subscription resource){
						
		return createResource(targetId, name, resource, ResourceType.SUBSCRIPTION);


There is no error shows up.

But i have another question. In fact, i download the source of Monitor.jar and i made it into a plugin in my IN side.
My question is How do i give the "nu" value if it is a plugin in IN?

Thanks in advance and have a good day!

Can
Previous Topic:Two general questions: Managing library dependencies and referencing local directories
Next Topic:OM2M on Android
Goto Forum:
  


Current Time: Sat Oct 12 15:59:49 GMT 2024

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

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

Back to the top