Code Monkey home page Code Monkey logo

Comments (6)

shamblett avatar shamblett commented on August 30, 2024

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.

from mqtt_client.

HabilaHC avatar HabilaHC commented on August 30, 2024

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....

from mqtt_client.

shamblett avatar shamblett commented on August 30, 2024

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);

from mqtt_client.

HabilaHC avatar HabilaHC commented on August 30, 2024

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!

from mqtt_client.

iulian0512 avatar iulian0512 commented on August 30, 2024

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.

from mqtt_client.

hao47 avatar hao47 commented on August 30, 2024

please help

from mqtt_client.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.