Start in three steps
Read temperature and change a setpoint over CoAP using an environmental sensor that registers with a Lightweight M2M (LwM2M) server.
Before you start: Install SPX with CoAP and LwM2M support and SPX UI. Start a reachable LwM2M server, such as Leshan, and have a CoAP client ready. Download the LwM2M sensor model.
1. Create and register the sensor
Import the YAML in Models → Load model from file. Create an instance with lwm2m_server_host set to your registration server and lwm2m_local_port=56830. Start it and check that registration succeeds. The server’s UDP port 5683 and the instance’s chosen UDP port 56830 serve different roles.
2. Read a device resource
Send GET to coap://SPX_HOST:56830/3/0/0, using the reachable SPX host and published UDP port. Expect 2.05 Content with text Hammerheads Engineers. Read /3303/0/5700 for temperature in °C. Read device resources from the instance port, not the registration server’s port.
3. Write and verify the setpoint
Send PUT to /3308/0/5900 with Content-Format 0 (text/plain) and payload 24.0. The acknowledgement is 2.04 Changed with an empty body. Success: GET the same resource and read 24.0. Restore 22.0 with PUT, verify it with GET, then stop the instance.
Protocol communication
Use these settings and messages with the library’s LwM2M environment sensor model.
- Device URI
- coap://SPX_HOST:56830 — chosen local instance UDP port
- Registration server
- LWM2M_SERVER_HOST:5683; endpoint generic-lwm2m-env-001; separate from the device port
- Payload format
- text/plain (CoAP Content-Format 0); numeric values as text
Replace host placeholders with reachable addresses and use your published ports.
Swipe the table to see requests and replies.
| Address / message | Operation / payload | Expected reply |
|---|---|---|
/3/0/0 | GET — manufacturer | 2.05 Content; Hammerheads Engineers |
/3303/0/5700 | GET — temperature | 2.05 Content; numeric °C text, starting at 22.5 then changing |
/3304/0/5700 | GET — humidity | 2.05 Content; numeric percentage text |
/3308/0/5900 | GET / PUT — target; send text 24.0 | PUT: 2.04 Changed; subsequent GET: 2.05 with 24.0 |
/3308/0/5903 | GET / PUT — HVAC mode; send text auto | PUT: 2.04 Changed; GET: 2.05 with auto |
Values describe this model’s nominal setup unless noted. Live measurements change as the simulation runs.
Example request and reply
Read the manufacturer, PUT 24.0 to /3308/0/5900 with Content-Format 0, then GET it. Verify 24.0 and follow the changing temperature. Restore target 22.0.
GET coap://SPX_HOST:56830/3/0/0
→ 2.05 Content: Hammerheads Engineers
PUT coap://SPX_HOST:56830/3308/0/5900
Content-Format: 0 (text/plain)
Payload: 24.0
→ 2.04 Changed (empty payload)
GET coap://SPX_HOST:56830/3308/0/5900
→ 2.05 Content: 24.0No reply or an unexpected value?
- The linked model uses the lwm2m adapter: it registers with a server and exposes CoAP resources. It differs from a standalone coap_server model.
- 56830 is an explicit local-port override; default 0 selects a runtime port. Publish the chosen UDP port. Device resource reads go to that port, not the registration server’s 5683.
- PUT returns an empty 2.04 Changed response, not an echoed value. GET to verify. Check registration and UDP reachability before debugging paths.
What you can test next
- Read humidity at
/3304/0/5700. - Write and read back HVAC mode at
/3308/0/5903. - Use the separate
coap_serveradapter when you need a standalone CoAP model without LwM2M registration.
See the LwM2M adapter guide for configuration details.
