Function anjay_lwm2m_gateway_resource_observation_status

Function Documentation

anjay_resource_observation_status_t anjay_lwm2m_gateway_resource_observation_status(anjay_t *anjay, anjay_iid_t end_dev, anjay_oid_t oid, anjay_iid_t iid, anjay_rid_t rid)

Gets information whether and how a given Resource is observed. See anjay_resource_observation_status_t for details.

NOTE: This API is a companion to anjay_notify_changed. There is no analogous API that would be a companion to anjay_notify_instances_changed. Any changes to set of instances of any LwM2M Object MUST be considered observed at all times and notified as soon as possible.

NOTE: This function may be used to implement notifications for Resources that require active polling by the client application. A naive implementation could look more or less like this (pseudocode):

status = anjay_resource_observation_status(anjay, oid, iid, rid);
if (status.is_observed
        && current_time >= last_check_time + status.min_period) {
    new_value = read_resource_value();
    if (new_value != old_value) {
        anjay_notify_changed(anjay, oid, iid, rid);
    }
    last_check_time = current_time;
}

However, please note that such implementation may not be strictly conformant to the LwM2M specification. The timeline below shows a state change between resource reads:

[time] --|--------|-*------|-->     | - intervals between resource reads
         |<------>|                 * - point in time when underlying state
         min_period                     actually changes

the specification would require the notification to be sent exactly at the time of the (*) event, but with this naive implementation, will be delayed until the next (|).

Parameters:
  • anjay – Anjay object to operate on.

  • end_dev – End Device Instance ID.

  • oid – Object ID of the Resource to check.

  • iid – Object Instance ID of the Resource to check.

  • rid – Resource ID of the Resource to check.

Returns:

Observation status of a given Resource. If the arguments do not specify a valid Resource path, data equivalent to a non-observed Resource will be returned.