Skip to content

Test MQTT TLS and reliability

Use a TLS WebSocket MQTT connection to inspect QoS, retained state, last will and reconnect boundaries.

Broker Bex: I want you to follow each acknowledgement and state transition before naming a reliability guarantee., your practice guide

Broker Bex: I want you to follow each acknowledgement and state transition before naming a reliability guarantee.
Predict the reading, then compare it with the measurement.

Python 3 in your browser (JupyterLite)

Python · no install

Use a TLS WebSocket MQTT connection to inspect QoS, retained state, last will and reconnect boundaries.

Tier 2 · Web · paste-in setup · No account

Version tested: Python 3.12.7 / Pyodide 0.27.6 in JupyterLite 0.6.4; Chromium 148.0.7778.96; captured against a local Mosquitto-compatible WebSocket broker because the capture host cannot reach the public broker; the notebook targets test.mosquitto.org; captureSource playwright:jupyterlite. Date: 2026-09-10.

Open the notebook in your browser and run each Python cell; no install or account is needed.

Three ways to run: use JupyterLite here with no install; run main.py locally from the downloadable lab folder; or open the same notebook in Google Colab.

Open in your browser (new tab)

Steps

Screens captured against Python 3 in your browser (JupyterLite) Python 3.12.7 / Pyodide 0.27.6 in JupyterLite 0.6.4; Chromium 148.0.7778.96; captured against a local Mosquitto-compatible WebSocket broker because the capture host cannot reach the public broker; the notebook targets test.mosquitto.org; captureSource playwright:jupyterlite on 2026-09-10; the tool may have moved on — the text steps are the contract.

  1. 1 Step 1

    Do
    Connect over the notebook's wss endpoint and identify the trust boundary.
    You will see
    The step names the deployed WSS URL and explains that TLS does not authorize topic meaning.
    Why it matters
    Transport protection is necessary but separate from identity, ACL and application checks.
    JupyterLite step 1 showing the TLS WebSocket boundary.
    Step 1 · Python 3 in your browser (JupyterLite); numbered callout added to a real capture. Enlarge screenshot (new tab)
  2. 2 Step 2

    Do
    Publish one message at each MQTT QoS level.
    You will see
    The trace shows QoS 0, 1 and 2 callback delivery and their handshakes.
    Why it matters
    QoS changes MQTT transfer behavior, not exactly-once database effects.
    JupyterLite step 2 showing QoS delivery evidence.
    Step 2 · Python 3 in your browser (JupyterLite); numbered callout added to a real capture. Enlarge screenshot (new tab)
  3. 3 Step 3

    Do
    Publish retained state and join with a late subscriber.
    You will see
    The late subscriber receives online with the retained flag before cleanup.
    Why it matters
    Retained state is a current snapshot, not an event history.
    JupyterLite step 3 showing a retained late-join message.
    Step 3 · Python 3 in your browser (JupyterLite); numbered callout added to a real capture. Enlarge screenshot (new tab)
  4. 4 Step 4

    Do
    Close a client without DISCONNECT to trigger its last will.
    You will see
    The watcher receives the offline will while a graceful close is explicitly contrasted.
    Why it matters
    A will reports an ungraceful session end but cannot diagnose its cause.
    JupyterLite step 4 showing the broker-delivered last will.
    Step 4 · Python 3 in your browser (JupyterLite); numbered callout added to a real capture. Enlarge screenshot (new tab)
  5. 5 Step 5

    Do
    Reconnect a durable client after an offline QoS 1 publish.
    You will see
    The reused client identity receives the queued payload after reconnect.
    Why it matters
    Session persistence requires broker support, a stable identity and non-clean session state.
    JupyterLite step 5 showing queued delivery after reconnect.
    Step 5 · Python 3 in your browser (JupyterLite); numbered callout added to a real capture. Enlarge screenshot (new tab)
  6. 6 Step 6

    Do
    State the processing guarantee for every QoS level.
    You will see
    The trace separates MQTT exchange guarantees from idempotent application actions.
    Why it matters
    A duplicate transport delivery must not create a duplicate physical effect.
    JupyterLite step 6 showing delivery and processing boundaries.
    Step 6 · Python 3 in your browser (JupyterLite); numbered callout added to a real capture. Enlarge screenshot (new tab)
  7. 7 Step 7

    Do
    Clean retained state and close the bounded public-broker test.
    You will see
    The final record confirms cleanup, disconnects and the production-scope warning.
    Why it matters
    A shared public broker is suitable only for fictional learning traffic.
    JupyterLite step 7 showing cleanup and validation.
    Step 7 · Python 3 in your browser (JupyterLite); numbered callout added to a real capture. Enlarge screenshot (new tab)

Chapter checks

These questions refer to the chapter’s examples. Use the return links to review their answers.

  1. A temperature sensor in a smart building should only be able to publish its own readings. Which ACL rule best enforces this least-privilege requirement?

    Return to the chapter’s knowledge check
  2. Your company deploys MQTT sensors in customer buildings. A sensor is configured with client_id='sensor' and username='device' with a shared password. What's the main security risk?

    Return to the chapter’s knowledge check

Caution

Use only fictional data on the public broker. WSS demonstrates server-authenticated transport encryption, not device authorization or safe production command handling.

Return to MQTT Security Fundamentals · Browse Labs