Object / Resource Model

LWM2M data model with typed resources and callback-driven access.

This module defines the core LWM2M data model used throughout the wb-idf-lwm2m component:

  • Object definitions (wb_lwm2m_object_def_t) — Top-level container with an Object ID, human-readable name, instance list, and resource list.
  • Resource definitions (wb_lwm2m_resource_def_t) — Per-resource metadata including data type, allowed operations (R/W/E), and user callbacks.
  • Value type (wb_lwm2m_value_t) — Tagged union supporting all 10 LWM2M data types (String, Integer, UInteger, Float, Boolean, Opaque, Time, Objlink, CoreLnk, None).
  • Callback types — wb_lwm2m_read_cb_t, wb_lwm2m_write_cb_t, wb_lwm2m_execute_cb_t for server-initiated operations.
  • Helper macros — WB_LWM2M_VALUE_STRING(), WB_LWM2M_VALUE_INT(), etc. for convenient value construction.
  • Accessor functions — wb_lwm2m_value_get_int(), wb_lwm2m_value_get_float(), wb_lwm2m_type_name() for type-safe access.

Object Tree Structure

LWM2M uses a three-level addressing scheme:

*   /ObjectID/InstanceID/ResourceID
*   Example: /3/0/0 → Device Object, Instance 0, Manufacturer
* 

Resource Data Types (OMA LWM2M Core Spec §C.1)

Type Enum Macro Size
String WB_LWM2M_RES_TYPE_STRING WB_LWM2M_VALUE_STRING(s) 0..N bytes UTF-8
Integer WB_LWM2M_RES_TYPE_INTEGER WB_LWM2M_VALUE_INT(v) 1/2/4/8 bytes signed
UInteger WB_LWM2M_RES_TYPE_UINTEGER WB_LWM2M_VALUE_UINT(v) 1/2/4/8 bytes unsigned
Float WB_LWM2M_RES_TYPE_FLOAT WB_LWM2M_VALUE_FLOAT(v) 4/8 bytes IEEE 754
Boolean WB_LWM2M_RES_TYPE_BOOLEAN WB_LWM2M_VALUE_BOOL(v) 1 byte
Opaque WB_LWM2M_RES_TYPE_OPAQUE WB_LWM2M_VALUE_OPAQUE(d,l) 0..N bytes binary
Time WB_LWM2M_RES_TYPE_TIME WB_LWM2M_VALUE_TIME(t) 4/8 bytes Unix epoch
Objlink WB_LWM2M_RES_TYPE_OBJLINK WB_LWM2M_VALUE_OBJLINK(o,i) 4 bytes
CoreLnk WB_LWM2M_RES_TYPE_CORELNK WB_LWM2M_VALUE_CORELNK(s) RFC 6690 string
None WB_LWM2M_RES_TYPE_NONE — Execute-only

Resource Operations

Bitmask Meaning
WB_LWM2M_OP_READ Server can read this resource
WB_LWM2M_OP_WRITE Server can write this resource
WB_LWM2M_OP_EXECUTE Server can execute this resource
WB_LWM2M_OP_RW Shorthand for READ + WRITE

Example: Custom Temperature Object (IPSO 3303)

static esp_err_t temp_read(uint16_t obj_id, uint16_t inst_id, uint16_t res_id,
                           wb_lwm2m_value_t *value, void *user_ctx) {
    if (res_id == 5700) {
        *value = WB_LWM2M_VALUE_FLOAT(23.5);
        return ESP_OK;
    }
    return ESP_ERR_NOT_FOUND;
}

static const wb_lwm2m_object_def_t temp_obj = {
    .id = 3303,
    .name = "Temperature",
    .instances = {{ .id = 0 }},
    .instance_count = 1,
    .resources = {
        { .id = 5700, .type = WB_LWM2M_RES_TYPE_FLOAT,
          .operations = WB_LWM2M_OP_READ, .read_cb = temp_read },
    },
    .resource_count = 1,
};

Data Structures

wb_lwm2m_instance_t

LWM2M Object Instance.

Simple struct holding the instance ID. An object may have up to WB_LWM2M_MAX_INSTANCES instances.

Field Type Description
id uint16_t Instance ID (e.g. 0)

wb_lwm2m_object_def_t

Complete LWM2M Object Definition.

Top-level structure that fully describes an LWM2M object including its ID, instances, and all resource definitions with their callbacks. Pass to wb_lwm2m_add_object() to register with the client.

Note: The object definition is referenced (not copied) by the client, so it must remain valid for the lifetime of the client.

