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,

>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@xxxxxxxxxxx] 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

Back to the top