Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [cf-dev] Send modified resource's values to observing client

Hi,

Thank you for your quick response. It's not likely I am trying to create a CoAP gateway. What I intend to do is to enable CoAP communication between my device client and Eclipse Kura (this will act as my gateway). However, because currently Kura doesn't support CoAP, I want to use Californium to do it. Therefore I am playing around with Californium to understand it before I can start implement Californium into Kura.

About your suggestion, yes, I did what you mentioned in the code below (for the CoAP server on the device client):

public static class HelloResource extends CoapResource {

        public HelloResource() {
            super("Ultrasonic");
            setObservable(true);
        }

        @Override
        public void handleGET(CoapExchange exchange) {
            exchange.respond("Replace with something else to take the data sent to this CoAP server in handlePUT");
        }
       
       
        @Override
        public void handlePUT(CoapExchange exchange) {
            String payload = exchange.getRequestText();
            System.out.println(payload + " cm");
           
            try {
                exchange.respond(CHANGED, payload);
                changed();
            } catch (Exception e) {
                e.printStackTrace();
                exchange.respond(BAD_REQUEST, "Invalid String");
            }
        }
    }

When I use Observe on Copper. it can recognize the change trigger of resources, but what it receives/output on the screen is the text I put in the handleGET in the code above. Copper can recognize each time the data of my ultrasonic is changed on the CoAP server, and ouput the line "Replace with something else" instead of the real data for each change trigger. So my question is that what do I need to put inside the exchange.respond() of the handleGET (on the CoAP server) , so the handleGET can take the data/payload sent to the CoAP server (by PUT method of the CoAP client on device client) in the handlePUT.

Best regards,
Thong Q. Nguyen

2017-07-24 10:56 GMT+02:00 Kraus Achim (INST/ECS4) <Achim.Kraus@xxxxxxxxxxxx>:

Hi,

 

I don't think, that this works "out of the box" (but maybe there are already examples I don't know).

CoAP is designed to be able to use “protocol unaware gateways”, there is no need to have a CoAP-Gateway.

So I don’t know, what your intention is.

 

Usually, the devices “CoAP Server” implementation is intended to provide a “CoapResource” implementation,

which reads/manages your sensor values reporting changes in the resource representation using “CoapResource.changed()”.

Doing so, a “CoAP Client” would be able to “observe” this resource, if the “CoAP server” is reachable with in your network

environment. Unfortunately, in the “usual internet infrastructure”, your “CoAP server” may be not easy to reach J.   

 

Anyway:

Did you implement a “CoapResource” for the CoAP Server on the First Raspi?

If so, does your “handlePUT” Implementation also calls "changed" (to trigger a notify)?

 

Mit freundlichen Grüßen / Best regards

Achim Kraus

(INST/ECS4)
Bosch Software Innovations GmbH | Stuttgarter Straße 130 | 71332 Waiblingen | GERMANY
| www.bosch-si.com

Sitz: Berlin, Registergericht: Amtsgericht Charlottenburg; HRB 148411 B
Aufsichtsratsvorsitzender: Dr.-Ing. Thorsten Lücke; Geschäftsführung: Dr.-Ing. Rainer Kallenbach, Michael Hahn



From: cf-dev-bounces@xxxxxxxxxxx [mailto:cf-dev-bounces@eclipse.org] On Behalf Of Thong Q. Nguyen
Sent: Montag, 24. Juli 2017 10:27
To: Californium (Cf) developer discussions <cf-dev@xxxxxxxxxxx>
Subject: Re: [cf-dev] Send modified resource's values to observing client

 

Hi,

