Watch a CoAP write change a virtual tank
Plot the valve opening and the water level in Attributes. Close the inlet with a CoAP write and watch the level fall. Reopen it and the level begins to recover as the model simulates inflow and outflow.

Find the device endpoint and its LwM2M resources
Open Communication and expand the LwM2M adapter. Check both the registration server and the local CoAP device port. In the custom tank, /3203/0/5650 maps to the valve opening and /3300/0/5700 exposes the current tank level.

Show the CoAP resource bindings in YAML
Excerpt from the custom tank shown above.
bindings:
- name: query_tank_level
path: 3300/0/5700
operation: read
read_attribute: '#attr(tank_level_pct)'
content_format: text/plain
- name: set_valve_opening
path: 3203/0/5650
operation: write
write_attribute: '#attr(k__valve_opening_ratio)'
content_format: text/plain
Verify the write and read the tank level
The client received 2.04 Changed after writing 0.6 and read back 0.6 with a separate GET. The LwM2M view in this version of SPX UI stops at the bindings group. SPX Server recorded the write under set_valve_opening.
{
"direction": "inbound",
"raw": [48, 46, 54],
"decoded": "0.6",
"status": "ok",
"metadata": {
"method": "put",
"path": "/3203/0/5650"
}
}
Try a ready-made LwM2M sensor
Register a library sensor, read its temperature and verify a setpoint change through CoAP.
Test an IoT integration with a virtual device
Use a simulated device to explore CoAP resources and LwM2M registration without relying on physical hardware. Read measurements, write a control value and observe how the model responds.
CoAP & LwM2M
Registration and resource access use separate endpoints
LwM2M server
Device registration
Receives registration on its own UDP endpoint.
SPX Server · runtime
Virtual device
Simulates behavior and exposes CoAP resources on a device endpoint.
Your integration
CoAP client
Reads and writes resources at the reachable device address.
Install SPX with CoAP/LwM2M and SPX UI. The device registers with an LwM2M server such as Leshan. The server's registration port and the device's CoAP port have different roles: point a resource client at the reachable device endpoint, not the registration port. SPX also supports a standalone CoAP adapter when LwM2M registration is not needed.
Create a water-tank model with your AI agent
For this example, an AI agent creates a custom virtual tank with a numeric water level and a remotely adjustable inlet valve. The level evolves from a simple inflow and outlet balance; it is an illustrative simulation rather than a calibrated model of a physical tank.
Open your SPX workspace in a local AI agent and use this prompt:
Prompt for your AI agent
Create and test a new SPX custom virtual device model for a water storage tank with a numerically evolving water level and a remotely controlled analog inlet valve. It must be distinct from the existing environmental sensor. Use only standard IPSO/OMA LwM2M resources, and verify each resource URI, access mode, data type, and range from the authoritative OMA LwM2M Registry before using it. Map the tank level to Generic Sensor `/3300/0/5700` (read-only Float) and valve opening to Analog Output `/3203/0/5650` (read/write Float, 0..1); expose the level unit at `/3300/0/5701` (read-only String). Parameterize the LwM2M endpoint ID, Leshan host and port, and local CoAP port. Give all SPX attributes explicit types and stable names for every binding. Implement deterministic tank-level dynamics on each model run: level increases with valve opening times a configurable inflow gain, decreases by a configurable fixed outlet loss, and is clamped to 0–100%. Save the model YAML only under the workspace `custom_models` directory; do not edit the web UI or public catalog. Validate it, register the custom model, and create/start one uniquely named instance using the already available isolated Leshan service, preserving every existing instance. Perform a real Leshan/CoAP GET of the tank level, PUT a new valve opening value, GET the valve resource back, advance the virtual device enough simulation steps to show the numerical level response, and GET the level again. Report the exact model and instance IDs, resolved Leshan and CoAP endpoints/ports, resource URIs and types, actual before/after values, validation result, and limits of the test. Leave the instance running until a screenshot has been captured; do not clean it up.
Tested with GPT-6 Luna · Medium
Estimated API cost · $0.0545 per run
We tested this prompt with GPT-6 Luna · Medium. The agent created and validated the model, registered a virtual instance with Leshan, and verified reads and writes using a CoAP client. A separate run generated another model and confirmed the same resource mapping; it used a typed value when writing through Leshan. Download the resulting YAML. The estimated cost on the card comes from a separate run that generated and tuned a new tank model, verified registration and valve readback, and measured its level response. A new run may select different endpoints, so check its reported configuration.
Connect and observe
In our example the resources map to SPX attributes as follows:
| CoAP resource | Operation | Model value |
|---|---|---|
/3300/0/5700 | GET | Tank level as a Float in percent |
/3300/0/5701 | GET | Level units as a String (%) |
/3203/0/5650 | GET / PUT | Valve opening as a Float from 0 to 1 |
The resource types and access modes follow the OMA registry's Generic Sensor and Analog Output definitions. This demonstration tests these selected resources; it does not establish complete LwM2M conformance. Use values within the specified valve range.
- Check that the instance has registered with your LwM2M server, then send GET to the device's
/3300/0/5700. - Send a text/plain PUT to
/3203/0/5650with0.0to close the inlet. A 2.04 Changed response acknowledges the write; a separate GET verifies the valve value. - Read the level again after it has changed. Reopen the inlet, for example with
0.6, and observe the response in SPX UI. The rate is per simulation step and depends on runtime execution speed.
In our test, closing the valve reduced the level from 100% to approximately 52.6%. After a write of 0.6, CoAP read back 0.6 and the simulated level rose again. The test client and Leshan ran within an isolated Docker network; the CoAP port was not published to the host.
See the LwM2M adapter guide for registration and resource settings, and the CoAP adapter guide for standalone CoAP.
