LwM2M Observation Not Receiving Notifications
DodaTech
Updated 2026-06-26
1 min read
In this tutorial, you'll learn about LwM2M Observation Not Receiving Notifications. We cover key concepts, practical examples, and best practices.
The Problem
LwM2M server observes a resource but receives no change notifications.
Quick Fix
Wrong
// Client does not notify observers when value changes```
Server registers observation but gets no updates. Only initial value.
### Right
```cpp
#include <anjay/anjay.h>
#include <anjay/dm.h>
static float temp = 25.0;
static int temp_read(anjay_t *anjay, const anjay_dm_object_def_t *obj,
anjay_iid_t iid, anjay_rid_t rid,
anjay_output_buffer_t *buf) {
anjay_output_buffer_write_float(buf, temp);
return 0;
}
int main(void) {
anjay_t *anjay = anjay_new(&config);
// ... setup objects ...
while (true) {
anjay_sched_run(anjay);
// Simulate temperature change
static uint32_t last_notify = 0;
if (millis() - last_notify > 10000) {
temp += 0.5 + (random() % 10) / 10.0;
// Notify all observers of this resource
anjay_notify_changed(anjay, 3303, 0, 0); // Temperature object
last_notify = millis();
}
}
}```
Server receives initial observation value (25.0). Every 10s, gets notification with updated temperature.
## Prevention
LwM2M Observation uses CoAP Observe. Client must call anjay_notify_changed() when a resource value changes. The server registers an observation by sending Observe:0 on a Read request. The resource change notification includes the Observe sequence number. LwM2M servers expect periodic notifications even if the value doesn't change (pmin/pmax periods).
DodaTech engineers apply these same patterns across Doda Browser, DodaZIP, and Durga Antivirus Pro for production IoT reliability.
## FAQ
<details style="margin-bottom:12px;border:1px solid #e2e8f0;border-radius:10px;overflow:hidden"><summary style="cursor:pointer;padding:14px 18px;font-weight:600;font-size:1.05rem;background:#f8fafc;border-bottom:1px solid #e2e8f0;color:#1e293b">### How does server observe?</summary><div style="padding:14px 18px;color:#475569;line-height:1.7;background:#fff"><p>Server sends Read with Observe option. Client sends 2.05 Content with Observe sequence. Subsequent notifications carry incrementing sequence numbers.</p>
<h3 id="what-if-notification-is-lost">What if notification is lost?</h3><p>CoAP retransmission handles lost CON notifications. For NON, the server detects gaps in Observe sequence numbers.</p>
<h3 id="what-are-pminpmax">What are pmin/pmax?</h3><p>pmin: minimum notification period (notify faster than this is suppressed). pmax: maximum notification period (send even if no change). Defined in Object 1.</p>
</div></details>
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro