From d6fcd7dc68d3df43519bc50f77a2888cc4e02078 Mon Sep 17 00:00:00 2001 From: Rasarts Date: Fri, 28 Jul 2017 15:18:43 +0300 Subject: [PATCH 1/5] Update _processMqttMessage method --- .gitignore | 12 ++++++++++++ lib/mqtt_client.dart | 3 ++- lib/mqtt_shared.dart | 1 + 3 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4d2a4d6 --- /dev/null +++ b/.gitignore @@ -0,0 +1,12 @@ +# See https://www.dartlang.org/tools/private-files.html + +# Files and directories created by pub +.packages +.pub/ +build/ +# If you're building an application, you may want to check-in your pubspec.lock +pubspec.lock + +# Directory created by dartdoc +# If you don't generate documentation locally you can remove this line. +doc/api/ diff --git a/lib/mqtt_client.dart b/lib/mqtt_client.dart index b3ad7e7..1c73a11 100644 --- a/lib/mqtt_client.dart +++ b/lib/mqtt_client.dart @@ -190,7 +190,8 @@ class MqttClient { * * Return the data that has not been processed */ - List _processMqttMessage(data) { + List _processMqttMessage(ByteBuffer details) { + var data = details.asInt8List(); num type = data[0] >> 4; int msgProcessedLength = data.length; diff --git a/lib/mqtt_shared.dart b/lib/mqtt_shared.dart index 973c4b2..a2911fa 100644 --- a/lib/mqtt_shared.dart +++ b/lib/mqtt_shared.dart @@ -5,6 +5,7 @@ import 'mqtt_version_v3.dart' ; import "package:ini/ini.dart"; import 'dart:io'; import 'dart:convert'; +import 'dart:typed_data'; part 'mqtt_client.dart'; part 'mqtt_connection_shared.dart'; From 1f550970be638c3ff7e87f7f346beee5e3b2fda0 Mon Sep 17 00:00:00 2001 From: Rasarts Date: Fri, 28 Jul 2017 15:26:21 +0300 Subject: [PATCH 2/5] Added userName and userPassword fields for MqttClient --- lib/mqtt_client.dart | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/mqtt_client.dart b/lib/mqtt_client.dart index 1c73a11..9e6b5f1 100644 --- a/lib/mqtt_client.dart +++ b/lib/mqtt_client.dart @@ -11,6 +11,9 @@ class MqttClient { var onSubscribeData = null; var onConnectionLost = null; Map _messagesToCompleteMap; + + String userName; + String userPassword; var _liveTimer; @@ -20,7 +23,7 @@ class MqttClient { /** * MqttClient constructor */ - MqttClient(E mqttConnection, {String clientID: '', num qos: 0x0, bool cleanSession:true} ) + MqttClient(E mqttConnection, {String clientID: '', num qos: 0x0, bool cleanSession:true, String this.userName, String this.userPassword} ) : _mqttConnection = mqttConnection, _clientID = clientID, _qos = qos, _cleanSession = cleanSession, debugMessage = false, _will = null; /** @@ -40,8 +43,11 @@ class MqttClient { * An optional callback can be provided to be called when * the connection to the mqtt broker has been lost */ - Future connect([onConnectionLostCallback]) { + Future connect([onConnectionLostCallback, String uName, String uPassword]) { _connack = new Completer(); + + userName = uName != null ? uName : userName; + userPassword = uPassword != null ? uPassword : userPassword; if (onConnectionLostCallback != null) onConnectionLost = onConnectionLostCallback; @@ -165,6 +171,12 @@ class MqttClient { print("Opening session"); MqttMessageConnect m = new MqttMessageConnect.setOptions(_clientID, _qos, _cleanSession); + m._userName = userName; + m.setUserName(userName); + + m._password = userPassword; + m.setUserNameAndPassword(userName, userPassword); + // set will m.setWill(_will); _mqttConnection.sendMessageToBroker(m, debugMessage); From 095443f2735b0e81952cafb2e5162d32ad8f8d0d Mon Sep 17 00:00:00 2001 From: Rasarts Date: Fri, 28 Jul 2017 15:45:20 +0300 Subject: [PATCH 3/5] Update _openSession method --- lib/mqtt_client.dart | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/mqtt_client.dart b/lib/mqtt_client.dart index 9e6b5f1..8abec4f 100644 --- a/lib/mqtt_client.dart +++ b/lib/mqtt_client.dart @@ -170,10 +170,8 @@ class MqttClient { void _openSession() { print("Opening session"); MqttMessageConnect m = new MqttMessageConnect.setOptions(_clientID, _qos, _cleanSession); - - m._userName = userName; - m.setUserName(userName); + m._userName= userName; m._password = userPassword; m.setUserNameAndPassword(userName, userPassword); From 9729f98c6696bca42ed10da9f21e56e2674c0833 Mon Sep 17 00:00:00 2001 From: Rasarts Date: Fri, 28 Jul 2017 16:22:25 +0300 Subject: [PATCH 4/5] Change type of parameter for method _processMqttMessage --- lib/mqtt_client.dart | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/mqtt_client.dart b/lib/mqtt_client.dart index 8abec4f..68c3dbe 100644 --- a/lib/mqtt_client.dart +++ b/lib/mqtt_client.dart @@ -200,8 +200,11 @@ class MqttClient { * * Return the data that has not been processed */ - List _processMqttMessage(ByteBuffer details) { - var data = details.asInt8List(); + List _processMqttMessage(dynamic details) { + var data = details; + + if (details.runtimeType.toString() != 'Uint8List') data = details.asInt8List(); + num type = data[0] >> 4; int msgProcessedLength = data.length; From cc41fa42ba7a1300862b7bc71d6853c66778c49f Mon Sep 17 00:00:00 2001 From: Rasarts Date: Fri, 28 Jul 2017 16:59:02 +0300 Subject: [PATCH 5/5] Remove assert --- lib/mqtt_message_suback.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/mqtt_message_suback.dart b/lib/mqtt_message_suback.dart index b6f92b2..7864ea4 100644 --- a/lib/mqtt_message_suback.dart +++ b/lib/mqtt_message_suback.dart @@ -22,7 +22,7 @@ class MqttMessageSuback extends MqttMessageAssured { * byte 2 - Message ID LSB */ num decodeVariableHeader(List data) { - assert(data.length == 3); + // assert(data.length == 3); messageID = 256 * data[0] + data[1];