Senzorv1.0.1

Broker settings

Set the MQTT broker every instance connects to, with its client IDs, credentials and TLS.

All instances of a project connect to one broker. To change it, click the Broker: localhost:1883 button in the top bar, which shows the current host and port. Clicking a broker problem in the Problems tab opens the same window, with the cursor in the box the problem is about. A problem with one value shows in red under that value's box, which gets a red outline.

The Broker window

The broker button opens Project settings, whose Broker section edits the project's [broker] section; its Simulation section holds the seed. Changes go into the project as you type. Instances that are already running keep their connection and show restart to apply until you restart them. While the broker settings have problems, they show device has errors instead, and cannot be restarted until you fix them. Problems with the broker settings appear in red under the box they are about, or at the top of the window, and while there are any, no device can start.

LabelKey in the fileDefault
Hosthostlocalhost
Portport1883
MQTT versionmqtt_version5
TransporttransportTCP
Pathpath/mqtt
Client ID prefixclient_id_prefixsenzor-
Keep alivekeep_alive30s
Session expirysession_expiry0s
Usernameusernamenone
Passwordpassword or password_envnone
TLS[broker.tls]off

Presets

Presets, next to Broker, fills in the address of a known broker. Choosing one sets Host and Port, and clears the username, the password and TLS, which these brokers do not need; the other settings stay.

PresetHost and port
Mosquitto on this computerlocalhost:1883
Mosquitto test servertest.mosquitto.org:1883
HiveMQ public brokerbroker.hivemq.com:1883
EMQX public brokerbroker.emqx.io:1883
The three public brokers are shared with everyone on the internet: anyone can read what your devices publish there. Do not send anything private.

MQTT version

MQTT version chooses 5 or 3.1.1 for every instance of the project. Use 3.1.1 for a broker that does not support MQTT 5. Such a broker refuses MQTT 5 clients:

  • A broker that answers the MQTT 5 connection with "unsupported protocol version" ends each instance Failed with the broker does not support MQTT 5; ….
  • A broker that speaks only MQTT 3.1.1, such as Mosquitto before 1.6, closes the connection. Senzor then checks whether the broker answers MQTT 3.1.1, and if it does, ends the instance Failed with the same message. Over TLS it cannot check: the instance keeps reconnecting, and until it has connected once its error ends with the broker closed the connection before accepting it; if it supports only MQTT 3.1.1, ….

With 3.1.1, the MQTT 5 settings (Session expiry here, and the message properties and Will delay in the template editor) are disabled with the note needs MQTT 5; the broker settings use MQTT 3.1.1. A setting that still has a value stays editable, so you can clear it; until you do, the Problems tab lists it, and the devices it affects cannot start (all of them, for Session expiry).

Transport

Transport chooses how instances reach the broker: TCP, the usual MQTT connection, or WebSocket, MQTT inside a WebSocket connection, as brokers behind a web server or a proxy take it. With WebSocket, a Path row appears under it: the path the broker serves MQTT on, /mqtt unless you change it. It must start with /, or the Problems tab lists path `mqtt` must start with / and no device can start. Brokers take WebSocket on a port of their own, such as 8080 or 8083, so set Port to that.

With TLS on, WebSocket connects over wss://, with the same certificates. The project file writes transport = "websocket" and path; with TCP, neither is written. The Path of a TCP connection is not used.

Session expiry

Session expiry is how long the broker keeps an instance's session after its connection ends. At 0s, the default, every connect starts a clean session. Above zero, a reconnect continues the session; that is what lets an instance that reconnects within its template's Will delay cancel its Last Will. See Availability and Last Will. It takes whole seconds, like 1m.

Client ID prefix

Each instance connects with the prefix followed by its instance ID as its client ID, so with the default prefix, instance office-0 connects as senzor-office-0. A broker allows one connection per client ID, so give each copy of a project its own prefix when several copies use the same broker.

Keep alive

Keep alive takes a duration like 30s or 1m: whole seconds, from 1 second to 65535 seconds (18h 12m 15s), the most MQTT can carry. Text that is not a duration stays in the box with the hint use e.g. 10s, 500ms, 1h, and the setting keeps its previous value.

