Skip to content

Add CoAP and LWM2M TLV support#680

Open
joakimeriksson wants to merge 5 commits into
kbandla:masterfrom
joakimeriksson:coap-lwm2m-tlv
Open

Add CoAP and LWM2M TLV support#680
joakimeriksson wants to merge 5 commits into
kbandla:masterfrom
joakimeriksson:coap-lwm2m-tlv

Conversation

@joakimeriksson

@joakimeriksson joakimeriksson commented Apr 19, 2026

Copy link
Copy Markdown
Contributor

Implement CoAP (RFC 7252) with support for core features, Observe (RFC 7641), and Block-wise transfers (RFC 7959).
Implement LWM2M Binary TLV + JSON (OMA LWM2M v1.0) with support for Object Instances, Multiple Resources, and Resource Instances.
Add functional examples for LWM2M devices and servers, including a Leshan-ready agent.

Implement CoAP (RFC 7252) with support for core features, Observe (RFC 7641),
and Block-wise transfers (RFC 7959).
Implement LWM2M Binary TLV (OMA LWM2M v1.0) with support for Object Instances,
Multiple Resources, and Resource Instances.
Add functional examples for LWM2M devices and servers, including a Leshan-ready
agent.
Comment thread examples/leshan_agent.py Fixed
Comment thread examples/lwm2m_device.py Fixed
Comment thread examples/lwm2m_server.py Fixed
Comment thread examples/leshan_agent.py Outdated
Comment thread dpkt/lwm2m.py Outdated
joakimeriksson and others added 2 commits April 28, 2026 08:24
Per PR review, the wire-format-baked name LWM2M_TLV doesn't scale once
LwM2M's other content formats land. Restructure dpkt/lwm2m.py around a
single LWM2M namespace class (cdp.CDP-style nesting), so wire formats
become peers of an abstract data model rather than the only API:

  * LWM2M.Resource, LWM2M.ObjectInstance — format-independent model
  * LWM2M.TLV — wire format, nested (was top-level LWM2M_TLV)
  * LWM2M.ContentFormat — CoAP content-format codes
  * LWM2M.encode(obj, fmt) / LWM2M.decode(buf, fmt) — format dispatch

Callers build payloads once with native Python values and pick the wire
format at serialization time. TLV decode returns raw bytes (TLV is not
self-describing); a schema layer can be added later when needed.

Examples updated to use the new API; the Leshan agent's hand-built TLV
construction collapses into a list of LWM2M.Resource(id, value) plus a
single LWM2M.encode call.

Module-level LWM2M_OBJ_*, LWM2M_DEV_*, LWM2M_TLV_* constants kept to
match the dpkt convention (dhcp.DHCP_OPT_*, coap.COAP_OPT_*, etc.).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Implements LWM2M.JSON alongside LWM2M.TLV so callers can serve LwM2M
JSON to peers that ask for it. The data-model layer added in the prior
commit stays unchanged — Resource / ObjectInstance round-trip through
either format via LWM2M.encode / LWM2M.decode.

JSON has the debug advantage of being self-describing: decoded values
come back as native Python types (str, int, float, bool), unlike TLV
where decoded values are raw bytes pending an Object schema.

The Leshan agent now picks JSON when a peer sends Accept:
application/vnd.oma.lwm2m+json (verified end-to-end against
leshan.eclipseprojects.io for both single resources and full Object
Instance reads, including float values).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants