Before you begin
Install SPX with the MQTT package and SPX UI. Start a broker and have an MQTT client ready. Use the environment-sensor YAML linked in the communication reference.
Run the test
- Import the YAML in Models → Load model from file. Create a fresh instance with your broker host/port and
mqtt_topic_prefix=spx/demo/env. Start it and confirm RUNNING. - Connect your client to the same broker and subscribe to
spx/demo/env/telemetry/#. Subscribe before publishing: this model uses retain=false. - Publish plain text
24.0tospx/demo/env/command/setpoint_c. Keep the subscription open and readspx/demo/env/telemetry/target_c.
Check the result
The target reply represents 24°C, and telemetry/temperature_c changes over time. Broker acknowledgement alone does not prove the target changed. Publish 22.0, verify the restored target, then stop the instance.
Protocol communication
Use these settings and messages with the library’s environment sensor model.
- Client / transport
- MQTT client → BROKER_HOST:1883; same broker as SPX
- Example prefix
- spx/demo/env (override); library default: spx/examples/env
- Delivery
- Model QoS 1; retain=false; subscribe before sending commands
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 |
|---|---|---|
spx/demo/env/telemetry/# | Subscribe to the full telemetry subtree | Separate topic/value messages, not a combined JSON object |
spx/demo/env/telemetry/temperature_c | Subscribe — measured temperature | Numeric UTF-8 text, for example 22.5; changes while running |
spx/demo/env/command/setpoint_c | Publish plain text 24.0 | telemetry/target_c on the same prefix → 24.0 |
spx/demo/env/telemetry/target_c | Subscribe — target readback | Numeric text; initially 22.0 on a fresh instance |
spx/demo/env/telemetry/humidity_percent | Subscribe — humidity | Numeric percentage text; for example 45.0; changes while running |
Values describe this model’s nominal setup unless noted. Live measurements change as the simulation runs.
Example request and reply
Keep the subscription open, publish 24.0, and verify target_c=24.0 plus a changing temperature_c. Publish 22.0 to restore the target.
SUBSCRIBE spx/demo/env/telemetry/#
PUBLISH spx/demo/env/command/setpoint_c payload: 24.0
RECEIVE spx/demo/env/telemetry/target_c payload: 24.0
PUBLISH spx/demo/env/command/setpoint_c payload: 22.0
RECEIVE spx/demo/env/telemetry/target_c payload: 22.0No reply or an unexpected value?
- BROKER_HOST is the broker address reachable from your client. A container name such as mosquitto-server may work for SPX but not for a desktop client.
- Use your actual prefix on every topic. Send 24.0 as plain text, without JSON braces or extra quote characters.
- PUBACK confirms broker delivery; telemetry/target_c confirms device state. With retain=false, a late subscriber may miss an unchanged target.
Next steps
See the sensor walkthrough and its temperature-response chart. For adapter settings, use the MQTT guide.