Field Type Description
id uint16_t Object ID (e.g. 3 for Device)
instance_count size_t Number of instances.
instances[4] wb_lwm2m_instance_t Object instances.
multiple_instances bool true if object supports multiple instances
name const char * Human-readable name (optional)
resource_count size_t Number of resources.
resources[24] wb_lwm2m_resource_def_t Resource definitions.
user_ctx void * User context passed to callbacks.

wb_lwm2m_resource_def_t

Single resource definition within an LWM2M object.

Each resource has an ID, data type, allowed operations, and optional callbacks for server-initiated read/write/execute.

Field Type Description
execute_cb wb_lwm2m_execute_cb_t Execute callback (if OP_EXECUTE)
id uint16_t Resource ID.
mandatory bool Required by the object spec?
multiple bool true if this is a multi-instance resource
operations uint8_t Bitmask of WB_LWM2M_OP_*.
read_cb wb_lwm2m_read_cb_t Read callback (if OP_READ)
type wb_lwm2m_res_type_t Data type.
write_cb wb_lwm2m_write_cb_t Write callback (if OP_WRITE)

wb_lwm2m_value_t

Tagged union representing any LWM2M resource value.

Use the helper macros (WB_LWM2M_VALUE_STRING, WB_LWM2M_VALUE_INT, etc.) to construct values. Use wb_lwm2m_value_get_int() / wb_lwm2m_value_get_float() for type-safe reading with automatic conversions.

Field Type Description
bool_val bool WB_LWM2M_RES_TYPE_BOOLEAN.
float_val double WB_LWM2M_RES_TYPE_FLOAT.
int_val int64_t WB_LWM2M_RES_TYPE_INTEGER.
objlink_val struct WB_LWM2M_RES_TYPE_OBJLINK.
objlink_val.inst_id uint16_t
objlink_val.obj_id uint16_t
opaque_val struct WB_LWM2M_RES_TYPE_OPAQUE.
opaque_val.data const uint8_t *
opaque_val.len size_t
str_val struct WB_LWM2M_RES_TYPE_STRING / WB_LWM2M_RES_TYPE_CORELNK.
str_val.len size_t
str_val.str const char *
time_val int64_t WB_LWM2M_RES_TYPE_TIME (seconds since 1970-01-01T00:00Z)
uint_val uint64_t WB_LWM2M_RES_TYPE_UINTEGER.
type wb_lwm2m_res_type_t

Type Definitions

wb_lwm2m_read_cb_t

typedef esp_err_t(* wb_lwm2m_read_cb_t) (uint16_t obj_id, uint16_t inst_id, uint16_t res_id, wb_lwm2m_value_t *value, void *user_ctx)

Read callback — invoked when a resource value is needed.

wb_lwm2m_write_cb_t

typedef esp_err_t(* wb_lwm2m_write_cb_t) (uint16_t obj_id, uint16_t inst_id, uint16_t res_id, const wb_lwm2m_value_t *value, void *user_ctx)

Write callback — invoked when the server writes a resource.

wb_lwm2m_execute_cb_t

typedef esp_err_t(* wb_lwm2m_execute_cb_t) (uint16_t obj_id, uint16_t inst_id, uint16_t res_id, const uint8_t *args, size_t args_len, void *user_ctx)

Execute callback — invoked when the server executes a resource.

Enumerations

wb_lwm2m_fw_state_t

Firmware Update States (/5/0/3)

Enumerator Value Description
WB_LWM2M_FW_STATE_IDLE 0
WB_LWM2M_FW_STATE_DOWNLOADING 1
WB_LWM2M_FW_STATE_DOWNLOADED 2
WB_LWM2M_FW_STATE_UPDATING 3

wb_lwm2m_fw_update_result_t

Firmware Update Result Codes (/5/0/5)

Enumerator Value Description
WB_LWM2M_FW_RESULT_DEFAULT 0
WB_LWM2M_FW_RESULT_SUCCESS 1
WB_LWM2M_FW_RESULT_NOT_ENOUGH_FLASH 2
WB_LWM2M_FW_RESULT_OUT_OF_RAM 3
WB_LWM2M_FW_RESULT_CONN_LOST 4
WB_LWM2M_FW_RESULT_INTEGRITY_FAILED 5
WB_LWM2M_FW_RESULT_UNSUPPORTED_PKG 6
WB_LWM2M_FW_RESULT_INVALID_URI 7
WB_LWM2M_FW_RESULT_UPDATE_FAILED 8
WB_LWM2M_FW_RESULT_UNSUPPORTED_PROTOCOL 9

wb_lwm2m_res_type_t

LWM2M Resource Data Type enumeration.

Enumerator Value Description
WB_LWM2M_RES_TYPE_NONE 0 Execute-only resource (no data)
WB_LWM2M_RES_TYPE_STRING 1 UTF-8 string, 0..65535 bytes.
WB_LWM2M_RES_TYPE_INTEGER 2 Signed integer: 8/16/32/64-bit.
WB_LWM2M_RES_TYPE_UINTEGER 3 Unsigned integer: 8/16/32/64-bit (LWM2M 1.1+)
WB_LWM2M_RES_TYPE_FLOAT 4 IEEE 754 float: 32-bit or 64-bit.
WB_LWM2M_RES_TYPE_BOOLEAN 5 Boolean: 0 or 1.
WB_LWM2M_RES_TYPE_OPAQUE 6 Opaque binary data, 0..65535 bytes.
WB_LWM2M_RES_TYPE_TIME 7 Unix timestamp (signed 32/64-bit integer)
WB_LWM2M_RES_TYPE_OBJLINK 8 Object Link: ObjectID:InstanceID.
WB_LWM2M_RES_TYPE_CORELNK 9 CoRE Link-Format string (RFC 6690)

wb_lwm2m_security_mode_t

LWM2M Security Modes (Security Object /0, Resource /0/0/2)

Enumerator Value Description
WB_LWM2M_SEC_MODE_PSK 0 Pre-Shared Key.
WB_LWM2M_SEC_MODE_RAW_PUB_KEY 1 Raw Public Key.
WB_LWM2M_SEC_MODE_CERTIFICATE 2 Certificate.
WB_LWM2M_SEC_MODE_NOSEC 3 NoSec (plain CoAP)
WB_LWM2M_SEC_MODE_CERT_EST 4 Certificate with EST.

Macros

WB_LWM2M_OBJ_SECURITY 0

WB_LWM2M_OBJ_SERVER 1

WB_LWM2M_OBJ_ACCESS_CONTROL 2

WB_LWM2M_OBJ_DEVICE 3

WB_LWM2M_OBJ_CONN_MONITORING 4

WB_LWM2M_OBJ_FIRMWARE_UPDATE 5

WB_LWM2M_OBJ_LOCATION 6

WB_LWM2M_OBJ_CONN_STATISTICS 7

WB_LWM2M_RES_SEC_SERVER_URI 0

String — LWM2M Server URI.

WB_LWM2M_RES_SEC_BOOTSTRAP 1

Boolean — Bootstrap-Server.

WB_LWM2M_RES_SEC_MODE 2

Integer — Security Mode (0-4)

WB_LWM2M_RES_SEC_PUB_KEY_IDENTITY 3

Opaque — Public Key or Identity.

WB_LWM2M_RES_SEC_SERVER_PUB_KEY 4

Opaque — Server Public Key.

WB_LWM2M_RES_SEC_SECRET_KEY 5

Opaque — Secret Key.

WB_LWM2M_RES_SEC_SHORT_SERVER_ID 10

Integer — Short Server ID.

WB_LWM2M_RES_SRV_SHORT_ID 0

Integer — Short Server ID.

WB_LWM2M_RES_SRV_LIFETIME 1

Integer — Lifetime (seconds)

WB_LWM2M_RES_SRV_MIN_PERIOD 2

Integer — Default Min Period.

WB_LWM2M_RES_SRV_MAX_PERIOD 3

Integer — Default Max Period.

WB_LWM2M_RES_SRV_DISABLE 4

Execute — Disable.

WB_LWM2M_RES_SRV_DISABLE_TIMEOUT 5

Integer — Disable Timeout.

WB_LWM2M_RES_SRV_NOTIFICATION_STORING 6

Boolean — Notification Storing.

WB_LWM2M_RES_SRV_BINDING 7

String — Binding.

WB_LWM2M_RES_SRV_REG_UPDATE_TRIGGER 8

Execute — Registration Update Trigger.

WB_LWM2M_RES_DEVICE_MANUFACTURER 0

String — Manufacturer.

WB_LWM2M_RES_DEVICE_MODEL_NUMBER 1

String — Model Number.

WB_LWM2M_RES_DEVICE_SERIAL_NUMBER 2

String — Serial Number.

WB_LWM2M_RES_DEVICE_FW_VERSION 3

String — Firmware Version.

WB_LWM2M_RES_DEVICE_REBOOT 4

Execute — Reboot.

