Add CoAP and LWM2M TLV support#680
Open
joakimeriksson wants to merge 5 commits into
Open
Conversation
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.
kbandla
reviewed
Apr 21, 2026
kbandla
reviewed
Apr 27, 2026
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.