MQTT broker

The station's own MQTT broker: its row in the Communication column, turning it on and off, its port and the devices connected, client authentication, the entry This station it gives the MQTT driver, and what it does not do.

View as Markdown

The MQTT broker takes the MQTT messages of the devices on your network, so a bench or a small laboratory reads its ESP32 boards, gateways and sensors without installing a broker of its own. It is the third row of the Servers folder, after the Modbus server, and it is not a driver: the devices connect to it and publish, and the station reads what they publish through the MQTT driver, as it reads any broker. Its panel says so under the title: "Takes the MQTT messages of the devices on your network, so they need no broker of their own. It receives connections and never makes one." Viewing the Connector reads the page; configuring the Connector changes it.

The row in the column

The row sits under the Servers folder of the Communication tree, below the Modbus server, with a hub icon where the drivers show a plug. A station has exactly one, and it is never created or deleted. The search box finds it by its name, and the state chips file it by its state: off while it is turned off, issues while its port is in use or it could not listen, OK otherwise. Beside the name it says what the broker is doing, and a dot sums it up:

The row says Dot When
"Turned off" grey The broker is off, which is how every station starts.
"Listening on port 1883", then how many devices are connected: "No client connected", "1 client connected", "3 clients connected" green The broker is on and the runtime runs: the port is open.
"Port 1883 is in use" red The broker is on, but another program holds the port.
"Could not listen on port 1883" red The broker is on, but Windows refused to open the port for another reason.
"Runtime stopped" grey The broker is on and the runtime is stopped: the port stays closed until the runtime runs again.

The dot is the broker's alone: it takes no part in the Drivers folder's roll-up or in the status bar, which are about the equipment the station reads.

Turning it on and off

Command What it does Greyed when
Enable Turns the broker on: "Turn the broker on: it listens on port 1883 while the runtime runs, and the MQTT driver gets the entry through which this station reads it." The feed says "MQTT broker turned on." The broker is already on ("The broker is already on."), a run holds the station, or the runtime is stopped.
Disable Turns the broker off: "Turn the broker off: it closes its port and drops every client." The feed says "MQTT broker turned off." The broker is already off ("The broker is already off."), a run holds the station, or the runtime is stopped.

A role that may not configure the Connector is not drawn the two commands. Being on is a setting the station keeps, and listening follows the runtime: the broker opens its port once the runtime is up, closes it and drops every device when the runtime stops, and opens it again when the runtime comes back. A port it cannot open is its own state, said on the row and under the port field, and the station runs on without it.

The Port and clients card

Field What it does Values and default
TCP port The port the broker listens on, on every address of this computer, IPv4 and IPv6, without TLS. Changing it while the broker listens closes the old port and opens the new one, which drops every device; the feed says "MQTT broker moved to port 1884." 1 to 65535. Default 1883, the MQTT port without TLS.
Connected clients How many devices are connected now. While any is, a table lists each one with Client ID, Client address (its IP address and port) and Connected at. Read only.

A port the broker cannot move to is refused before anything is stored, said under the field, and the field goes back to the port in force: a number outside the range ("Port must be between 1 and 65535."), the port of the web server, of agent access, of the OPC UA server or of the Modbus server ("Port N is already the Modbus server. Pick another port, or move the Modbus server first."), and a port another program holds ("Port N is in use on this machine. Close what is holding it, or pick another port."). The station's other port fields refuse the broker's port in turn: "Port N is already the MQTT broker. Pick another port, or move the MQTT broker first."

Under the card a note says: "No TLS: devices connect in plain MQTT, at most 100 at once. Other machines reach this broker only if Windows Firewall lets TCP port 1883 in: allowing it is your decision, and this station never does it on its own. Retained messages are kept until the station restarts."

At most 100 devices are connected at once, the station's own session included: one more is refused with the MQTT reason for an exceeded quota, and a device that reconnects under its own client ID takes its old place back. Retained messages are kept in memory: they come back after the runtime stops and starts again, and they are gone when the station restarts.

Windows Firewall

