Back to Arduino Esp32

CoAP Simple GET — Native API

libraries/OpenThread/examples/Native/CoAP/CoAP_SimpleGet/README.md

3.3.113.6 KB
Original Source

CoAP Simple GET — Native API

Minimal two-board demo: one node runs a CoAP server with path hello, the other sends a confirmable GET and prints the payload on Serial. The Leader forms the network with a fixed dataset; the client joins using the network key only (no Commissioner).

SketchRole
server (Leader + CoAP server)Thread Leader + CoAP server on port 5683
client (one-shot GET)Thread Child + one-shot GET client
ParameterValue
Network nameESP_OT_CoAP_Demo
Channel24
PAN ID0xC0A0
CoAP pathhello

The server registers onHello() in callback mode (no CoAP polling in loop()). The client uses setConfirmable(true) for a reliable GET with response.

How to Run

  1. Flash server (Leader + CoAP server) on one ESP32-H2 / ESP32-C6 / ESP32-C5 board and open Serial Monitor at 115200.
  2. Wait until Serial shows Attached as Leader and CoAP server listening on path 'hello'.
  3. Flash client (one-shot GET) on a second board (same NETKEY as the server).
  4. The client performs one GET on hello and prints the response.

Each sketch has its own README with configuration, expected output, and troubleshooting.

Required IDF features (sdkconfig)

FeatureUsed by
CONFIG_OPENTHREAD_ENABLED=yBoth sketches
CONFIG_SOC_IEEE802154_SUPPORTED=yBoth sketches

Troubleshooting

Startup order: Flash CoAP SimpleGet — server first and wait for Attached as Leader and CoAP server listening on path 'hello'. Then flash CoAP SimpleGet — client. The client only needs the same NETKEY as the server — reset the client if it booted before the server was Leader, or erase flash after changing dataset constants.

SymptomLikely cause
Client Thread attach failedFlash server first and wait for Leader. Client needs the same NETKEY.
Client Started as LeaderServer not running — client formed its own network. Start server, erase client flash, retry.
Client started before serverNo Leader on the mesh — start server, then reset client.
GET hello -> error timeoutSeparate Thread partitions (wrong startup order) or server CoAP not started.
Wrong payload or attach to wrong networkStale NVS dataset on either board — erase flash on both boards.

See Also

License

Apache License 2.0.