Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

O & N #601

Closed
anuscool opened this issue Oct 25, 2018 · 24 comments
Closed

O & N #601

anuscool opened this issue Oct 25, 2018 · 24 comments
Labels
question Any question about leshan

Comments

@anuscool
Copy link

i want to set lt,gt,pmin,pmax and step value for different sensor.
is present leshan server code support this,if not,where i can change different value of(lt,gt,pmin,pmax and step value) for different sensor.

I need help where i can do changes for this requirement in leshan-server code.

@sbernard31
Copy link
Contributor

It seems you are talking about leshan-server API.

To set attributes (lt,gt,pmin,pmax ....), you just need to send a WriteAttributesRequest like explained in the LWM2M specification.

@sbernard31 sbernard31 added the question Any question about leshan label Oct 25, 2018
@anuscool
Copy link
Author

anuscool commented Oct 25, 2018

i was doing this by change in leshan-server code( commit id - 790fe57)

+ObserveSpec spec = new +ObserveSpec.Builder().greaterThan(16).lessThan(8).minPeriod(5).maxPeriod(10).step(3).build();
+WriteAttributesRequest write = new WriteAttributesRequest(target,spec);
+WriteAttributesResponse ocResponse = server.send(registration, write, TIMEOUT);

My changes are applicable for all objects and their resources....how i can set these parameter for specific object and their resources.

@sbernard31
Copy link
Contributor

I do not understand ...

There are severals constructor which allow to target object, object instance or resource ... This is not enough ?

Did you read the LWM2M specification about write attributes ?

@anuscool
Copy link
Author

anuscool commented Nov 1, 2018

I am trying to write-attributes for temperature sensor value using below command:
PUT
http://125.63.92.175:8080/api/clients/urn:imei:867290030016447/3303/0/5700?pmin=30&pmax=120&lt=20.0&gt=25.0&st=1.2
text/plain

I am using htp requester but i am getting error: Invalid request:Invalid value type for resource /3303/0/5700, expected FLOAT, got STRING

what could be the reason

@sbernard31
Copy link
Contributor

sbernard31 commented Nov 5, 2018

Finally, I understand you are not talking about leshan-server-cf API but about leshan-server-demo.

So, currently there is no REST API or UI for Write Attributes.