WB_LWM2M_RES_DEVICE_FACTORY_RESET 5

Execute — Factory Reset.

WB_LWM2M_RES_DEVICE_POWER_SOURCES 6

Integer[] — Available Power Sources.

WB_LWM2M_RES_DEVICE_POWER_VOLTAGE 7

Integer[] — Power Source Voltage (mV)

WB_LWM2M_RES_DEVICE_POWER_CURRENT 8

Integer[] — Power Source Current (mA)

WB_LWM2M_RES_DEVICE_BATTERY_LEVEL 9

Integer — Battery Level (%)

WB_LWM2M_RES_DEVICE_MEMORY_FREE 10

Integer — Memory Free (KB)

WB_LWM2M_RES_DEVICE_ERROR_CODE 11

Integer[] — Error Code.

WB_LWM2M_RES_DEVICE_RESET_ERROR_CODE 12

Execute — Reset Error Code.

WB_LWM2M_RES_DEVICE_CURRENT_TIME 13

Time — Current Time.

WB_LWM2M_RES_DEVICE_UTC_OFFSET 14

String — UTC Offset.

WB_LWM2M_RES_DEVICE_TIMEZONE 15

String — Timezone.

WB_LWM2M_RES_DEVICE_BINDING 16

String — Supported Binding.

WB_LWM2M_RES_DEVICE_TYPE 17

String — Device Type.

WB_LWM2M_RES_DEVICE_HW_VERSION 18

String — Hardware Version.

WB_LWM2M_RES_DEVICE_SW_VERSION 19

String — Software Version.

WB_LWM2M_RES_DEVICE_BATTERY_STATUS 20

Integer — Battery Status.

WB_LWM2M_RES_DEVICE_MEMORY_TOTAL 21

Integer — Memory Total (KB)

WB_LWM2M_RES_FW_PACKAGE 0

Opaque — Package.

WB_LWM2M_RES_FW_PACKAGE_URI 1

String — Package URI.

WB_LWM2M_RES_FW_UPDATE 2

Execute — Update.

WB_LWM2M_RES_FW_STATE 3

Integer — State (0-3)

WB_LWM2M_RES_FW_UPDATE_RESULT 5

Integer — Update Result (0-9)

WB_LWM2M_RES_FW_PKG_NAME 6

String — Package Name.

WB_LWM2M_RES_FW_PKG_VERSION 7

String — Package Version.

WB_LWM2M_RES_FW_PROTOCOL_SUPPORT 8

Integer[] — Protocol Support.

WB_LWM2M_RES_FW_DELIVERY_METHOD 9

Integer — Delivery Method.

WB_LWM2M_RES_LOC_LATITUDE 0

Float — Latitude.

WB_LWM2M_RES_LOC_LONGITUDE 1

Float — Longitude.

WB_LWM2M_RES_LOC_ALTITUDE 2

Float — Altitude (m)

WB_LWM2M_RES_LOC_RADIUS 3

Float — Radius (m)

WB_LWM2M_RES_LOC_VELOCITY 4

Opaque — Velocity.

WB_LWM2M_RES_LOC_TIMESTAMP 5

Time — Timestamp.

WB_LWM2M_RES_LOC_SPEED 6

Float — Speed (m/s)

WB_LWM2M_RES_CONN_NETWORK_BEARER 0

Integer — Network Bearer.

WB_LWM2M_RES_CONN_AVAIL_BEARERS 1

Integer[] — Available Network Bearer.

WB_LWM2M_RES_CONN_RADIO_SIGNAL 2

Integer — Radio Signal Strength (dBm)

Integer — Link Quality.

WB_LWM2M_RES_CONN_IP_ADDRESSES 4

String[] — IP Addresses.

WB_LWM2M_RES_CONN_ROUTER_IP 5

String[] — Router IP Addresses.

Integer — Link Utilization (%)

WB_LWM2M_RES_CONN_APN 7

String[] — APN.

WB_LWM2M_RES_CONN_CELL_ID 8

Integer — Cell ID.

WB_LWM2M_RES_CONN_SMNC 9

Integer — SMNC.

WB_LWM2M_RES_CONN_SMCC 10

Integer — SMCC.

WB_LWM2M_OP_READ (1 << 0)

Server can read this resource.

WB_LWM2M_OP_WRITE (1 << 1)

Server can write this resource.

WB_LWM2M_OP_EXECUTE (1 << 2)

Server can execute this resource.

WB_LWM2M_OP_RW (WB_LWM2M_OP_READ | WB_LWM2M_OP_WRITE)

Read + Write.

WB_LWM2M_VALUE_STRING(s)

Construct a String value.

#define WB_LWM2M_VALUE_STRING(s) (wb_lwm2m_value_t){ .type = WB_LWM2M_RES_TYPE_STRING, .str_val = { .str = (s), .len = strlen(s) } }

WB_LWM2M_VALUE_STRING_LEN(s, l)

Construct a String value with explicit length (for non-NUL-terminated)

#define WB_LWM2M_VALUE_STRING_LEN(s, l) (wb_lwm2m_value_t){ .type = WB_LWM2M_RES_TYPE_STRING, .str_val = { .str = (s), .len = (l) } }

WB_LWM2M_VALUE_INT(v)

Construct a signed Integer value.

#define WB_LWM2M_VALUE_INT(v) (wb_lwm2m_value_t){ .type = WB_LWM2M_RES_TYPE_INTEGER, .int_val = (int64_t)(v) }

WB_LWM2M_VALUE_UINT(v)

Construct an unsigned Integer value (LWM2M 1.1+)

#define WB_LWM2M_VALUE_UINT(v) (wb_lwm2m_value_t){ .type = WB_LWM2M_RES_TYPE_UINTEGER, .uint_val = (uint64_t)(v) }

WB_LWM2M_VALUE_FLOAT(v)

Construct a Float value (double precision)

#define WB_LWM2M_VALUE_FLOAT(v) (wb_lwm2m_value_t){ .type = WB_LWM2M_RES_TYPE_FLOAT, .float_val = (double)(v) }

WB_LWM2M_VALUE_BOOL(v)

Construct a Boolean value.

#define WB_LWM2M_VALUE_BOOL(v) (wb_lwm2m_value_t){ .type = WB_LWM2M_RES_TYPE_BOOLEAN, .bool_val = (bool)(v) }

WB_LWM2M_VALUE_OPAQUE(d, l)

Construct an Opaque (binary) value.

#define WB_LWM2M_VALUE_OPAQUE(d, l) (wb_lwm2m_value_t){ .type = WB_LWM2M_RES_TYPE_OPAQUE, .opaque_val = { .data = (const uint8_t *)(d), .len = (l) } }

WB_LWM2M_VALUE_TIME(t)

Construct a Time value (Unix timestamp)

#define WB_LWM2M_VALUE_TIME(t) (wb_lwm2m_value_t){ .type = WB_LWM2M_RES_TYPE_TIME, .time_val = (int64_t)(t) }

WB_LWM2M_VALUE_OBJLINK(oid, iid)

Construct an Object Link value.

#define WB_LWM2M_VALUE_OBJLINK(oid, iid) (wb_lwm2m_value_t){ .type = WB_LWM2M_RES_TYPE_OBJLINK, .objlink_val = { .obj_id = (oid), .inst_id = (iid) } }

WB_LWM2M_VALUE_CORELNK(s)

Construct a CoRE Link-Format value.

#define WB_LWM2M_VALUE_CORELNK(s) (wb_lwm2m_value_t){ .type = WB_LWM2M_RES_TYPE_CORELNK, .str_val = { .str = (s), .len = strlen(s) } }

WB_LWM2M_MAX_INSTANCES 4

WB_LWM2M_MAX_RESOURCES 24

Functions

wb_lwm2m_type_name

Get type name as string (for logging)

static const char * wb_lwm2m_type_name(wb_lwm2m_res_type_t type)

Parameters:

  • type (wb_lwm2m_res_type_t)

wb_lwm2m_value_get_int

Get integer from value (auto-converts from int, uint, time, bool)

static int64_t wb_lwm2m_value_get_int(const wb_lwm2m_value_t *v)

Parameters:

  • v (const wb_lwm2m_value_t *)

wb_lwm2m_value_get_float

Get float from value (auto-converts from int, uint)

static double wb_lwm2m_value_get_float(const wb_lwm2m_value_t *v)

Parameters:

  • v (const wb_lwm2m_value_t *)

wb_lwm2m_value_is_string

Check if value carries string-like data (String or CoreLnk)

static bool wb_lwm2m_value_is_string(const wb_lwm2m_value_t *v)

Parameters:

  • v (const wb_lwm2m_value_t *)

wb_lwm2m_value_is_numeric

Check if value carries numeric data (Integer, UInteger, Float, Time)

static bool wb_lwm2m_value_is_numeric(const wb_lwm2m_value_t *v)

Parameters:

  • v (const wb_lwm2m_value_t *)