Skip to content

Dynamic awake time for Queue mode

Simon edited this page Feb 8, 2023 · 4 revisions

⚠️ This is out of LWM2M specification and so you will lost interoperability ! ⚠️

In this page it is explained how to create a dynamic awake time provider, where the client awake time is not fixed since the beginning. The client specifies this time as an attribute in the update message. Leshan saves all the additional parameters that comes in the registration/update messages as a Map called additionalRegistrationAttributes.

The ClientAwakeTimeProvider API provides an interface that can be used to provide this dynamic provider. This API contains the method getClientAwakeTime(Registration reg) which takes a Registration object as a parameter, and returns the corresponding awake time for that client. Therefore, the additionalRegistrationAttributes can be taken from the Registration object, and the awake time attribute can be read, like:

clientAwakeTime = Integer.valueOf(reg.getAdditionalRegistrationAttributes().get("at"));

This additional attributes will be updated with the update messages (implemented in #481), and therefore the client can change the awake time dynamically.

Then, the class implementing this dynamic awake time provider will look like:

public class DynamicClientAwakeTimeProvider implements ClientAwakeTimeProvider {

    int clientAwakeTime;

    public DynamicClientAwakeTimeProvider() {
        this.clientAwakeTime = 93000;
    }

    public DynamicClientAwakeTimeProvider(int defaultClientAwakeTime) {
        this.clientAwakeTime = defaultClientAwakeTime;
    }

    @Override
    public int getClientAwakeTime(Registration reg) {
        if (reg.getAdditionalRegistrationAttributes().containsKey("at")) {

            this.clientAwakeTime = Integer.valueOf(reg.getAdditionalRegistrationAttributes().get("at"));
        }

        // Returns the last awake time that was included in the registration message. If no awake time was ever included
        // in this message, returns the default one.
        return this.clientAwakeTime;
    }

}

See also #1397-comment-1422371246 for more information about this.