Skip to content

MQTT probe

The MQTT probe connects to an MQTT broker and runs one action or a list of packet steps on it, recording every control packet with its fields and its raw bytes. VirtuProbe speaks MQTT directly, written against the specification rather than wrapped around a client library, so you can send a packet a client library would refuse and you see what the broker did with it, including the things it did that the specification does not allow.

A probe is a broker address, a session, an identity and either one action or a list of steps. One send opens the connection, sends the CONNECT, runs what the probe asks for and closes the session.

The MQTT probe editor: a connection to a broker on port 1884 speaking MQTT 5, the session fields with a random Client ID and clean start, with a Read retained messages action reading the topic filter $SYS/#.

FieldDescription
HostThe broker address
PortThe broker port (default: 1883, or 8883 with TLS)
VersionMQTT 5, 3.1.1 or 3.1
TLS modeNone or TLS
Trust self-signed certificatesAccept a server certificate that does not verify and skip the host name check. Shown with TLS on. Lab use
Over WebSocketCarry MQTT inside a WebSocket instead of a raw TCP stream
WebSocket pathThe request path of the WebSocket (default: /mqtt)

The TLS mode and the WebSocket switch combine into four transports: plain TCP, TLS, MQTT inside a WebSocket and MQTT inside a WebSocket over TLS. The default port follows the TLS mode, 1883 without it and 8883 with it. It moves only off that default, so a port you typed stays put.

The probe holds a reference to a credential in the credential store, not the secret itself. Pick an Authentication method in the session fields and a Credential in the auth fields.

AuthenticationCredential
User name and passwordA Basic credential, sent in the CONNECT
A SCRAM mechanismEnhanced authentication (MQTT 5 only). The CONNECT names the mechanism and the exchange runs over AUTH packets before the CONNACK

A client certificate (scheme MTLS, mutual TLS) is made in the credential store and picked in the same Credential list. Over TLS it is the connection’s identity. It may also carry a user name and password for a broker that wants both. A user name and password credential can be made without leaving the editor with New credential.

The SCRAM mechanisms on offer are SCRAM-SHA-256, SCRAM-SHA-512 and SCRAM-SHA-1. Enhanced authentication needs MQTT 5; the editor says so when the version is set lower.

A probe that logs on and has no credential of its own uses the project default (see when the probe names its own account).

FieldDescription
Client IDLeft empty, a random identifier is used for every run. A fixed one makes the broker disconnect the client that already holds it, so set it only when you mean to take that session over
Keep alive (s)The keep-alive the CONNECT asks for (default: 60)
Session expiry (s)MQTT 5 Session Expiry Interval. Empty leaves the property out
Clean startStart a fresh session rather than resume a stored one
Will MessageA Will topic, Will payload, QoS and retain. The broker publishes this if the connection drops without a DISCONNECT. Empty topic means no Will Message

Switch between Action and Advanced. An action is a ready-made exchange. Advanced is a list of control packets you write by hand.

ActionWhat it does
ConnectConnects, reads the CONNACK and disconnects
Read retained messagesSubscribes and collects the retained messages the broker holds. An empty filter reads everything
Subscribe and receiveSubscribes and waits for the given number of messages
PublishPublishes one message. With QoS 1 or 2 the acknowledgement is part of the result
Publish and wait for the answerSubscribes to the Response Topic (or to the topic itself), publishes and waits for the answer
PingConnects and exchanges PINGREQ for PINGRESP

A publishing action takes a Topic, a Payload, a QoS and a Retain flag. A receiving action takes a Topic filter, how many Messages to wait for and how long to Wait (ms).

The payload is read as Text, Hex, Base64 or Sparkplug B (JSON). For Sparkplug B you write the payload as JSON, a metrics list with a name, a datatype and a value per metric. It is sent as protobuf. A missing timestamp is filled in.

On MQTT 5, a publish may carry the specification’s PUBLISH properties: Payload Format Indicator, Message Expiry Interval, Content Type, Response Topic, Correlation Data, Topic Alias and User Property.

Advanced mode sends exactly the steps you list. Each step is a control packet (CONNECT, CONNACK, PUBLISH, PUBACK, PUBREC, PUBREL, PUBCOMP, SUBSCRIBE, SUBACK, UNSUBSCRIBE, UNSUBACK, PINGREQ, PINGRESP, DISCONNECT, AUTH), a WAIT that collects what arrives, or RAW bytes written as hex.

