Home » Eclipse Projects » OM2M » Using CoAP based applications (Copper vs Erbium)
Using CoAP based applications (Copper vs Erbium) [message #1464204] |
Fri, 07 November 2014 09:43 |
Fesseha Tsegaye Messages: 10 Registered: October 2014 |
Junior Member |
|
|
Hey guys,
First of all much thanks for your hard work. OM2M is a great work.
I was trying to set up a test environment with a CoAP (Erbium) running sensor DA. The problem I have is, I can not successfully pass the Authentication (requestingEntity). While using Copper plugin as CoAP client, I can send a GET request like,
coap :// [2001:bbbb:dddd:0:2ff:ffff:ffff:ffff]<colon>5683/om2m/nscl?authorization=admin:admin
and it works fine. But with Erbium the same request would respond with error like,
osgi> Nov 06, 2014 6:16:45 PM org.eclipse.om2m.core.router.Router doRequest
INFORMATION: RequestIndication [method=RETRIEVE, base=, targetID=/nscl, representation=, requestingEntity=null, protocol=null]
Nov 06, 2014 6:16:45 PM org.eclipse.om2m.comm.coap.CoapMessageDeliverer service
INFORMATION: check point: requestIndication sent and waiting for responseConfirm
Nov 06, 2014 6:16:45 PM org.eclipse.om2m.comm.coap.CoapMessageDeliverer getCoapStatusCode
INFORMATION: The received code is STATUS_AUTHORIZATION_NOT_ADDED
Nov 06, 2014 6:16:45 PM org.eclipse.om2m.comm.coap.CoapMessageDeliverer service
INFORMATION: check point : The code is 4.01
Nov 06, 2014 6:16:45 PM org.eclipse.om2m.comm.coap.CoapMessageDeliverer service
INFORMATION: the responseConfirm: ResponseConfirm [statusCode=STATUS_AUTHORIZATION_NOT_ADDED, representation=<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<om2m:errorInfo xmlns:om2m="link" xmlns:xmime="link">
<om2m:statusCode>STATUS_AUTHORIZATION_NOT_ADDED</om2m:statusCode>
<om2m:additionalInfo>Requesting Entity should not be null</om2m:additionalInfo>
</om2m:errorInfo>
, resourceURI=null]
Nov 06, 2014 6:16:45 PM org.eclipse.om2m.comm.coap.CoapMessageDeliverer service
INFORMATION: CoAP Response parameters set
Nov 06, 2014 6:16:45 PM org.eclipse.om2m.comm.coap.CoapMessageDeliverer deliverRequest
INFORMATION: the response= ACK-4.01 MID=26068, Token=[], OptionSet=[], "<?xmlversion="1.0" ".. 22 bytes
Nov 06, 2014 6:16:45 PM org.eclipse.om2m.comm.coap.CoapMessageDeliverer deliverRequest
I know my question is more related to the CoAP client (CoAP header) but if you already have encountered the same problems please let me know.
regards,
Fesseha
|
|
| | | |
Re: Using CoAP based applications (Copper vs Erbium) [message #1516143 is a reply to message #1516129] |
Thu, 18 December 2014 17:39 |
Mahdi Ben Alaya Messages: 229 Registered: November 2013 |
Senior Member |
|
|
I think that returning the representation of the created resource is useless in constraint environment.
So I suggest you to go to "org.eclipse.om2m.comm.coap" plugin and update the "CoapServer.java".
Update the following code (line 242) :
if(responseConfirm.getRepresentation()!=null){
//filling in the fields of the Coap response
response.setPayload(responseConfirm.getRepresentation());
}
like this:
if(responseConfirm.getRepresentation()!=null){
//filling in the fields of the Coap response
if(statusCode != 2.01){
response.setPayload(responseConfirm.getRepresentation());
}
}
Tell me is this update meets your need.
If yes, I will push a patch to the git.
cheers
[Updated on: Thu, 18 December 2014 17:40] Report message to a moderator
|
|
| | | | | | | | | | |
Re: Using CoAP based applications (Copper vs Erbium) [message #1740691 is a reply to message #1464410] |
Wed, 17 August 2016 10:34 |
Son Duong Messages: 60 Registered: June 2016 |
Member |
|
|
Hi Mahdi,
I wonder that in OM2M version 1.0.0, how the authorization will be done. I tried to put the Query parameter: authorization=admin:admin to the request uri: coap://127.0.0.1:5683/~/in-cse/in-name?authorization=admin:admin, but the server responsed with an error 4.03 Unknown or unauthorized originator. Do you have any idea?
Thank you in advanced
Son
Mahdi Ben Alaya wrote on Fri, 07 November 2014 14:22Hello,
Ok, let's try to investigate this issue.
Technically, I think that all URI parameters goes in the "Uri-Query" option of the CoAP protocol.
So, try to add the option: "Uri-Query" with the value: "authorization=admin:admin" to your CoAP request (instead of adding it as a URI parameter) and let's see.
Mahdi
[Updated on: Wed, 17 August 2016 10:34] Report message to a moderator
|
|
|
Re: Using CoAP based applications (Copper vs Erbium) [message #1741005 is a reply to message #1740691] |
Mon, 22 August 2016 10:52 |
Klemen Petrovcic Messages: 34 Registered: November 2015 |
Member |
|
|
Hi Son Duong.
The OneM2M version of the OM2M platform uses the Californium library to implement the general protocol binding. For a better
understanding of the binding, you can take a look at the protocols specifications.
I've looked at the two popular CoAP clients: the Copper plugin and the libcoap CLI tool. Both of them are, at this time,
not suitable to be used with this binding, since they do not support multiple custom options (you can read about them in the mentioned specifications).
I built a simple CoAP client, using the Californium library, with the purpose of demonstrating its usage with the general
CoAP binding. The provided examples are analogous to the ones of the HTTP tutorial.
I'd also like to mention the changed usage of the name attribute. In previous releases of the platform,
there was a special field (X-M2M-NM in HTTP), which was used for specifying the name of the resource, which was to be created.
In the latest version, this field is replaced, by a suitable attribute ("rn" or "nm"). This change is also included in the provided client.
I changed the default platform CoAP port to 5683, in the config.ini file of the suitable CSE unit, since the plugin doesn't use
the TLS encryption yet. The attached "coapmonitor.jar" application uses the 5685 port instead (just as an example).
[Updated on: Mon, 22 August 2016 10:53] Report message to a moderator
|
|
|
Re: Using CoAP based applications (Copper vs Erbium) [message #1741030 is a reply to message #1741005] |
Mon, 22 August 2016 13:01 |
Son Duong Messages: 60 Registered: June 2016 |
Member |
|
|
Hi Klemen,
this is exactly what I am looking for, thank you very much!
Klemen Petrovcic wrote on Mon, 22 August 2016 10:52Hi Son Duong.
The OneM2M version of the OM2M platform uses the Californium library to implement the general protocol binding. For a better
understanding of the binding, you can take a look at the protocols specifications.
I've looked at the two popular CoAP clients: the Copper plugin and the libcoap CLI tool. Both of them are, at this time,
not suitable to be used with this binding, since they do not support multiple custom options (you can read about them in the mentioned specifications).
I built a simple CoAP client, using the Californium library, with the purpose of demonstrating its usage with the general
CoAP binding. The provided examples are analogous to the ones of the HTTP tutorial.
I'd also like to mention the changed usage of the name attribute. In previous releases of the platform,
there was a special field (X-M2M-NM in HTTP), which was used for specifying the name of the resource, which was to be created.
In the latest version, this field is replaced, by a suitable attribute ("rn" or "nm"). This change is also included in the provided client.
I changed the default platform CoAP port to 5683, in the config.ini file of the suitable CSE unit, since the plugin doesn't use
the TLS encryption yet. The attached "coapmonitor.jar" application uses the 5685 port instead (just as an example).
|
|
|
Re: Using CoAP based applications (Copper vs Erbium) [message #1741143 is a reply to message #1741030] |
Tue, 23 August 2016 10:41 |
Son Duong Messages: 60 Registered: June 2016 |
Member |
|
|
Hallo Klemen,
I tried your Coap client and it works fine, thank you once again. May I ask you another question? In the OM2M package, there is already a LAMP example (plugin number 30) and I would like to switch on the lamp using Coap request. Based on your Coap client example, I created another request function, called: returnCreatePostRequestString() which is used to create the POST request to switch on the LAMP, and I post this request to the address: coap://127.0.0.1:5683/~/mn-cse/mn-name/LAMP_0?op=setOn&lampid=LAMP_0.
Here is my returnCreatePostRequestString() function to create the POST request:
public static Request returnCreatePostRequestString() {
// TODO Auto-generated method stub
// Used to POST something
Request createSrc = new Request(Code.POST);
byte[] b10 = new byte[8];
new Random().nextBytes(b10);
createSrc.setToken(b10);
createSrc.getOptions()
.setContentFormat(MediaTypeRegistry.APPLICATION_XML)
.setAccept(MediaTypeRegistry.APPLICATION_XML)
.addOption(new Option(256, "admin:admin"));
return createSrc;
}
In the request I just added the option authorization admin:admin, and it works fine with HTTP (tested using Simple REST Client) but unfortunatelly not for the CoAP, the Coap response show Error Code 4.00. It stacked with this Error Log:
[2016-08-23 12:40:44,580 INFO] - org.eclipse.om2m.core.router.Router
Received request in Router: RequestPrimitive [operation=5,
to=/mn-cse/mn-name/LAMP_0,
from=admin:admin,
returnContentType=application/xml,
requestContentType=application/xml,
queryStrings={}]
[2016-08-23 12:40:44,581 INFO] - org.eclipse.om2m.core.router.Router
Request handling in the current CSE: /mn-cse/mn-name/LAMP_0
[2016-08-23 12:40:44,582 INFO] - org.eclipse.om2m.core.redirector.Redirector
Sending notification to IPE: sample
May you help me where did I do wrong?
Thank you very much
Son
|
|
| | |
Re: Using CoAP based applications (Copper vs Erbium) [message #1741634 is a reply to message #1741005] |
Fri, 26 August 2016 13:25 |
Son Duong Messages: 60 Registered: June 2016 |
Member |
|
|
hi Klemen,
I have another question about the CoAP Monitor server.
I tried to run the CoAP monitor jar file under port 5685. And I created a subscription container in my AE which set the notification uri (nu) as coap://127.0.0.1:5685/monitor. However when I run the plugin, it was not able to create the subscription container and it show the 5001 error:
[2016-08-26 15:17:03,149 INFO] - org.eclipse.om2m.core.router.Router
ResourceController to be used [SubscriptionController]
[2016-08-26 15:17:03,164 INFO] - org.eclipse.om2m.core.notifier.Notifier
Sending notify request to: coap://127.0.0.1:5685/monitor
[2016-08-26 15:17:03,164 INFO] - org.eclipse.om2m.core.comm.RestClient
the requestIndication RC: RequestPrimitive [operation=5,
to=coap://127.0.0.1:5685/monitor,
from=/mn-cse,
content=<?xml version="1.0" encoding="UTF-8"?>
<m2m:sgn xmlns:m2m="http://www.onem2m.org/xml/protocols">
<vrq>true</vrq>
<sud>false</sud>
</m2m:sgn>
,
returnContentType=application/xml,
requestContentType=application/xml,
]
[2016-08-26 15:17:03,164 INFO] - org.eclipse.om2m.core.router.Router
OM2M exception caught in Router: No RestClient service found for protocol: coap
[2016-08-26 15:17:03,164 INFO] - org.eclipse.om2m.core.router.Router
Response in Router= ResponsePrimitive [responseStatusCode=5001,
content=No RestClient service found for protocol: coap,
to=admin:admin,
from=/mn-cse,
contentType=text/plain,
]
I think the problem because it can not find the coap binding in the RestClient class.
Do you have any idea how to fix this problem. Did the coap monitor server work in your system?
Thank you
Son
|
|
| | | | | | | | | |
Goto Forum:
Current Time: Sat Dec 07 12:31:19 GMT 2024
Powered by FUDForum. Page generated in 0.06774 seconds
|