TCS Pune

MQTT Publish, Subscribe and QoS

IoT & Wireless practical

MQTT Publish, Subscribe and QoS

Model topics, retained state, QoS and Last Will using a lab broker or the local simulator.

Topology and objective

Sensor publisher → MQTT broker → dashboard subscriber; command topic returns to device.

Hardware and tools

  • Supported development board
  • USB data cable
  • Current-limited supply
  • Serial monitor and logic analyser when applicable

Security and RF safety

  • Use TLS for untrusted networks.nUse per-device credentials and topic ACLs.nNever expose an unauthenticated broker to the internet.

Practical procedure

  1. Design device-specific telemetry and command topics.nConnect with a unique client ID.nPublish JSON telemetry at QoS 0.nSubscribe to a command topic.nTest retained state and Last Will offline status.

Telemetry / payload

{"device_id":"esp32-01","ts":1724659200,"temperature":25.2,"online":true}

Starter code / config

telemetry: tcs/lab/esp32-01/telemetryncommands: tcs/lab/esp32-01/commandnstatus: tcs/lab/esp32-01/status

Expected results

CheckpointExpectedTool
PublishSubscriber receives valid JSONMQTT clientnOffline

Troubleshooting

SymptomCheckAction
Connection refusedVerify host, port, TLS and credentialsCorrect one setting at a timenDuplicate messages
Local-only sandbox

Commands & telemetry simulator

Device statusOfflineNever seen
Latest value
Messages0this session

Send command

Simulator ready. No network connection is used.
Privacy: Use test credentials and non-sensitive sample data. Never publish Wi-Fi passwords, API tokens, device certificates, SIM credentials or precise personal GPS locations.
Ready when you are

Need help with your laptop or computer?

Send us the model and fault details. Start your repair request online or contact TCS Pune directly.

WA