shamblett / mqtt_client

A server and browser based MQTT client for dart
Other
552 stars 179 forks source link

The broker is not responding to the connection request message (Missing Connection Acknowledgement? #440

Closed HabilaHC closed 1 year ago

HabilaHC commented 1 year ago

Hi fellows, I need to connect to AWS broker, however, it is showing an exception (mqtt-client::NoConnectionException). I've tried inserting another setup to MqttConnectMessage, still showing the exception, May you help me, please? Code and the loggings bellow

/*

import 'dart:async'; import 'dart:io'; import 'package:flutter/services.dart'; import 'package:mqtt_client/mqtt_server_client.dart'; import 'package:mqtt_client/mqtt_client.dart';

/// An example of connecting to the AWS IoT Core MQTT broker and publishing to a devices topic. /// This example uses MQTT on port 8883 using certificites /// More instructions can be found at https://docs.aws.amazon.com/iot/latest/developerguide/mqtt.html and /// https://docs.aws.amazon.com/iot/latest/developerguide/protocols.html, please read this /// before setting up and running this example. Future readPoint() async { // Your AWS IoT Core endpoint url const url = 'a3vd2md0ix5msi-ats.iot.us-east-1.amazonaws.com'; // AWS IoT MQTT default port const port = 8883; // The client id unique to your device const clientId = 'FlutterThing';

// Create the client final client = MqttServerClient.withPort(url, clientId, port);

// Set secure client.secure = true; // Set Keep-Alive client.keepAlivePeriod = 20; // Set the protocol to V3.1.1 for AWS IoT Core, if you fail to do this you will not receive a connect ack with the response code // client.setProtocolV311();

// logging if you wish client.logging(on: true); client.acknowledgeQos1Message(MqttPublishMessage());

// Set the security context as you need, note this is the standard Dart SecurityContext class. // If this is incorrect the TLS handshake will abort and a Handshake exception will be raised, // no connect ack message will be received and the broker will disconnect. // For AWS IoT Core, we need to set the AWS Root CA, device cert & device private key // Note that for Flutter users the parameters above can be set in byte format rather than file paths final context = SecurityContext.defaultContext; final List pathCa = (await rootBundle.load('assets/certs/AmazonRootCA1.pem')).buffer.asInt8List(); final List pathCert = (await rootBundle.load('assets/certs/8dd6a09012c45dd3ec039330b7d0f09a8402548e7379e7aa5fa67f3251797d5e-certificate.pem.crt')).buffer.asInt8List(); final List pathkey = (await rootBundle.load('assets/certs/8dd6a09012c45dd3ec039330b7d0f09a8402548e7379e7aa5fa67f3251797d5e-private.pem.key')).buffer.asInt8List();

context.setClientAuthoritiesBytes(pathCa); context.useCertificateChainBytes(pathCert); context.usePrivateKeyBytes(pathkey); client.securityContext = context;

// Setup the connection Message final connMess = MqttConnectMessage() .withWillRetain() .withWillQos(MqttQos.atMostOnce);

client.connectionMessage = connMess;

// Connect the client try { print('MQTT client connecting to AWS IoT using certificates....'); await client.connect(); } on Exception catch (e) { print('MQTT client exception - $e'); client.disconnect();

}

if (client.connectionStatus!.state == MqttConnectionState.connected) { print('MQTT client connected to AWS IoT');

// Publish to a topic of your choice after a slight delay, AWS seems to need this
await MqttUtilities.asyncSleep(1);
const topic = 'teste/topic';
final builder = MqttClientPayloadBuilder();
builder.addString('Hello World');
// Important: AWS IoT Core can only handle QOS of 0 or 1. QOS 2 (exactlyOnce) will fail!
client.publishMessage(topic, MqttQos.atLeastOnce, builder.payload!);

// Subscribe to the same topic
client.subscribe(topic, MqttQos.atLeastOnce);
// Print incoming messages from another client on this topic
client.updates!.listen((List<MqttReceivedMessage<MqttMessage>> c) {
  final recMess = c[0].payload as MqttPublishMessage;
  final pt =
  MqttPublishPayload.bytesToStringAsString(recMess.payload.message);
  print(
      'EXAMPLE::Change notification:: topic is <${c[0].topic}>, payload is <-- $pt -->');
  print('');
});

} else { print( 'ERROR MQTT client connection failed - disconnecting, state is ${client.connectionStatus!.state}'); client.disconnect(); }

print('Sleeping....'); await MqttUtilities.asyncSleep(10);

print('Disconnecting'); client.disconnect();

return 0; }

I/flutter (12154): MQTT client connecting to AWS IoT using certificates.... I/flutter (12154): 10-2023-01-19 14:18:15.648609 -- MqttClient::connect - Connection timeout period is 5000 milliseconds I/flutter (12154): 10-2023-01-19 14:18:15.648736 -- MqttClient::connect - keep alive is enabled with a value of 20 seconds I/flutter (12154): 10-2023-01-19 14:18:15.649305 -- MqttConnectionKeepAlive:: Initialised with a keep alive value of 20 seconds I/flutter (12154): 10-2023-01-19 14:18:15.649378 -- MqttConnectionKeepAlive:: Disconnect on no ping response is disabled I/flutter (12154): 10-2023-01-19 14:18:15.649443 -- MqttConnectionHandlerBase::connect - server a3vd2md0ix5msi-ats.iot.us-east-1.amazonaws.com, port 8883 I/flutter (12154): 10-2023-01-19 14:18:15.649507 -- SynchronousMqttServerConnectionHandler::internalConnect entered I/flutter (12154): 10-2023-01-19 14:18:15.649563 -- SynchronousMqttServerConnectionHandler::internalConnect - initiating connection try 0, auto reconnect in progress false I/flutter (12154): 10-2023-01-19 14:18:15.649630 -- SynchronousMqttServerConnectionHandler::internalConnect - secure selected I/flutter (12154): 10-2023-01-19 14:18:15.649685 -- SynchronousMqttServerConnectionHandler::internalConnect - calling connect I/flutter (12154): 10-2023-01-19 14:18:15.650239 -- MqttSecureConnection::connect - entered I/flutter (12154): 10-2023-01-19 14:18:16.165142 -- MqttSecureConnection::connect - securing socket I/flutter (12154): 10-2023-01-19 14:18:16.165385 -- MqttSecureConnection::connect - start listening I/flutter (12154): 10-2023-01-19 14:18:16.165489 -- MqttServerConnection::_startListening I/flutter (12154): 10-2023-01-19 14:18:16.165585 -- SynchronousMqttServerConnectionHandler::internalConnect - connection complete I/flutter (12154): 10-2023-01-19 14:18:16.165657 -- SynchronousMqttServerConnectionHandler::internalConnect sending connect message I/flutter (12154): 10-2023-01-19 14:18:16.165708 -- MqttConnectionHandlerBase::sendMessage - MQTTMessage of type MqttMessageType.connect I/flutter (12154): Header: MessageType = MqttMessageType.connect, Duplicate = false, Retain = false, Qos = MqttQos.atMostOnce, Size = 0 I/flutter (12154): Connect Variable Header: ProtocolName=MQTT, ProtocolVersion=4, ConnectFlags=Connect Flags: Reserved1=false, CleanStart=false, WillFlag=false, WillQos=MqttQos.atMostOnce, WillRetain=true, PasswordFlag=false, UserNameFlag=false, KeepAlive=20 I/flutter (12154): MqttConnectPayload - client identifier is : FlutterThing I/flutter (12154): 10-2023-01-19 14:18:16.165930 -- SynchronousMqttServerConnectionHandler::internalConnect - pre sleep, state = Connection status is connecting with return code of noneSpecified and a disconnection origin of none I/flutter (12154): 10-2023-01-19 14:18:18.368565 -- MqttConnectionBase::_onDone - calling disconnected callback I/flutter (12154): 10-2023-01-19 14:18:21.169213 -- SynchronousMqttServerConnectionHandler::internalConnect - post sleep, state = Connection status is connecting with return code of noneSpecified and a disconnection origin of none I/flutter (12154): 10-2023-01-19 14:18:21.169393 -- SynchronousMqttServerConnectionHandler::internalConnect - initiating connection try 1, auto reconnect in progress false I/flutter (12154): 10-2023-01-19 14:18:21.169459 -- SynchronousMqttServerConnectionHandler::internalConnect - secure selected I/flutter (12154): 10-2023-01-19 14:18:21.169580 -- SynchronousMqttServerConnectionHandler::internalConnect - calling connect I/flutter (12154): 10-2023-01-19 14:18:21.169679 -- MqttSecureConnection::connect - entered I/flutter (12154): 10-2023-01-19 14:18:21.638096 -- MqttSecureConnection::connect - securing socket I/flutter (12154): 10-2023-01-19 14:18:21.638650 -- MqttSecureConnection::connect - start listening I/flutter (12154): 10-2023-01-19 14:18:21.638934 -- MqttServerConnection::_startListening I/flutter (12154): 10-2023-01-19 14:18:21.639060 -- SynchronousMqttServerConnectionHandler::internalConnect - connection complete I/flutter (12154): 10-2023-01-19 14:18:21.639263 -- SynchronousMqttServerConnectionHandler::internalConnect sending connect message I/flutter (12154): 10-2023-01-19 14:18:21.639457 -- MqttConnectionHandlerBase::sendMessage - MQTTMessage of type MqttMessageType.connect I/flutter (12154): Header: MessageType = MqttMessageType.connect, Duplicate = false, Retain = false, Qos = MqttQos.atMostOnce, Size = 24 I/flutter (12154): Connect Variable Header: ProtocolName=MQTT, ProtocolVersion=4, ConnectFlags=Connect Flags: Reserved1=false, CleanStart=false, WillFlag=false, WillQos=MqttQos.atMostOnce, WillRetain=true, PasswordFlag=false, UserNameFlag=false, KeepAlive=20 I/flutter (12154): MqttConnectPayload - client identifier is : FlutterThing I/flutter (12154): 10-2023-01-19 14:18:21.639929 -- SynchronousMqttServerConnectionHandler::internalConnect - pre sleep, state = Connection status is connecting with return code of noneSpecified and a disconnection origin of none I/flutter (12154): 10-2023-01-19 14:18:23.321482 -- MqttConnectionKeepAlive::pingRequired I/flutter (12154): 10-2023-01-19 14:18:23.323 -- MqttConnectionKeepAlive::pingRequired - sending ping request I/flutter (12154): 10-2023-01-19 14:18:23.323263 -- MqttConnectionHandlerBase::sendMessage - MQTTMessage of type MqttMessageType.pingRequest I/flutter (12154): Header: MessageType = MqttMessageType.pingRequest, Duplicate = false, Retain = false, Qos = MqttQos.atMostOnce, Size = 0 I/flutter (12154): 10-2023-01-19 14:18:23.323521 -- MqttConnectionKeepAlive::pingRequired - restarting ping timer I/flutter (12154): 10-2023-01-19 14:18:23.656975 -- MqttConnection::onData I/flutter (12154): 10-2023-01-19 14:18:23.660280 -- MqttServerConnection::_onData - message received MQTTMessage of type MqttMessageType.pingResponse I/flutter (12154): Header: MessageType = MqttMessageType.pingResponse, Duplicate = false, Retain = false, Qos = MqttQos.atMostOnce, Size = 0 I/flutter (12154): 10-2023-01-19 14:18:23.660753 -- MqttServerConnection::_onData - message available event fired I/flutter (12154): 10-2023-01-19 14:18:23.660989 -- MqttConnectionHandlerBase::messageAvailable - message type is MqttMessageType.pingResponse I/flutter (12154): 10-2023-01-19 14:18:23.661152 -- MqttConnectionKeepAlive::pingResponseReceived I/flutter (12154): 10-2023-01-19 14:18:23.827297 -- MqttConnectionBase::_onDone - calling disconnected callback I/flutter (12154): 10-2023-01-19 14:18:26.642551 -- SynchronousMqttServerConnectionHandler::internalConnect - post sleep, state = Connection status is connecting with return code of noneSpecified and a disconnection origin of none I/flutter (12154): 10-2023-01-19 14:18:26.642743 -- SynchronousMqttServerConnectionHandler::internalConnect - initiating connection try 2, auto reconnect in progress false I/flutter (12154): 10-2023-01-19 14:18:26.642901 -- SynchronousMqttServerConnectionHandler::internalConnect - secure selected I/flutter (12154): 10-2023-01-19 14:18:26.643016 -- SynchronousMqttServerConnectionHandler::internalConnect - calling connect I/flutter (12154): 10-2023-01-19 14:18:26.643183 -- MqttSecureConnection::connect - entered I/flutter (12154): 10-2023-01-19 14:18:27.111294 -- MqttSecureConnection::connect - securing socket I/flutter (12154): 10-2023-01-19 14:18:27.111479 -- MqttSecureConnection::connect - start listening I/flutter (12154): 10-2023-01-19 14:18:27.111551 -- MqttServerConnection::_startListening I/flutter (12154): 10-2023-01-19 14:18:27.111681 -- SynchronousMqttServerConnectionHandler::internalConnect - connection complete I/flutter (12154): 10-2023-01-19 14:18:27.111974 -- SynchronousMqttServerConnectionHandler::internalConnect sending connect message I/flutter (12154): 10-2023-01-19 14:18:27.112093 -- MqttConnectionHandlerBase::sendMessage - MQTTMessage of type MqttMessageType.connect I/flutter (12154): Header: MessageType = MqttMessageType.connect, Duplicate = false, Retain = false, Qos = MqttQos.atMostOnce, Size = 24 I/flutter (12154): Connect Variable Header: ProtocolName=MQTT, ProtocolVersion=4, ConnectFlags=Connect Flags: Reserved1=false, CleanStart=false, WillFlag=false, WillQos=MqttQos.atMostOnce, WillRetain=true, PasswordFlag=false, UserNameFlag=false, KeepAlive=20 I/flutter (12154): MqttConnectPayload - client identifier is : FlutterThing I/flutter (12154): 10-2023-01-19 14:18:27.112313 -- SynchronousMqttServerConnectionHandler::internalConnect - pre sleep, state = Connection status is connecting with return code of noneSpecified and a disconnection origin of none I/flutter (12154): 10-2023-01-19 14:18:29.298401 -- MqttConnectionBase::_onDone - calling disconnected callback I/flutter (12154): 10-2023-01-19 14:18:32.116416 -- SynchronousMqttServerConnectionHandler::internalConnect - post sleep, state = Connection status is connecting with return code of noneSpecified and a disconnection origin of none I/flutter (12154): 10-2023-01-19 14:18:32.116602 -- SynchronousMqttServerConnectionHandler::internalConnect failed I/flutter (12154): MQTT client exception - mqtt-client::NoConnectionException: The maximum allowed connection attempts ({3}) were exceeded. The broker is not responding to the connection request message (Missing Connection Acknowledgement? I/flutter (12154): 10-2023-01-19 14:18:32.116920 -- MqttConnectionHandlerBase::disconnect - entered I/flutter (12154): 10-2023-01-19 14:18:32.116993 -- MqttConnectionHandlerBase::_performConnectionDisconnect entered I/flutter (12154): 10-2023-01-19 14:18:32.117062 -- MqttConnectionKeepAlive::stop - stopping keep alive I/flutter (12154): ERROR MQTT client connection failed - disconnecting, state is MqttConnectionState.disconnected I/flutter (12154): Sleeping....

shamblett commented 1 year ago

OK, you are connecting to the broker and sending a connect message -

I/flutter (12154): 10-2023-01-19 14:18:21.639457 -- MqttConnectionHandlerBase::sendMessage - MQTTMessage of type MqttMessageType.connect

The broker is then disconnecting you

This is usually an indication of a protocol error. I can see this from your code above -

// Set the protocol to V3.1.1 for AWS IoT Core, if you fail to do this you will not receive a connect ack with the response code
// client.setProtocolV311();

You need to uncomment the line that sets the protocol to V3.1.1, see what happens then.

HabilaHC commented 1 year ago

OK, you are connecting to the broker and sending a connect message -

I/flutter (12154): 10-2023-01-19 14:18:21.639457 -- MqttConnectionHandlerBase::sendMessage - MQTTMessage of type MqttMessageType.connect

The broker is then disconnecting you

This is usually an indication of a protocol error. I can see this from your code above -

// Set the protocol to V3.1.1 for AWS IoT Core, if you fail to do this you will not receive a connect ack with the response code
// client.setProtocolV311();

You need to uncomment the line that sets the protocol to V3.1.1, see what happens then.

I've uncommented that line and also tried with protocol to V3.1, all of them returned the same result,

logging uncommented protocol to V3.1.1: I/flutter (13077): MQTT client connecting to AWS IoT using certificates.... I/flutter (13077): 1-2023-01-19 17:57:26.570182 -- MqttClient::connect - Connection timeout period is 5000 milliseconds I/flutter (13077): 1-2023-01-19 17:57:26.579198 -- MqttClient::connect - keep alive is enabled with a value of 20 seconds I/flutter (13077): 1-2023-01-19 17:57:26.581707 -- MqttConnectionKeepAlive:: Initialised with a keep alive value of 20 seconds I/flutter (13077): 1-2023-01-19 17:57:26.582136 -- MqttConnectionKeepAlive:: Disconnect on no ping response is disabled I/flutter (13077): 1-2023-01-19 17:57:26.585354 -- MqttConnectionHandlerBase::connect - server a3vd2md0ix5msi-ats.iot.us-east-1.amazonaws.com, port 8883 I/flutter (13077): 1-2023-01-19 17:57:26.587974 -- SynchronousMqttServerConnectionHandler::internalConnect entered I/flutter (13077): 1-2023-01-19 17:57:26.588181 -- SynchronousMqttServerConnectionHandler::internalConnect - initiating connection try 0, auto reconnect in progress false I/flutter (13077): 1-2023-01-19 17:57:26.588515 -- SynchronousMqttServerConnectionHandler::internalConnect - secure selected I/flutter (13077): 1-2023-01-19 17:57:26.590829 -- SynchronousMqttServerConnectionHandler::internalConnect - calling connect I/flutter (13077): 1-2023-01-19 17:57:26.591407 -- MqttSecureConnection::connect - entered I/flutter (13077): 1-2023-01-19 17:57:27.127415 -- MqttSecureConnection::connect - securing socket I/flutter (13077): 1-2023-01-19 17:57:27.130318 -- MqttSecureConnection::connect - start listening I/flutter (13077): 1-2023-01-19 17:57:27.132408 -- MqttServerConnection::_startListening I/flutter (13077): 1-2023-01-19 17:57:27.135641 -- SynchronousMqttServerConnectionHandler::internalConnect - connection complete I/flutter (13077): 1-2023-01-19 17:57:27.135834 -- SynchronousMqttServerConnectionHandler::internalConnect sending connect message I/flutter (13077): 1-2023-01-19 17:57:27.136179 -- MqttConnectionHandlerBase::sendMessage - MQTTMessage of type MqttMessageType.connect I/flutter (13077): Header: MessageType = MqttMessageType.connect, Duplicate = false, Retain = false, Qos = MqttQos.atMostOnce, Size = 0 I/flutter (13077): Connect Variable Header: ProtocolName=MQTT, ProtocolVersion=4, ConnectFlags=Connect Flags: Reserved1=false, CleanStart=false, WillFlag=false, WillQos=MqttQos.atMostOnce, WillRetain=true, PasswordFlag=false, UserNameFlag=false, KeepAlive=20 I/flutter (13077): MqttConnectPayload - client identifier is : FlutterThing I/flutter (13077): 1-2023-01-19 17:57:27.148816 -- SynchronousMqttServerConnectionHandler::internalConnect - pre sleep, state = Connection status is connecting with return code of noneSpecified and a disconnection origin of none I/flutter (13077): 1-2023-01-19 17:57:29.350259 -- MqttConnectionBase::_onDone - calling disconnected callback I/flutter (13077): 1-2023-01-19 17:57:32.155270 -- SynchronousMqttServerConnectionHandler::internalConnect - post sleep, state = Connection status is connecting with return code of noneSpecified and a disconnection origin of none I/flutter (13077): 1-2023-01-19 17:57:32.156238 -- SynchronousMqttServerConnectionHandler::internalConnect - initiating connection try 1, auto reconnect in progress false I/flutter (13077): 1-2023-01-19 17:57:32.157922 -- SynchronousMqttServerConnectionHandler::internalConnect - secure selected I/flutter (13077): 1-2023-01-19 17:57:32.158149 -- SynchronousMqttServerConnectionHandler::internalConnect - calling connect I/flutter (13077): 1-2023-01-19 17:57:32.158387 -- MqttSecureConnection::connect - entered I/flutter (13077): 1-2023-01-19 17:57:32.613729 -- MqttSecureConnection::connect - securing socket I/flutter (13077): 1-2023-01-19 17:57:32.613919 -- MqttSecureConnection::connect - start listening I/flutter (13077): 1-2023-01-19 17:57:32.614181 -- MqttServerConnection::_startListening I/flutter (13077): 1-2023-01-19 17:57:32.614406 -- SynchronousMqttServerConnectionHandler::internalConnect - connection complete I/flutter (13077): 1-2023-01-19 17:57:32.614810 -- SynchronousMqttServerConnectionHandler::internalConnect sending connect message I/flutter (13077): 1-2023-01-19 17:57:32.615069 -- MqttConnectionHandlerBase::sendMessage - MQTTMessage of type MqttMessageType.connect I/flutter (13077): Header: MessageType = MqttMessageType.connect, Duplicate = false, Retain = false, Qos = MqttQos.atMostOnce, Size = 24 I/flutter (13077): Connect Variable Header: ProtocolName=MQTT, ProtocolVersion=4, ConnectFlags=Connect Flags: Reserved1=false, CleanStart=false, WillFlag=false, WillQos=MqttQos.atMostOnce, WillRetain=true, PasswordFlag=false, UserNameFlag=false, KeepAlive=20 I/flutter (13077): MqttConnectPayload - client identifier is : FlutterThing I/flutter (13077): 1-2023-01-19 17:57:32.615504 -- SynchronousMqttServerConnectionHandler::internalConnect - pre sleep, state = Connection status is connecting with return code of noneSpecified and a disconnection origin of none I/flutter (13077): 1-2023-01-19 17:57:34.804402 -- MqttConnectionBase::_onDone - calling disconnected callback I/flutter (13077): 1-2023-01-19 17:57:37.618472 -- SynchronousMqttServerConnectionHandler::internalConnect - post sleep, state = Connection status is connecting with return code of noneSpecified and a disconnection origin of none I/flutter (13077): 1-2023-01-19 17:57:37.620211 -- SynchronousMqttServerConnectionHandler::internalConnect - initiating connection try 2, auto reconnect in progress false I/flutter (13077): 1-2023-01-19 17:57:37.622382 -- SynchronousMqttServerConnectionHandler::internalConnect - secure selected I/flutter (13077): 1-2023-01-19 17:57:37.623833 -- SynchronousMqttServerConnectionHandler::internalConnect - calling connect I/flutter (13077): 1-2023-01-19 17:57:37.625868 -- MqttSecureConnection::connect - entered I/flutter (13077): 1-2023-01-19 17:57:38.088066 -- MqttSecureConnection::connect - securing socket I/flutter (13077): 1-2023-01-19 17:57:38.088235 -- MqttSecureConnection::connect - start listening I/flutter (13077): 1-2023-01-19 17:57:38.088324 -- MqttServerConnection::_startListening I/flutter (13077): 1-2023-01-19 17:57:38.088416 -- SynchronousMqttServerConnectionHandler::internalConnect - connection complete I/flutter (13077): 1-2023-01-19 17:57:38.088478 -- SynchronousMqttServerConnectionHandler::internalConnect sending connect message I/flutter (13077): 1-2023-01-19 17:57:38.088553 -- MqttConnectionHandlerBase::sendMessage - MQTTMessage of type MqttMessageType.connect I/flutter (13077): Header: MessageType = MqttMessageType.connect, Duplicate = false, Retain = false, Qos = MqttQos.atMostOnce, Size = 24 I/flutter (13077): Connect Variable Header: ProtocolName=MQTT, ProtocolVersion=4, ConnectFlags=Connect Flags: Reserved1=false, CleanStart=false, WillFlag=false, WillQos=MqttQos.atMostOnce, WillRetain=true, PasswordFlag=false, UserNameFlag=false, KeepAlive=20 I/flutter (13077): MqttConnectPayload - client identifier is : FlutterThing I/flutter (13077): 1-2023-01-19 17:57:38.088738 -- SynchronousMqttServerConnectionHandler::internalConnect - pre sleep, state = Connection status is connecting with return code of noneSpecified and a disconnection origin of none I/flutter (13077): 1-2023-01-19 17:57:40.270702 -- MqttConnectionBase::_onDone - calling disconnected callback I/flutter (13077): 1-2023-01-19 17:57:43.093511 -- SynchronousMqttServerConnectionHandler::internalConnect - post sleep, state = Connection status is connecting with return code of noneSpecified and a disconnection origin of none I/flutter (13077): 1-2023-01-19 17:57:43.093757 -- SynchronousMqttServerConnectionHandler::internalConnect failed I/flutter (13077): MQTT client exception - mqtt-client::NoConnectionException: The maximum allowed connection attempts ({3}) were exceeded. The broker is not responding to the connection request message (Missing Connection Acknowledgement? I/flutter (13077): 1-2023-01-19 17:57:43.097536 -- MqttConnectionHandlerBase::disconnect - entered I/flutter (13077): 1-2023-01-19 17:57:43.097810 -- MqttConnectionHandlerBase::_performConnectionDisconnect entered I/flutter (13077): 1-2023-01-19 17:57:43.100565 -- MqttConnectionKeepAlive::stop - stopping keep alive I/flutter (13077): ERROR MQTT client connection failed - disconnecting, state is MqttConnectionState.disconnected I/flutter (13077): Sleeping....

shamblett commented 1 year ago

OK, leave the protocol at 3.1.1 and strip down your connect message to its basic form, i.e. remove these -

.withWillRetain()
.withWillQos(MqttQos.atMostOnce);
HabilaHC commented 1 year ago

OK, leave the protocol at 3.1.1 and strip down your connect message to its basic form, i.e. remove these -

.withWillRetain()
.withWillQos(MqttQos.atMostOnce);

Hi Steve,

I found out what was happening. It was an error in the AWS IoT policy. The policy was not allowing the connection. Thank you for the help finding out the problem!

iulian0512 commented 1 year ago

OK, leave the protocol at 3.1.1 and strip down your connect message to its basic form, i.e. remove these -

.withWillRetain()
.withWillQos(MqttQos.atMostOnce);

this fixed my issue, i had mosquitto 2.0.15 on localhost ubuntu 20 without 'will' it works as expected.

hao47 commented 7 months ago

please help