(see : #341 and LWM2M-Supported-features)

@anuscool
Copy link
Author

anuscool commented Nov 5, 2018

can we add write attribute support in doPut function of ClientServlet.java file.
can you help me out?

@sbernard31
Copy link
Contributor

You just want to add the REST API right ? (no UI ?)

So adding this is doPut could make sense.

You can look at the ClientServlet class to inspire yourself.

I propose to choose an URI like this :
clients/endPoint/LWRequest/attributes?attributeName=attributeValue&attributeName=attributeValue ...
or
clients/endPoint/LWRequest/attributes and put the value in the request body.

To deserialize write-attributes you can use AttributeSet.parse()

If you succeed, you can provide a PR :D !

@anuscool
Copy link
Author

anuscool commented Nov 5, 2018

yes i want to just add REST API so that i can change my sensor resources attributes through http.
i will try with you given approach and if it works i will sure raise a PR.

I am using tool http requester a firefox extension for sending PUT command for write attributes.
http://125.63.92.175:8080/api/clients/urn:imei:867290030016447/3303/0/5700?pmin=30&pmax=120&lt=20.0&gt=25.0&st=1.2

@sbernard31
Copy link
Contributor

@anuscool
Copy link
Author

anuscool commented Nov 8, 2018

Thanx for the approach,how i will use AttributeSet.parse() to copy query string parameter(pmin,pmax,lt,gt and st) to ObserveSpec spec then i will call
WriteAttributesRequest write = new WriteAttributesRequest(target,spec);
WriteAttributesResponse cResponse = server.send(registration, write, TIMEOUT);

@sbernard31
Copy link
Contributor

sbernard31 commented Nov 8, 2018

Which version are you using ?
ObserveSpec should be replaced by AttributeSet since leshan-1.0.0-M8. 🤔

@anuscool
Copy link
Author

anuscool commented Nov 8, 2018

i am using leshan master branch and i was hardcoding the value like below but how i will copy this parameter from write-attribute restapi to AttributeSet.

                AttributeSet attributes = null;
                List<String> uriQueries = {};
                attributes = AttributeSet.parse(uriQueries);
                WriteAttributesRequest write = new WriteAttributesRequest(target,attributes);
                WriteAttributesResponse cResponse = server.send(registration, write, TIMEOUT);

I am stuck in List uriQueries = {}; ,how i will use it to copy write-attributes(pmin,pmax,lt,gt and step)

@sbernard31
Copy link
Contributor

I suspect you want I write all the code for you 😛

Look at javax.servlet.http.HttpServletRequest.getQueryString()

(you can just pass a String to AttributeSet.parse)

@Redferne
Copy link

Redferne commented Nov 9, 2018

I suspect you want I write all the code for you

I would buy you a couple of beers if you did 😸 Also frantically looking for this Read/Write attributes feature using the REST API in Leshan Server Demo. It's one of the "small" missing pieces to get proper Resource Observations working as intended.

@anuscool
Copy link
Author

@sbernard31 Thanks for guiding, i am able to write-attributes using rest API,now i am testing it fully once it will complete i will raise a PR.

For customer demo purpose this is temporary solution for us,we want it through GUI,can you please guide me how i will proceed to write-attributes using leshan GUI.

@sbernard31
Copy link
Contributor

For customer demo purpose this is temporary solution for us,we want it through GUI,can you please guide me how i will proceed to write-attributes using leshan GUI.

Honestly, I don't know how it could looks like.

But if you want to look at the code all happened here :
UI templates for angular 1.2.x (very old version :/ the current version is 1.7.x)
leshan-server-demo/src/main/resources/webapp/partials/resource.html (template for resource)
leshan-server-demo/src/main/resources/webapp/partials/instance.html (template for instance)
leshan-server-demo/src/main/resources/webapp/partials/object.html (template for object)

directive/controller for this templates :
leshan-server-demo/src/main/resources/webapp/js/resource-directives.js
leshan-server-demo/src/main/resources/webapp/js/instances-directives.js
leshan-server-demo/src/main/resources/webapp/js/object-directives.js

It would not be as straightforward than implementing the REST API and angular 1.2 is a bit obsolete.

@anuscool
Copy link
Author

can we do write attribute from leshan GUI instance write tab,can we write attribute values using write tab for different sensor
temparature

@sbernard31
Copy link
Contributor

I do not understand.

@anuscool
Copy link
Author

i mean to say that,the figure i have attached of temperature sensor in which,can i use temperature instance 0 Write button to write-attributes of temperature sensor.

@sbernard31
Copy link
Contributor

Write button is use to do a write request at instance level.

You want to change it to use a "write attribute request` instead ?

In that case, you could have a look at leshan-server-demo/src/main/resources/webapp/js/instances-directives.js

look at this : https://github.com/eclipse/leshan/blob/master/leshan-server-demo/src/main/resources/webapp/js/instance-directives.js#L93

@anuscool
Copy link
Author

i want a separate write attribute button just like write and i want to copy all the code of "write" for write attributes then i want to change that code,for that i think i have to change the code for passing my attributes data(pmin,pmax,lt,gt and st) through this GUI because these attributes will go as string value but for normal write operation we pass id and its value.

can you help me out what changes required in normal "write" function to support write-attributes functionality through GUI.

@sbernard31
Copy link
Contributor

I already pointed you the file to look at. Just use it as example.

@anuscool
Copy link
Author

how i will use this line for writing attribute
$http({method: 'PUT', url: "api/clients/" + $routeParams.clientId + scope.resource.path, data: rsc, headers:{'Content-Type': 'application/json'},params:{format:format}})

i am trying with this

$http({method: 'PUT', url: "api/clients/" + $routeParams.clientId + scope.resource.path+"/attributes", data: pmin=1, headers:{'Content-Type': 'application/json'},params:{format:format}})

i need some guidance to run this.

@sbernard31
Copy link
Contributor

https://code.angularjs.org/1.2.7/docs/api/ng.$http

I proposed 2 ways : passing attributes as request payload/data or a url query parameters...
You choose to use url query parameters until now and here you are using payload/data.

@anuscool anuscool changed the title can we set different value (lt,gt,pmin,pmax and step value) for different object in case of observe O & N Dec 3, 2018
@anuscool anuscool closed this as completed Dec 3, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Any question about leshan
Projects
None yet
Development

No branches or pull requests

3 participants