Username and password

Leave Username empty to connect without credentials. A password needs a username.

The selector next to Password says where the password comes from:

  • none: no password.
  • in the file: type the password into the box. Senzor stores it in the project file as password, in plain text.
  • from env var: type the name of an environment variable, which starts as MQTT_PASSWORD. Senzor stores the name as password_env and reads the variable from the environment Senzor runs in. If the variable is not set, the Problems tab says so and no device can start.

Use from env var to keep the password out of the project file, for example when you commit the file to a repository:

[broker]
host = "mqtt.example.com"
username = "senzor"
password_env = "MQTT_PASSWORD"

TLS

Tick use TLS to connect over TLS. Three more boxes appear:

  • CA file: the certificate authority that signed the broker's certificate, as a PEM file. Leave it empty to trust the system's root certificates.
  • Client certificate and Client key: PEM files for brokers that require client certificate authentication. Set both or neither; they also require a CA file.

Ticking use TLS does not change the port. Brokers usually accept TLS on a different port, often 8883, so set Port as well.

Senzor reads the files whenever it validates the project, so a file it cannot read shows up in the Problems tab. Relative paths are resolved against the project file's folder, as the note at the bottom of the window says. For a project you have not saved yet, they are resolved against the folder you started Senzor in. The project file reference lists every broker key.

Test connection

Test connection, under the broker settings, connects to the broker once with the settings as they are, then disconnects. It does not start any device and sends no messages or Last Will. The client ID is the Client ID prefix followed by connection-test, for example senzor-connection-test.

While it runs, the window shows connecting…. Then it shows Connected, or in red why the connection failed, in the same words a failed instance uses: a refusal such as broker refused the connection: BadUserNamePassword, a broker that does not support MQTT 5, or a network error. When the broker does not answer within 10 seconds, the result is no answer from <host>:<port> within 10 s.

The result stays until you change a broker setting. While the broker settings have problems, the button is off: hover over it to read Fix the broker problems first.

Clear retained messages

Every instance with availability leaves its last status, usually offline, as a retained message on the broker, and so do the messages of a template with Retain ticked and the Home Assistant discovery messages of a template with announce over MQTT Discovery ticked. New subscribers receive them first. Clear retained messages…, under Test connection, deletes them.

It lists the topics first, in a dialog such as Clear 3 retained topics?. Clear publishes an empty retained message to each topic, which makes the broker forget the message it keeps there; Cancel leaves them. While it runs, the window shows clearing…, then Cleared 3 retained topics, or in red why it could not, after Could not clear:. The client ID is the Client ID prefix followed by clear-retained.

The button is off while any of the project's instances runs, since they would publish their retained messages again: hover over it to read Stop the devices first: running instances would publish their retained messages again. It is also off while the broker settings have problems. When no template has availability, retains its messages or announces to Home Assistant, the window says Nothing to clear: no template has availability, retains its messages or announces to Home Assistant. A topic that uses a field value is cleared only for the field's first value, and devices with problems are left out. From the command line, use senzor-cli clear-retained.

Run elsewhere

Run elsewhere, at the bottom of Project settings, puts text on the clipboard that runs the project with senzor-cli, for the setups the CI and Docker recipe describes:

  • Copy as a GitHub Actions step: a step that validates the project, runs it for up to 10 minutes in the background while ./run-integration-tests.sh (replace it with your tests) runs, then stops it cleanly.
  • Copy as a docker-compose service: a service named senzor that mounts the project file into the container and runs it. It names an image senzor-cli, which you build yourself, as the recipe's Senzor in a container explains. When the broker's host is localhost, a comment points out that inside a container that is the container itself.

Both use the project's file name, so the buttons are off until the project is saved; they assume the file sits next to the workflow's working directory or the compose file, so adjust the path if it does not. When the broker password comes from an environment variable (password_env), the step passes it from a secret of the same name and the service from the environment. Copied. confirms the copy. The command palette offers both too.

On this page