The station never changes Windows Firewall by itself. Under the note, a dot and a sentence say whether its own inbound rule for the broker lets the port in: "Inbound MQTT connections are allowed on port 1883 for private and domain networks.", "Network clients may be blocked because no app-owned rule allows port 1883.", or, on a launch that may not manage the firewall, such as an isolated profile or a copy that is not the installed program, "This launch cannot manage Windows Firewall. Configure inbound access in the operating system if needed." Only while the rule is missing, Allow local network asks Windows, with your approval, for a rule named "Ganter Lab MQTT broker": inbound TCP on the port, private and domain networks, the local subnet, this program. It is pressed from the station's own app ("The firewall rule can only be applied from the station's desktop app."), and the feed says "Requesting Windows Firewall access for MQTT port 1883…", then "Windows Firewall now allows MQTT connections on port 1883."

Client authentication

The Client authentication card decides who may connect:

Choice Who connects
Anonymous "Any device connects, with or without a username and password." Every station starts here.
Username & password "Every device signs in with the one username and password below." A device with any other username or password is refused, and the journal says so, grouped like any repeated failure.

Under the choice stand Username and the password, whose label says only whether one is stored: Password (stored) or Password (none stored). The stored password is never drawn back into the page: the field starts empty, and "Leave it empty to keep the stored password." The choice, the username and the password are applied together with Apply, greyed while nothing changed ("Change the authentication to apply it."); the feed then says "MQTT broker authentication saved.", and, as the line beside the button warns, "A device already connected that the new authentication does not admit is disconnected."

Entry Refused with
Username & password chosen while the username or the password is empty "Type a username and a password before the broker asks for them."
The username cleared while Username & password is in force "The broker asks every device for a username, so it cannot be empty. Choose Anonymous first to clear it."
A username or a password over 128 characters "A username takes at most 128 characters."

Under Anonymous, the username and the password stay stored for the next time. The password is kept like the password of a broker the station reads, protected for this Windows account: a backup opened on another machine or account arrives without it, no device signs in until it is typed again, and the card says "Cannot be read on this Windows account: it only opens on the machine and the Windows account that entered it. Enter it again here."

This station

The panel's last card, This station, says what the broker gives the MQTT driver: "Turned on, the broker adds the entry This station under the MQTT driver, through which this station reads the devices that publish here: on 127.0.0.1, with the broker's port and authentication. Add those devices under This station, by a scan or by hand. Turning the broker off leaves This station and its devices in place, disconnected."

Moment What happens
The broker is turned on and the station has no entry The MQTT driver is added to the station and gains the broker This station: 127.0.0.1, the broker's port, no TLS, enabled, with the broker's username and password under Username & password.
The port or the authentication changes The entry follows: its host, port and sign-in are brought to the broker's. Its name, client ID, keep-alive and whether it is enabled stay yours. Its own panel says "This entry is how this station reads its own MQTT broker (Servers, MQTT broker): its host, port and authentication follow that broker, and it stays while the broker is on."
The broker is on The entry cannot be deleted: Delete broker stays greyed on the command bar, on its right-click menu and in the driver's table, saying "Broker 'This station' is how this station reads its own MQTT broker, so it stays while that broker is on. Turn the MQTT broker off under Servers first."
The broker is turned off The entry and its devices stay where they are, disconnected. Deleted then, it is created again the next time the broker is turned on.

Nothing is added under the entry by itself: add the devices that publish to the broker with the broker's scan or by hand, as under any broker of the MQTT driver. The station's own session waits longer between attempts while the broker is off, so after the broker is turned on, the entry can take up to 30 seconds to read online. This station also carries the Publish card every broker does: what the station publishes of its own data to its own broker.

Agent access

Tool What it does
station_broker_status Reports the broker: on or off, the port, the state, the authentication without the password, the devices connected and the entry This station. It keeps working while the runtime is stopped.
station_broker_configure Turns the broker on or off, moves its port and changes the authentication, with the rules of the panel.

Neither name begins with mqtt_broker_, the tools of the brokers the station reads; both are described with every other tool on Tools.

What it does not do

  • No TLS and no WebSocket: devices connect in plain MQTT over TCP.
  • One username and password for every device, never one per device.
  • No persistent sessions, and no retained message survives a restart of the station.
  • It stops with the station: devices that keep publishing while the station is off need a broker of their own (Installing a broker).