Skip to content

LwM2M Execute Operation Has No Effect

DodaTech Updated 2026-06-26 1 min read

In this tutorial, you'll learn about LwM2M Execute Operation Has No Effect. We cover key concepts, practical examples, and best practices.

The Problem

LwM2M Execute (E) operation on a resource returns success but nothing happens.

Quick Fix

Wrong

// Execute handler returns success but does nothing
static int exec_handler(anjay_t *anjay, const anjay_dm_object_def_t *obj,
                        anjay_iid_t iid, anjay_rid_t rid,
                        anjay_execute_ctx_t *ctx) {
  return 0;  // No action taken
}```

Server receives 2.04 Changed but device does not reboot/action.


### Right

```cpp
#include <anjay/anjay.h>
#include <anjay/dm.h>

static bool pending_reboot = false;

static int reboot_exec(anjay_t *anjay, const anjay_dm_object_def_t *obj,
                       anjay_iid_t iid, anjay_rid_t rid,
                       anjay_execute_ctx_t *ctx) {
  // Action taken here
  pending_reboot = true;

  // Parse any arguments from the execute
  int buf[16];
  size_t len = anjay_execute_get_args(ctx, buf, sizeof(buf));

  Serial.print("Reboot execute received. Args length: ");
  Serial.println(len);

  return 0;  // Success — server sees 2.04
}

void loop() {
  anjay_sched_run(anjay);

  if (pending_reboot) {
    delay(100);
    ESP.restart();  // Actual action
  }
}```

Server receives 2.04 Changed. Device reboots after 100ms delay.


## Prevention

LwM2M Execute is used for actions (reboot, factory reset, <a href="/embedded-systems/firmware-updates/">firmware update</a>). The resource must have the E (Execute) operation bit set. The handler parses optional arguments from the CoAP payload. Execute always returns 2.04 Changed on success. Actual action may be deferred — the handler should not block for long operations.

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">### What resources support Execute?</summary><div style="padding:14px 18px;color:#475569;line-height:1.7;background:#fff"><p>Common: Device/Reboot (3/0/4), <a href="/embedded-systems/firmware-updates/">Firmware Update</a>/Update (5/0/0), Device/Factory Reset (3/0/5). Custom resources can also support Execute.</p>
<h3 id="can-execute-pass-arguments">Can Execute pass arguments?</h3><p>Yes. The CoAP POST payload carries arguments. Common: <a href="/embedded-systems/firmware-updates/">firmware update</a> URI, factory reset PIN code.</p>
<h3 id="what-is-asynchronous-execute">What is asynchronous Execute?</h3><p>Execute triggers a long-running action. The client responds 2.04 immediately, performs the action, then sends a notification when complete. Prevents timeout.</p>
</div></details>

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro