Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [leshan-dev] Registration Listener

...

Please consider using the Leshan API instead of using this kind of hack.

        // create a server
        LeshanServer server = new LeshanServerBuilder().build();
        server.start();

        // get current registered clients
        Collection<Client> allClients = server.getClientRegistry().allClients();

        // be notified of new registration
        server.getClientRegistry().addListener(new ClientRegistryListener() {
            public void updated(Client client) {
            }

            public void unregistered(Client client) {
            }

            public void registered(Client newClient) {
                System.out.println("New registration:" + newClient);
            }
        });

If you're limited by the current API please open an issue[1].

[1]https://github.com/eclipse/leshan/issues/new


Le 08/03/2016 16:59, Pablo Punal a écrit :
Hi,

You can add a Simple CoAP resource on Leshan and request periodically (also you can implement it with observe). 
Modify "leshan-server-cf/src/main/java/org/eclipse/leshan/server/californium/impl/RegisterResource.java” and add this:

@Override
    public void handleGET(CoapExchange exchange) {
        Request request = exchange.advanced().getRequest();
        Collection<Client> clients = registrationHandler.clientRegistry.allClients();
        ArrayList<JSONObject> clientsArray = new ArrayList<>();
        Client client;
        JSONObject json;
        for(int i=0; i<clients.size(); i++) {
            client = (Client)clients.toArray()[i];
            json = new JSONObject();
            json.put("endPoint", client.getEndpoint());
            json.put("registrationId", client.getRegistrationId());
            json.put("address", client.getAddress().toString());
            json.put("port", client.getPort());
            json.put("objectLinks", Arrays.toString(client.getObjectLinks()));
            clientsArray.add(json);
        }
        String resp = clientsArray.toString();
        exchange.respond(ResponseCode.CONTENT, resp, MediaTypeRegistry.APPLICATION_LINK_FORMAT);
    }

Now you can request to Leshan server for connected devices. In this example you will receive this:

[
  1. {
    • "endPoint":"mulle-216",
    • "address":"\/fdfd:0:0:0:0:0:0:1",
    • "objectLinks":"[<\/1\/1>, <\/1\/2>, <\/2\/0>, <\/3\/0>, <\/4\/0>, <\/3311\/0>, <\/3311\/1>]",
    • "port":5683,
    • "registrationId":"3KnmBsPJ8T"
    },
  2. {
    • "endPoint":"mulle-248",
    • "address":"\/fdfd:0:0:0:f95e:73b7:a8e7:eeb0",
    • "objectLinks":"[<\/1\/1>, <\/1\/2>, <\/2\/0>, <\/3\/0>, <\/4\/0>, <\/3311\/1>, <\/3311\/2>, <\/3311\/3>, <\/3311\/4>]",
    • "port":5683,
    • "registrationId":"YmDbZUBAph"
    }
]

I implement this on one SCADA system that you can look at: https://github.com/punyal/BlackHole

I hope this help you.


Pablo Puñal Pereira
pablo.punal@xxxxxx





-------- Forwarded Message --------
Subject: Re: [leshan-dev] Registration Listener
Date:  Tue, 8 Mar 2016 11:56:02 +0100
From:  Simon Bernard <contact@xxxxxxxxxxxxxxx>
Reply-To: leshan developer discussions <leshan-dev@xxxxxxxxxxx>
To:  leshan developer discussions <leshan-dev@xxxxxxxxxxx>


You should have a look at ClientRegistry[1] and ClientRegistryListener[2]

[1]https://github.com/eclipse/leshan/blob/master/leshan-server-core/src/main/java/org/eclipse/leshan/server/client/ClientRegistry.java
[2]https://github.com/eclipse/leshan/blob/master/leshan-server-core/src/main/java/org/eclipse/leshan/server/client/ClientRegistryListener.java

Le 08/03/2016 11:08, Subhash Nair p a écrit :
Hi ,

    I have an idea about using Leshan as Device management server .My Platform does not have a Device Management Capability and so  I am looking for a ways where I can keep Leshan as an external entity to which I can redirect the DM operations.

Whenever  LWM2M  clients are getting registered to the Leshan server  I am looking for a mechanism like where I would implement a Registration Listener in my platform ,   and Leshan will notify this Listener about the registered client and its capabilities.
    
   Such kind of Notification service is there currently.?

Thanks in advance for the advcie .


Regards
Subhash Nair


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



<Attached Message Part.txt>



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


Back to the top