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,

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


Back to the top