StepFields
PUBLISHTopic, QoS (0 to 3, so an illegal 3 can be sent), Retain, DUP, Payload and its encoding
SUBSCRIBETopic filters (comma separated), QoS and on MQTT 5 an Options byte for No Local, Retain As Published and Retain Handling
UNSUBSCRIBETopic filters
WAITWait (ms) and an optional Stop after this many messages
RAWBytes (hex), sent as they are
The acknowledgements and DISCONNECT, AUTHA Reason code

Any packet also takes a Packet ID where it carries one. A Header flags override and a Remaining Length override let the packet break the fixed header on purpose, so the Remaining Length can be made to disagree with the body. On MQTT 5 any packet may carry any of the specification’s properties.

A CONNECT is sent in front of your steps unless they already open with a CONNECT or a RAW step, so a probe that means to break the CONNECT itself opens with its own. Acknowledge QoS 1 and 2 automatically completes the inbound QoS 1 and QoS 2 handshakes for you; off, the probe sends only what its steps say. Action mode always acknowledges.

An MQTT broker drives devices, so a probe that changes the target is sent only when writes are enabled for the workspace in Settings > Advanced, the probe is Armed for writes and you confirm the send. In a chain there is nobody to confirm, so the first two decide. A refused probe sends nothing at all and the result says which condition was missing.

A probe counts as changing the target when it:

  • publishes a message, which the devices subscribed to the topic act on,
  • connects with a fixed Client ID, which disconnects the client that holds it,
  • registers a Will Message, which the broker publishes if the connection drops,
  • joins a shared subscription ($share/{group}/{filter}), which takes a share of the messages from the other consumers, or
  • sends RAW bytes that cannot be shown to be a read. A packet type VirtuProbe does not know counts here too, because nothing says it is a read.

A step that changes the target carries a Modifies target chip. The bar above it reads Modifies target with the reasons or Read only when the probe only reads. Stop after messages and Stop after bytes bound how much one run collects.

The result opens with the transport outcome when it is not OK, the duration and a CONNACK line: the return or reason code with its name, the MQTT version, the Client ID the broker assigned and whether a session was present. A probe the write gate refused shows a warning in place of the run and says nothing was sent.

Messages lists the application messages the broker delivered, each with its topic, QoS, retain flag and size. A message expands to its payload, its MQTT 5 properties and, for a Sparkplug B payload, a table of its metrics with their datatypes and values. Packets lists every control packet of the run in order, each with its direction, whether it succeeded, its command and the time it arrived at. A packet expands to its decoded fields and its raw bytes. A packet the proxy answered carries a Mocked chip. A packet the broker sent against the specification carries a Rules broken count with the findings listed inside.

An MQTT response: the retained $SYS broker-status topics the broker delivered, each a row with its QoS and its retain flag.

An expression picks a received message: blank is the last one, a whole number is its position counting from 0 and anything else is a Topic Filter (wildcards included) that selects the messages whose topic it matches.

ExtractorReturns
MQTT_SUCCESStrue when the probe passed, otherwise false
MQTT_CONNACK_CODEThe CONNACK code as a number: 0 is accepted, anything else is the broker’s refusal. Blank when no CONNACK arrived
MQTT_SESSION_PRESENTThe Session Present flag of the CONNACK, true or false
MQTT_REASON_CODEThe reason code of a received packet, as a number. The expression is a packet type (PUBACK, SUBACK, DISCONNECT); blank is the last received packet that carries a code. A SUBACK gives its highest code
MQTT_SUBACK_CODESEvery code of the last SUBACK, in the order of the filters, comma separated. A code is the granted QoS, or 128 and above for a refused filter
MQTT_MESSAGE_COUNTHow many messages arrived. Blank counts all of them, a Topic Filter counts the ones it matches
MQTT_MESSAGE_TOPICThe topic a received message arrived on, which tells a wildcard subscription which topic answered
MQTT_MESSAGE_PAYLOADThe payload of a received message as text. Blank when it is not valid UTF-8
MQTT_MESSAGE_PAYLOAD_HEXThe payload of a received message as hex
MQTT_MESSAGE_PROPERTYOne MQTT 5 property of the last message by its specification name (Content Type, Response Topic), or user:KEY for a User Property
MQTT_SERVER_PROPERTYOne property the broker announced in its CONNACK (Maximum QoS, Retain Available, Assigned Client Identifier), by its specification name
MQTT_SPARKPLUG_METRICThe value of a Sparkplug B metric by name. The newest message that carries it wins, so after a birth and some data messages this is the current value

MQTT is a chain step. {{variable}} placeholders resolve into the host, the WebSocket path, the Client ID, the Will topic and payload, the topic and payload and every step’s topic, payload, raw hex, filters and property values before the probe is sent. One pattern is to publish a setpoint, subscribe and read it back with MQTT_MESSAGE_PAYLOAD and assert on the value. Another is HTTP then MQTT: change something through the system’s own API, then subscribe to the topic it is supposed to drive.

A probe that changes the target has to be armed to run in a chain. Unarmed, the chain step fails and nothing is sent.

MQTT is interceptable behind the proxy’s SOCKS5 front door. MQTT is client-first. The proxy claims a flow by the start of its CONNECT, so it cannot take another protocol’s connection.

A mock rule for MQTT matches on the host and on a command, a case-insensitive prefix of the packet’s type followed by what it addresses: CONNECT, PUBLISH plant/line1/state, SUBSCRIBE plant/#. It answers with a reason or return code written as a number (0x87, 135, 5). The mock answers the control packets a session needs, so a client talking to it does not hang: a CONNECT gets a CONNACK, a SUBSCRIBE a SUBACK, a PUBLISH above QoS 0 its acknowledgement, an UNSUBSCRIBE its UNSUBACK, a PINGREQ a PINGRESP and the third leg of a QoS 2 flow its PUBCOMP. A QoS 0 PUBLISH has nothing to acknowledge, so it is dropped, which is what a broker losing it would look like.

A mock may also carry a SCRAM verifier (the mechanism, the salt, the iteration count, the StoredKey and the ServerKey a real server stores) so it stands in as an enhanced-authentication broker: it answers the challenge, checks the client proof and signs the server-final, so a SCRAM-auth probe completes a clean connection against the mock. The verifier cannot be reversed to the password, so it is safe in the rule.

What the proxy can read depends on the transport. Plain TCP is decoded packet by packet. Under TLS the bytes are encrypted, so the proxy relays them without decoding. MQTT inside a WebSocket opens with an HTTP upgrade and is read as HTTP.

virtuprobe-docker ships two brokers from two independent implementations. Two brokers that accept the same hand-written packets are better evidence than one.

Terminal window
cd virtuprobe-docker/all-protocols && docker compose up --build -d mqtt sparkplug-node mqtt-emqx

Mosquitto (mqtt-simple) has six listeners, one for every way into a broker:

ListenerAddressAuthentication
MQTTlocalhost:1883user name and password
MQTT, anonymouslocalhost:1884none
MQTT over TLSlocalhost:8883user name and password
MQTT over mutual TLSlocalhost:8884client certificate, its CN is the user name
MQTT over WebSocketws://localhost:9001user name and password
MQTT over WebSocket over TLSwss://localhost:9002user name and password

User vptest / Password123! may read and write everything; readonly / Password123! may read everything and write nothing, so a publish as readonly is refused. It seeds retained messages under plant/# and public/. A Sparkplug B edge node publishes births and a data message every two seconds under spBv1.0/VirtuProbe/.... The data messages carry aliases only, so a subscriber that missed the births sees no metric names until it sends a rebirth command.

EMQX (mqtt-emqx) runs beside it on its own ports (2883, 9883, WebSocket 9083 and 9084 on path /mqtt) and is the one that implements MQTT 5 enhanced authentication: user scramuser / Password123! with SCRAM-SHA-256. It has the same vptest and readonly users, no anonymous access, with topic aliases and shared subscriptions on.

Both brokers accept MQTT 3.1, 3.1.1 and 5. The TLS material and the exact seed are in each target’s README.md.

  • MQTT over QUIC. The transport is TCP, TLS or WebSocket.
  • Running as a broker or a bridge. The probe is a client.
  • Reading a payload beyond text, hex, Base64 and Sparkplug B. Anything else is kept as raw bytes, which MQTT_MESSAGE_PAYLOAD_HEX returns.

A probe file written by hand or over MCP is shaped like this.

  • The broker is host, port, tlsMode (NONE or TLS), webSocket and protocolVersion (5, 3.1.1, 3.1). authMethod is blank for a user name and password or a SCRAM mechanism for enhanced authentication. authCredentialId names a credential in the store.
  • mode is ACTION or ADVANCED. An action names actionType (PUBLISH, SUBSCRIBE_RECEIVE, READ_RETAINED, PUBLISH_RECEIVE, PING, CONNECT_CHECK) with topic, payload, qos and the rest beside it.
  • An advanced step is a type and the fields that type uses. {"type": "SUBSCRIBE", "filters": ["plant/#"], "qos": 1} is a whole subscribe. {"type": "WAIT", "waitMs": 2000, "messageCount": 3} collects three messages.
  • A probe that changes the target needs armed set to true, or the write gate refuses it and nothing is sent.