Skip to content

LwM2M Server Write Not Updating Resource

DodaTech Updated 2026-06-26 1 min read

In this tutorial, you'll learn about LwM2M Server Write Not Updating Resource. We cover key concepts, practical examples, and best practices.

The Problem

LwM2M server writes a value to a client resource but the value does not change.

Quick Fix

Wrong

// Write handler returns success but does not apply value
Server reports success but resource value remains unchanged.
# Anjay write handler
#include <anjay/anjay.h>

static int write_unit(
  anjay_t *anjay, const anjay_rid_t *rid,
  anjay_input_ctx_t *ctx) {
  
  char buf[32];
  size_t len = sizeof(buf);
  
  if (anjay_get_string(ctx, buf, &len)) {
    return ANJY_ERR_BAD_REQUEST;  # 4.00
  }
  
  // Validate
  if (strcmp(buf, 'C') != 0 && strcmp(buf, 'F') != 0) {
    return ANJY_ERR_BAD_REQUEST;  # Invalid unit
  }
  
  // Apply the new value
  strncpy(current_unit, buf, sizeof(current_unit));
  
  return 0;  # Success  server gets 2.04 Changed
}

# Resource must have 'W' in operations
# 'operations': 'RW'  or 'operations': 'W'
Server writes "C" to unit resource. Client reports success and applies the change.

Prevention

Resources must have 'W' (Write) in their operations mask. The write handler must parse the input, validate, apply the change, and return 0. Partial updates are supported — only specified resources in the object instance are written. Multiple-instance objects can have individual instances written.

DodaTech engineers apply these same patterns across Doda Browser, DodaZIP, and Durga Antivirus Pro for production IoT reliability.

FAQ

### What response does the server get on successful write?

CoAP 2.04 Changed. The server updates its cache with the new value.

Can the server write to multiple resources at once?

Yes. Write to an object instance writes all resources sent in the payload. Resources not included are unchanged.

What is the difference between Write and Write Attributes?

Write updates resource values. Write Attributes (LwM2M 1.0) sets observation parameters (pmin, pmax, gt, lt).

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro