mqtt 1.1.4

  • README.md
  • CHANGELOG.md
  • Installing
  • Versions
  • 31

Mqtt

This is an mqtt client written in DART. It can be used in the browser (over websocket) or the VM (over socker or websocket).

See http://mqtt.org/ for details on mqtt protocol

Usage

Create a connection over websocket: var mqttCnx = new MqttConnectionIOWebSocket.setOptions("ws://127.0.0.1/8080");

Create a connection over socket: var mqttCnx = new MqttConnectionIOSocket.setOptions(host:127.0.0.1, port: 8083);

Create mqtt client: MqttClient c = new MqttClient(mqttCnx, clientID: "MyClientID", qos: QOS_1);

Set a will (must be done before connecting to the broker): c.setWill("MyWillTopic", "MyWillPayload", QOS_1, 0);

Connect to broker: c.connect(onConnectionLost) .then( (c)=> onConnected(c) ) .catchError((e) => print("Error: $e"), test: (e) => e is SocketException)
.catchError((mqttErr) => print("Error: $mqttErr") );

Publish a message: c.publish("MyTopic", "MyMessage", 1, QOS_1, 0) .then( (m) => print("Message ${m.messageID} published"); );

Subscribe to a topic: c.subscribe("MyTopic", QOS_1, onMessage) .then( (s) => print("Subscription done - ID: ${s.messageID} - Qos: ${s.grantedQoS}") );

Unsubscribe: c.unsubscribe("MyTopic", s.messageID) .then( (u) => print("Unsubscribed from subscription ${u.messageID}") );

Disconnect: c.disconnect();

VM Example

See mqtt_sub for a sample mqtt publish and mqtt_pub for a sample subscribe. Available options can be displayed through: > dart mqtt_sub.dart -h > dart mqtt_pub.dart -h

Web Example

See Mqtt_web for a sample web page connecting, subscribing and publishing mqtt messages

Testing

Testing was done using the mosquitto broker (http://mosquitto.org/). A mosquitto test server is available at http://test.mosquitto.org/.

Websocket testing was done throught mqtt_ws_bridge.dart.

1.1.4

  • Dart 2 support

1.1.3

  • Fix error "Connection Refused: bad user name or password"
  • Fix issue with dart 2 support: "type 'Future<dynamic>' is not a subtype of type 'Future<int>'"

1.1.2

  • Dart 2 support

1.0.1

  • Initial version

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  mqtt: ^1.1.4

2. Install it

You can install packages from the command line:

with pub:


$ pub get

Alternatively, your editor might support pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:mqtt/mqtt_client.dart';
import 'package:mqtt/mqtt_connection_html_websocket.dart';
import 'package:mqtt/mqtt_connection_io_socket.dart';
import 'package:mqtt/mqtt_connection_io_websocket.dart';
import 'package:mqtt/mqtt_connection_shared.dart';
import 'package:mqtt/mqtt_message.dart';
import 'package:mqtt/mqtt_message_assured.dart';
import 'package:mqtt/mqtt_message_connack.dart';
import 'package:mqtt/mqtt_message_connect.dart';
import 'package:mqtt/mqtt_message_disconnect.dart';
import 'package:mqtt/mqtt_message_ping.dart';
import 'package:mqtt/mqtt_message_publish.dart';
import 'package:mqtt/mqtt_message_suback.dart';
import 'package:mqtt/mqtt_message_subscribe.dart';
import 'package:mqtt/mqtt_message_unsuback.dart';
import 'package:mqtt/mqtt_message_unsubscribe.dart';
import 'package:mqtt/mqtt_options.dart';
import 'package:mqtt/mqtt_shared.dart';
import 'package:mqtt/mqtt_utils.dart';
import 'package:mqtt/mqtt_version_v3.dart';
  
Version Uploaded Documentation Archive
1.1.4 Aug 13, 2018 Go to the documentation of mqtt 1.1.4 Download mqtt 1.1.4 archive
1.1.3 Aug 13, 2018 Go to the documentation of mqtt 1.1.3 Download mqtt 1.1.3 archive
1.1.2 Jun 4, 2018 Go to the documentation of mqtt 1.1.2 Download mqtt 1.1.2 archive
1.1.0 Oct 24, 2014 Go to the documentation of mqtt 1.1.0 Download mqtt 1.1.0 archive
1.0.2 Jun 4, 2018 Go to the documentation of mqtt 1.0.2 Download mqtt 1.0.2 archive
1.0.0 Jul 12, 2013 Go to the documentation of mqtt 1.0.0 Download mqtt 1.0.0 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
61
Health:
Code health derived from static analysis. [more]
--
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
--
Overall:
Weighted score of the above. [more]
31
Learn more about scoring.

The package version is not analyzed, because it does not support Dart 2. Until this is resolved, the package will receive a health and maintenance score of 0.

Analysis issues and suggestions

Fix dependencies in pubspec.yaml.

Running pub upgrade failed with the following output:

ERR: The current Dart SDK version is 2.1.0.
 
 Because mqtt depends on ini >=0.0.5 <2.0.0 which requires SDK version <2.0.0, version solving failed.

Health suggestions

Format bin/mqtt_ws_bridge/mqtt_ws.dart.

Run dartfmt to format bin/mqtt_ws_bridge/mqtt_ws.dart.

Format lib/mqtt_client.dart.

Run dartfmt to format lib/mqtt_client.dart.

Format lib/mqtt_connection_html_websocket.dart.

Run dartfmt to format lib/mqtt_connection_html_websocket.dart.

Fix additional 18 files with analysis or formatting issues.

Additional issues in the following files:

  • lib/mqtt_connection_io_socket.dart (Run dartfmt to format lib/mqtt_connection_io_socket.dart.)
  • lib/mqtt_connection_io_websocket.dart (Run dartfmt to format lib/mqtt_connection_io_websocket.dart.)
  • lib/mqtt_connection_shared.dart (Run dartfmt to format lib/mqtt_connection_shared.dart.)
  • lib/mqtt_message.dart (Run dartfmt to format lib/mqtt_message.dart.)
  • lib/mqtt_message_assured.dart (Run dartfmt to format lib/mqtt_message_assured.dart.)
  • lib/mqtt_message_connack.dart (Run dartfmt to format lib/mqtt_message_connack.dart.)
  • lib/mqtt_message_connect.dart (Run dartfmt to format lib/mqtt_message_connect.dart.)
  • lib/mqtt_message_disconnect.dart (Run dartfmt to format lib/mqtt_message_disconnect.dart.)
  • lib/mqtt_message_ping.dart (Run dartfmt to format lib/mqtt_message_ping.dart.)
  • lib/mqtt_message_publish.dart (Run dartfmt to format lib/mqtt_message_publish.dart.)
  • lib/mqtt_message_suback.dart (Run dartfmt to format lib/mqtt_message_suback.dart.)
  • lib/mqtt_message_subscribe.dart (Run dartfmt to format lib/mqtt_message_subscribe.dart.)
  • lib/mqtt_message_unsuback.dart (Run dartfmt to format lib/mqtt_message_unsuback.dart.)
  • lib/mqtt_message_unsubscribe.dart (Run dartfmt to format lib/mqtt_message_unsubscribe.dart.)
  • lib/mqtt_options.dart (Run dartfmt to format lib/mqtt_options.dart.)
  • lib/mqtt_shared.dart (Run dartfmt to format lib/mqtt_shared.dart.)
  • lib/mqtt_utils.dart (Run dartfmt to format lib/mqtt_utils.dart.)
  • lib/mqtt_version_v3.dart (Run dartfmt to format lib/mqtt_version_v3.dart.)

Maintenance issues and suggestions

Fix platform conflicts. (-20 points)

Error(s) prevent platform classification:

Fix dependencies in pubspec.yaml.

Running dartdoc failed. (-10 points)

Make sure dartdoc runs without any issues.

The description is too short. (-20 points)

Add more detail about the package, what it does and what is its target use case. Try to write at least 60 characters.

Maintain an example.

None of the files in your example/ directory matches a known example patterns. Common file name patterns include: main.dart, example.dart or you could also use mqtt.dart. Packages with multiple examples should use example/readme.md.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.8.0 <3.0.0