Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [leshan-dev] Firmware updates using LWM2M / Leshan

Harish,

The best way to change the firmware update indicator using the Leshan Client is to change the /5/0/3 (Firmware Update Object, State Resource) resource's value to 2 and then do a notifyResourceUpdated() on that resource.  The use of this is twofold:  if the server reads on that resource, it will get the 'Downloading' value.  If the server has initiated an observation on that resource, a notify will be sent back up.

An example of this can be seen in the IntegerValueResource inner class of the LeshanClientExample (in particular the setValue() method and the 'value' member).

I hope that helps!

-JF

On Wed, Feb 11, 2015 at 5:01 AM, Hothi Harish Amarshibhai 13MCS1021 <hothi.harish2013@xxxxxxxxx> wrote:
Hi,
    In is there any way to update resource from client side? 
    In firmware update wok-flow when client start downloading package. firmware update objects /5/0/4 resource should change to 2(downloading). How to make leshanclient to change this value in its object model?

On Mon, Feb 9, 2015 at 2:53 PM, Manu Sangoi <manu.sangoi.dev@xxxxxxxxx> wrote:
Hello, 

Here is an example of firmware object to handle the update flow: 

Thanks.
Manu

public class FirmwareUpdateObject {

        PackageUriResource packageUriRsc = new PackageUriResource();
        UpdateResource updateRsc = new UpdateResource();
        StateResource stateRsc = new StateResource();
        UpdateResultResource updateResultRsc = new UpdateResultResource();

        class PackageUriResource extends StringLwM2mResource {

            @Override
            protected void handleWrite(StringLwM2mExchange exchange) {
                LOG.info("Starting to download the firmware package from {}", exchange.getRequestPayload());
                exchange.respondSuccess();
                stateRsc.state = 2;

                HttpClient client = new HttpClient();
                HttpMethod get = new GetMethod(exchange.getRequestPayload());

                byte[] payload = null;
                try {
                    client.executeMethod(get);
                    payload = get.getResponseBody();

                    if (get.getStatusCode() == 200 && payload.length > 0) {
                        // downloaded
                        stateRsc.state = 3;
                        // TODO store the package
                    } else {
                        LOG.error("Invalid package file");
                        updateResultRsc.result = 5; // error result
                    }

                } catch (Exception e) {
                    LOG.error("Could not download the firmware package", e);
                }
            }
        }

        class UpdateResource extends StringLwM2mResource {

            @Override
            protected void handleExecute(LwM2mExchange exchange) {
                LOG.info("Updating the firmware");
                exchange.respond(ExecuteResponse.success());

                updateResultRsc.result = 0;

                try {
                    // TODO perform upgrade
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    //
                }

                updateResultRsc.result = 1;
                stateRsc.state = 1;
            }
        }

        class StateResource extends IntegerLwM2mResource {

            Integer state = 1;

            @Override
            protected void handleRead(final IntegerLwM2mExchange exchange) {
                exchange.respondContent(state);
            }
        }

        class UpdateResultResource extends IntegerLwM2mResource {

            Integer result = 0;

            @Override
            protected void handleRead(final IntegerLwM2mExchange exchange) {
                exchange.respondContent(result);
            }
        }

    }

2015-02-08 19:19 GMT+01:00 Julien Vermillard <jvermillard@xxxxxxxxx>:
Hi,
How the firmware update should work with LWM2M:

The server write update package the /5/0/1 URI.
So the device start download the package pointed by the URI and update the /5/0/3 from value 1 (Idle) to 2 (Downloading)
and 3 (Downloaded) when the package is ready to install.

The server should then (after reading /5/0/3 and seeing he download was sucessfull) start the update by sending the execute on /5/0/2.
After that the server should monitor the /5/0/5 and wait for a final result.

Maybe Manu you have an example of a firmware update using the java client?
HTH
Julien

On Sat Feb 07 2015 at 12:27:59 Davy De Waele <ddewaele@xxxxxxxxx> wrote:
Hi,

I've got a basic client / server up and running using Leshan and can read write basic values and execute standalone operations (ex: rebooting a device).

What I would like to do now is the following : Update the firmware of a device that is running the lwm2m client (java based leshan client) 

Am i correct in saying that I need to do the following :

  • Set a correct value for Package URI (/5/0/1), representing a URI that will be used by the client during the firmware update. (ex: a URL where the firmware is located)
  • Execute the actual firmware update (/5/0/2). The LWM2M client needs to read the Package URI to download the new firmware and do what it needs to do to install the new firmware on the device.

I was looking at the LeshanClientExample (https://github.com/jvermillard/leshan/blob/master/leshan-client-example/src/main/java/org/eclipse/leshan/client/example/LeshanClientExample.java) and I can intercept the firmware update action using an ExecutableResource.

From within the ExecutableResource (/5/0/2) handleExecute method, I suppose I need to retrieve the Package URI ? Does Leshan provide a way to read that resource, do I need to execute a Coap call myself ? 

Are there some code samples out there that show how to do this ?

Thanks.



_______________________________________________
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

_______________________________________________
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



_______________________________________________
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




--
Thanks and Regards,
Harish Hothi,
VIT University,
(8050811460).

_______________________________________________
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