MQTTSubscriber Block
Subscribes to an MQTT broker over WebSockets and outputs real-time values from a topic. Supports JSON payload parsing.
Open MQTTSubscriber in BlockWerk →# MQTTSubscriber Block
Description
MQTTSubscriber is a source block that connects to an MQTT broker over WebSockets and feeds real-time topic values into the simulation as a numeric signal. On each incoming message the payload is parsed — either as a raw number or by extracting a named key from a JSON object — and the result is injected at the output port on every simulation step.
Use this block to bring live hardware or IoT data (sensors, PLCs, cloud services) into a BlockWerk diagram. Combine with interpolation and a playout delay to smooth jitter from variable-rate network messages before feeding control or analysis blocks.
Parameters
brokerUrl
WebSocket URL of the MQTT broker. Must start with ws:// or wss://. Default: ws://broker.hivemq.com:8000/mqtt.
topic
MQTT topic to subscribe to. Default: /blockwerk/sensor1.
jsonPath
Optional key to extract from a JSON payload (e.g. temperature). Leave empty when the payload is a plain numeric string. Nested paths are not supported; supply only a single top-level key.
playoutDelay
Buffering latency in milliseconds (0–500 ms, UI only). Adds a fixed delay to smooth packet jitter before values are consumed by the simulation. Default: 0.
interpolation
Reconstruction filter applied between received messages (UI only). Options: none (zero-order hold) or linear. Default: linear.
Examples
Read a temperature sensor publishing plain numeric payloads
MQTTSubscriber ──► [Value] ──► Display
brokerUrl: ws://broker.hivemq.com:8000/mqtt
topic: /sensors/room1/temperature
jsonPath: (empty)
Extract a field from a JSON IoT payload with jitter smoothing
MQTTSubscriber ──► [Value] ──► PIDController → [in]
brokerUrl: wss://my-broker.local:8884/mqtt
topic: /factory/conveyor/speed
jsonPath: rpm
playoutDelay: 80
interpolation: linear
Remarks
- Source (output port only): This block produces a signal; it has no input port. The value
0is held on the output until the first message arrives. - WebSocket transport: The broker must expose MQTT-over-WebSocket. Standard TCP MQTT ports are not accessible from the browser.
- JSON parsing: When
jsonPathis set, the payload must be a valid JSON object. If parsing fails the previous value is retained. - Interpolation is UI-only: The
playoutDelayandinterpolationparameters affect how the block presents data on the canvas; they do not alter the raw signal written into simulation state. - Rate display: While connected, the block shows the incoming message rate in Hz on its face.
See Also
- MQTTPublisher: The complementary sink block — publishes a simulation signal to a broker topic.
- RemoteSensor: Source block for mobile device sensor streams over WebRTC (no broker required).