A small WPF desktop tool for connecting to and disconnecting from an MQTT broker. Used as a helper for other projects that rely on an MQTT broker.
- Connect to an MQTT broker using URL and password (credentials entered in the UI).
- Disconnect from the broker.
- Status indicator (red/green) and reactive UI: buttons and inputs enable/disable based on connection state, including when the connection drops unexpectedly (polling every second).
- Requirements: .NET 9 SDK, Windows (WPF).
- Build and run:
- Open
MqttHelperTools.slnin Visual Studio or Rider, or from the repo root: dotnet builddotnet run --project MqttHelperTools
- Open
- Enter the broker URL (e.g. hostname or IP, with optional port) and password, then use Connect / Disconnect.
- WPF for the UI; MQTTnet for the MQTT client.
- Single client instance: one MQTT client is created at startup and reused; Connect/Disconnect only change its state (no new client per click).
- Threading: a background task polls connection state and updates the UI via
Dispatcher.Invokeso the status and button/input state stay in sync without cross-thread access. - Cleanup: polling is cancelled and the MQTT client is disposed when the window closes (
Closedevent;IDisposableon the wrapper, inner client disposed infinally).
MqttHelperTools/– WPF app:MainWindow(UI + connect/disconnect handlers, polling),MqttClient(thin wrapper around MQTTnet, connect/disconnect, dispose).