Trace CoAP methods and Observe on local UDP
Discover a local CoAP resource, read and change values, then correlate two Observe notifications by token and actual UDP bytes.

Broker Bex
Broker Bex: I want you to match each resource action and notification to its wire evidence.
Predict the reading, then compare it with the measurement.
Python 3 + aiocoap
PythonDownload the three files, create a Python virtual environment, install requirements.txt, and run main.py.
Open the Python run guide (new tab)Get the files
Download all three prepared files into one folder. No account or paid service is required.
- Put main.py, requirements.txt, and README.md in the same folder.
- Create and activate a Python virtual environment, then install requirements.txt.
- Run python3 main.py and compare its output with each observed result below.
Steps
Step 1
- Do
- In the terminal window panel, run
python3 main.py --step 1to GET/sensorsand inspect the returned resource links. - You will see
- The local UDP trace contains a 2.05 Content response with
</temperature>;obs,</target>;rt="setpoint".
- The local UDP trace contains a 2.05 Content response with
- Why it matters
- Discovery names the observable reading and the writable target before clients use either resource.

Step 1 · Python 3 + aiocoap; numbered callout added to a real capture. Step 2
- Do
- In the terminal window panel, run
python3 main.py --step 2to GET/temperature; compare the datagram hex, CoAP code, and decoded reading. - You will see
- The actual response has
2.05 Contentand payload21.5; the output prints request and response datagram bytes.
- The actual response has
- Why it matters
- The resource value can be tied to a specific UDP request and response rather than inferred from a page example.

Step 2 · Python 3 + aiocoap; numbered callout added to a real capture. Step 3
- Do
- In the terminal window panel, run
python3 main.py --step 3to PUT22.0to/target; inspect the response code. - You will see
- The PUT payload is
22.0and the application response is2.04 Changedwith payload22.0.
- The PUT payload is
- Why it matters
- A change operation has a different method and success code from a read.

Step 3 · Python 3 + aiocoap; numbered callout added to a real capture. Step 4
- Do
- In the terminal window panel, run
python3 main.py --step 4to GET/targetafter the PUT. - You will see
- The follow-up GET returns
2.05 Contentwith payload22.0.
- The follow-up GET returns
- Why it matters
- A second read confirms that this run changed the target state.

Step 4 · Python 3 + aiocoap; numbered callout added to a real capture. Step 5
- Do
- In the terminal window panel, run
python3 main.py --step 5to register Observe and trigger two local temperature updates. - You will see
- The initial response is
21.5 observe=0; notifications report22.0 observe=1and22.5 observe=2.
- The initial response is
- Why it matters
- The changing Observe values and payloads show server-initiated updates after one registration.

Step 5 · Python 3 + aiocoap; numbered callout added to a real capture. Step 6
- Do
- In the terminal window panel, run
python3 main.py --step 6and compare the response token in all three UDP datagrams. - You will see
- Three server datagrams share one response token;
same token across initial response and updates=True.
- Three server datagrams share one response token;
- Why it matters
- The token links the initial response and subsequent notifications to one observer request.

Step 6 · Python 3 + aiocoap; numbered callout added to a real capture.
Chapter checks
These questions refer to the chapter’s examples. Use the return links to review their answers.
A CoAP Observe design replaces polling for a fast-changing sensor. What evidence should be reviewed before accepting it?
Return to the chapter’s knowledge checkThe thermostat accepts sequence 47, then receives sequence 46 with the same endpoint and Token one second later. How should it use the Observe value?
Return to the chapter’s knowledge check
Caution
Before you start
Read this before you start.
All values are fictional and the UDP datagrams stay on 127.0.0.1. Observe notifications are not proof of radio behavior, end-to-end security, battery savings, or a durable subscription after restart.
Technical details
- Version tested
- Version tested: Python 3.9.21; aiocoap 0.4.7; local UDP; Xfce Terminal 1.0.4 on Xvfb. Date: 2026-10-08.
https://iotclass.org/labs/coap-local-methods-observe.htmlReturn to CoAP Observe: Subscriptions and Updates · Browse Labs