MQTTPublisher Block
Publishes incoming signal values to an MQTT broker over WebSockets on a specified topic.
Open MQTTPublisher in BlockWerk →# MQTTPublisher Block
Description
MQTTPublisher is a sink block that forwards an incoming numeric signal to an MQTT broker over a WebSocket connection. During simulation, each time the input value changes, the block publishes it to the configured topic — throttled to a maximum of 50 Hz to conserve broker bandwidth.
Use this block to stream simulation outputs to external MQTT consumers: dashboards (e.g. Node-RED, Grafana), embedded controllers, or other BlockWerk instances subscribed to the same topic. The block displays live connection status and the current publish rate on the canvas.
Parameters
brokerUrl
WebSocket URL of the MQTT broker. Must start with ws:// or wss://. Default: ws://broker.hivemq.com:8000/mqtt.
topic
MQTT topic string to publish to. Default: /blockwerk/actuator1.
Examples
Stream a PID controller output to a physical actuator
PIDController → [out] ──► MQTTPublisher
brokerUrl: wss://my-broker.local:8884/mqtt
topic: /plant/actuator/valve
Broadcast a generated sine wave to a monitoring dashboard
SineWave → [out] ──► MQTTPublisher
brokerUrl: ws://broker.hivemq.com:8000/mqtt
topic: /blockwerk/monitor/sine
Remarks
- Sink (no output port): This block consumes a signal; it does not produce one. Connect to its left-side input port only.
- Publish rate cap: Messages are sent at most once every 20 ms (50 Hz), and only when the value has changed since the last publish.
- Active simulation required: Publishing only occurs while a simulation is running or paused. The block connects to the broker on canvas load, but does not publish in idle state.
- WebSocket transport: The broker must expose an MQTT-over-WebSocket endpoint. Standard MQTT TCP ports are not reachable from a browser.
- Broker availability: Connection failures are shown directly on the block face. The block does not retry automatically; reopen or reload to reconnect.
See Also
- MQTTSubscriber: The complementary source block — subscribes to a topic and injects the received value into the simulation.
- ExternalInput: Inject values without a network broker, using a direct in-app channel ID.