Sorry for being unclear. I am new to Californium so I am still learning about it. About my scenario, basically, I have an ultrasonic installed on the raspi, and just like you said, that raspi acts as a "Device Client", which implements both CoAP Client and Coap Server. Currently, I am sending the data of the ultrasonic from the CoAP Client to the CoAP Server by PUT method every 2 seconds. Now, I want to observe that data changes on another raspi (which will later act as the gateway between the Device Client and the Cloud). So I thought that I would implement another CoAP client on the gateway raspi to be able to observe the data on the CoAP server of the Device Client. In other words, I just want to send the data continuously from the device client to the gateway. Copper is used just to test the Observe function before I implement the gateway. I also draw a simple diagram to illustrate my scenario in case my words are still not clear.


Thank you for your help.

Best regards,

Thong Q. Nguyen




 

 

2017-07-24 9:34 GMT+02:00 Kraus Achim (INST/ECS4) <Achim.Kraus@xxxxxxxxxxxx>:

Hi,

>Currently, I have implemented a californium client which takes the values from my ultrasonic sensor on a raspberry Pi and send them to my californium server every 2 seconds.

“server” and “client” are also CoAP roles and therefore I would recommend to “qualify” the terms:
- Device Client
- Cloud/Home/Intranet Server
- CoAP Client
- CoAP Server

One of the cool features of CoAP is, that a “Device Client” usually implements both “CoAP Client” and “CoAP Server”.

That ahead, I don’t understand your setup.

I would guess, the raspi is you “Device Client”, implementing both “CoAP Client” and “CoAP Server”.
Then your “? Server” acts as “CoAP Client” to establish a observe relation to the devices “CoAP Server”.
Or,you just “push” actively the data from your device using the “CoAP Client” using POST.

Now I want to use Copper to observe to that resource for the changed values.

Now I’m totally lost .

Maybe you want to transfer data from your device to the “? Server” and then observe this data in Copper?
To answer that, please provide more information about your setup. Which component in your setup acts in which CoAP role?

Mit freundlichen Grüßen / Best regards

Achim Kraus

(INST/ECS4)
Bosch Software Innovations GmbH | Stuttgarter Straße 130 | 71332 Waiblingen | GERMANY | http://www.bosch-si.com

Sitz: Berlin, Registergericht: Amtsgericht Charlottenburg; HRB 148411 B
Aufsichtsratsvorsitzender: Dr.-Ing. Thorsten Lücke; Geschäftsführung: Dr.-Ing. Rainer Kallenbach, Michael Hahn



From: cf-dev-bounces@xxxxxxxxxxx [mailto:cf-dev-bounces@eclipse.org] On Behalf Of Thong Q. Nguyen
Sent: Freitag, 21. Juli 2017 16:57
To: cf-dev@xxxxxxxxxxx
Subject: [cf-dev] Send modified resource's values to observing client


Hi,
I am trying out californium with my scenario. Currently, I have implemented a californium client which takes the values from my ultrasonic sensor on a raspberry Pi and send them to my californium server every 2 seconds. Now I want to use Copper to observe to that resource for the changed values. However, so far I don't know how to make handleGET respond to take the value sent to the server through handlePUT, because as I notice the observe method will subscribe to the resource and use GET to receive the changed values.
Here is the code on my server side:

public static class HelloResource extends CoapResource {

        public HelloResource() {
            super("Ultrasonic");
            setObservable(true);
        }

        @Override
        public void handleGET(CoapExchange exchange) {
            exchange.respond("Replace to make Copper see the changed values");
        }
       
       
        @Override
        public void handlePUT(CoapExchange exchange) {
            String payload = exchange.getRequestText();
            System.out.println(payload + " cm");
           
            try {
                exchange.respond(CHANGED, payload);
                changed();
            } catch (Exception e) {
                e.printStackTrace();
                exchange.respond(BAD_REQUEST, "Invalid String");
            }
        }
    }
Could someone provide any help ? Thank you in advance.
Best regards,
Thong Q. Nguyen

_______________________________________________
cf-dev mailing list
cf-dev@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/cf-dev

 


_______________________________________________
cf-dev mailing list
cf-dev@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/cf-dev


Back to the top