Connectivity

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

See Also