Skip to main content

coap-client-get

:::warning [UNTESTED] native_sim build + run PASSED locally, but this has not been verified on real silicon (no bench / HiL sweep). :::

Build a CoAP GET PDU and parse a response PDU with the real API — no socket.

Source: examples/connectivity/coap-client-get/.

What it does

  1. Builds a CoAP GET PDU with coap_packet_init() + coap_packet_append_option().
  2. Reads it back through the public getters — coap_header_get_code(), coap_header_get_token(), coap_find_options().
  3. coap_packet_parse()s a hand-encoded canned 2.05 Content response and prints its payload.

Unlike mqtt-sn-publish and websocket-frame, this example calls a real library API throughout — nothing is hand-rolled.

:::note CoAP is in-tree, not a third-party pin CoAP (RFC 7252) is the Zephyr subsystem at subsys/net/lib/coap/, carried by the zephyr module itself — there is no separate west pin to fetch. libraries: [coap] is the ADR 0018 top-level form: the generator reads metadata/libraries/coap.yaml and emits CONFIG_NETWORKING=y + CONFIG_COAP=y. :::

board.yaml

libraries:
- name: coap

som:
sku: E1M-AEN801

preset: e1m-evk

cores:
m55_hp:
app: ./src
peripherals: []

diagnostics:
log_level: info

Note libraries: here has no cores: key — that is the top-level ADR 0018 form, distinct from the per-core §D.lib form the vendored libraries use.

This example does no I/O — swap som.sku to any SoM/preset pair and it still builds; PDU build/parse is entirely in RAM.

Expected output

[coap-client-get] request: code=0x01 (GET), token=a1b2c3d4, Uri-Path="sensor"
[coap-client-get] response: 14 bytes, code=0x45 (2.05 Content)
[coap-client-get] payload: "23.5C"
[coap-client-get] done

See also

Questions about this page? Discuss in Community Forum