A server and browser based MQTT client for Dart.
The client is an MQTT v3(3.1 and 3.1.1) implementation supporting subscription/publishing at all QOS levels, keep alive and synchronous connection. The client is designed to take as much MQTT protocol work off the user as possible, connection protocol is handled automatically as are the message exchanges needed to support the different QOS levels and the keep alive mechanism. This allows the user to concentrate on publishing/subscribing and not the details of MQTT itself.
Examples of usage can be found in the examples directory. An example is also provided showing how to use the client to connect to the mqtt-bridge of Google's IoT-Core suite. This demonstrates how to use secure connections and switch MQTT protocols. The test directory also contains standalone runnable scripts demonstrating subscription, publishing and topic filtering.
The server client supports both normal and secure TCP connections and secure(wss) and non-secure(ws) websocket connections. The browser client supports only secure(wss) and non-secure(ws) websocket connections.
The client has been used successfully with the MQTT brokers from several of the major cloud providers IOT/MQTT platforms, including :-
It has also been used with a range of both publicly available brokers such as Mosquitto and proprietary ones. An example using the adafruit MQTT broker for flutter can be found here.
The code is originally a port from the C# nMQTT client library to Dart.
Please read the changelog for details related to specific versions.
Run this command:
With Dart:
$ dart pub add mqtt_client
With Flutter:
$ flutter pub add mqtt_client
This will add a line like this to your package's pubspec.yaml (and run an implicit dart pub get):
dependencies:
mqtt_client: ^9.5.0
Alternatively, your editor might support dart pub get or flutter pub get. Check the docs for your editor to learn more.
Now in your Dart code, you can use:
import 'package:mqtt_client/mqtt_client.dart';
The client can be configured as either a server or browser based client in many ways, using normal TCP sockets, secure TCP sockets or websockets as needed. Numerous examples of usage can be found in the examples directory here
To get started please refer to this example, showing how to configure a client for basic server side MQTT operation.
Author: shamblett
Official Website: https://github.com/shamblett/mqtt_client