shamblett / mqtt_client

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

identifierRejected and a disconnection origin of none #253

Closed 3gcodes closed 3 years ago

3gcodes commented 3 years ago

I know there's a similar issue from 2018 that is closed, but I'm getting the same error. I'm using this as my example code...

https://medium.com/@emqtt/using-mqtt-in-the-flutter-project-6a5d90179c8b

Flutter version info:

Flutter 1.22.6 • channel stable • https://github.com/flutter/flutter.git
Framework • revision 9b2d32b605 (3 weeks ago) • 2021-01-22 14:36:39 -0800
Engine • revision 2f0af37152
Tools • Dart 2.10.5

And getting the following:

I/flutter ( 9784): 2-2021-02-12 20:25:05.602730 -- MqttConnectionHandlerBase::connect - server 192.168.0.34, port 1883
I/flutter ( 9784): 2-2021-02-12 20:25:05.603044 -- SynchronousMqttServerConnectionHandler::internalConnect entered
I/flutter ( 9784): 2-2021-02-12 20:25:05.603131 -- SynchronousMqttServerConnectionHandler::internalConnect - initiating connection try 0, auto reconnect in progress false
I/flutter ( 9784): 2-2021-02-12 20:25:05.603230 -- SynchronousMqttServerConnectionHandler::internalConnect - insecure TCP selected
I/flutter ( 9784): 2-2021-02-12 20:25:05.603668 -- SynchronousMqttServerConnectionHandler::internalConnect - calling connect
I/flutter ( 9784): 2-2021-02-12 20:25:05.603767 -- MqttNormalConnection::connect - entered
I/flutter ( 9784): 2-2021-02-12 20:25:05.662356 -- MqttServerConnection::_startListening
I/flutter ( 9784): 2-2021-02-12 20:25:05.662832 -- SynchronousMqttServerConnectionHandler::internalConnect - connection complete
I/flutter ( 9784): 2-2021-02-12 20:25:05.663126 -- SynchronousMqttServerConnectionHandler::internalConnect sending connect message
I/flutter ( 9784): 2-2021-02-12 20:25:05.663404 -- MqttConnectionHandlerBase::sendMessage - MQTTMessage of type MqttMessageType.connect
I/flutter ( 9784): Header: MessageType = MqttMessageType.connect, Duplicate = false, Retain = false, Qos = MqttQos.atMostOnce, Size = 0
I/flutter ( 9784): Connect Variable Header: ProtocolName=MQIsdp, ProtocolVersion=3, ConnectFlags=Connect Flags: Reserved1=false, CleanStart=true, WillFlag=true, WillQos=MqttQos.atLeastOnce, WillRetain=false, PasswordFlag=false, UserNameFlag=false, KeepAlive=60
I/flutter ( 9784): MqttConnectPayload - client identifier is : 
I/flutter ( 9784): 2-2021-02-12 20:25:05.666395 -- SynchronousMqttServerConnectionHandler::internalConnect - pre sleep, state = Connection status is connecting with return code of noneSpecified and a disconnection origin of none
I/flutter ( 9784): 2-2021-02-12 20:25:05.670081 -- MqttConnection::_onData
I/flutter ( 9784): 2-2021-02-12 20:25:05.670414 -- MqttServerConnection::_onData - message received MQTTMessage of type MqttMessageType.connectAck
I/flutter ( 9784): Header: MessageType = MqttMessageType.connectAck, Duplicate = false, Retain = false, Qos = MqttQos.atMostOnce, Size = 2
I/flutter ( 9784): Connect Variable Header: TopicNameCompressionResponse={0}, ReturnCode={MqttConnectReturnCode.identifierRejected}
I/flutter ( 9784): 2-2021-02-12 20:25:05.670585 -- MqttServerConnection::_onData - message available event fired
I/flutter ( 9784): 2-2021-02-12 20:25:05.671317 -- MqttConnectionHandlerBase::_connectAckProcessor
I/flutter ( 9784): 2-2021-02-12 20:25:05.671420 -- MqttConnectionHandlerBase::_connectAckProcessor connection rejected
I/flutter ( 9784): 2-2021-02-12 20:25:05.671510 -- MqttConnectionHandlerBase::_performConnectionDisconnect entered
I/flutter ( 9784): 2-2021-02-12 20:25:05.671632 -- MqttConnectionHandlerBase:: cancelling connect timer
I/flutter ( 9784): 2-2021-02-12 20:25:05.672389 -- MqttConnectionBase::_onDone - calling disconnected callback
I/flutter ( 9784): 2-2021-02-12 20:25:05.672538 -- SynchronousMqttServerConnectionHandler::internalConnect - post sleep, state = Connection status is disconnected with return code of identifierRejected and a disconnection origin of none
I/flutter ( 9784): 2-2021-02-12 20:25:05.672625 -- SynchronousMqttServerConnectionHandler::internalConnect - initiating connection try 1, auto reconnect in progress false
I/flutter ( 9784): 2-2021-02-12 20:25:05.672687 -- SynchronousMqttServerConnectionHandler::internalConnect - insecure TCP selected
I/flutter ( 9784): 2-2021-02-12 20:25:05.672755 -- SynchronousMqttServerConnectionHandler::internalConnect - calling connect
I/flutter ( 9784): 2-2021-02-12 20:25:05.672805 -- MqttNormalConnection::connect - entered
I/flutter ( 9784): 2-2021-02-12 20:25:05.689565 -- MqttServerConnection::_startListening
I/flutter ( 9784): 2-2021-02-12 20:25:05.690119 -- SynchronousMqttServerConnectionHandler::internalConnect - connection complete
I/flutter ( 9784): 2-2021-02-12 20:25:05.690352 -- SynchronousMqttServerConnectionHandler::internalConnect sending connect message
I/flutter ( 9784): 2-2021-02-12 20:25:05.690550 -- MqttConnectionHandlerBase::sendMessage - MQTTMessage of type MqttMessageType.connect
I/flutter ( 9784): Header: MessageType = MqttMessageType.connect, Duplicate = false, Retain = false, Qos = MqttQos.atMostOnce, Size = 38
I/flutter ( 9784): Connect Variable Header: ProtocolName=MQIsdp, ProtocolVersion=3, ConnectFlags=Connect Flags: Reserved1=false, CleanStart=true, WillFlag=true, WillQos=MqttQos.atLeastOnce, WillRetain=false, PasswordFlag=false, UserNameFlag=false, KeepAlive=60
I/flutter ( 9784): MqttConnectPayload - client identifier is : 
I/flutter ( 9784): 2-2021-02-12 20:25:05.692258 -- SynchronousMqttServerConnectionHandler::internalConnect - pre sleep, state = Connection status is connecting with return code of noneSpecified and a disconnection origin of none
I/flutter ( 9784): 2-2021-02-12 20:25:05.695322 -- MqttConnection::_onData
I/flutter ( 9784): 2-2021-02-12 20:25:05.695474 -- MqttServerConnection::_onData - message received MQTTMessage of type MqttMessageType.connectAck
I/flutter ( 9784): Header: MessageType = MqttMessageType.connectAck, Duplicate = false, Retain = false, Qos = MqttQos.atMostOnce, Size = 2
I/flutter ( 9784): Connect Variable Header: TopicNameCompressionResponse={0}, ReturnCode={MqttConnectReturnCode.identifierRejected}
I/flutter ( 9784): 2-2021-02-12 20:25:05.695566 -- MqttServerConnection::_onData - message available event fired
I/flutter ( 9784): 2-2021-02-12 20:25:05.695650 -- MqttConnectionHandlerBase::_connectAckProcessor
I/flutter ( 9784): 2-2021-02-12 20:25:05.695708 -- MqttConnectionHandlerBase::_connectAckProcessor connection rejected
I/flutter ( 9784): 2-2021-02-12 20:25:05.695777 -- MqttConnectionHandlerBase::_performConnectionDisconnect entered
I/flutter ( 9784): 2-2021-02-12 20:25:05.695836 -- MqttConnectionHandlerBase:: cancelling connect timer
I/flutter ( 9784): 2-2021-02-12 20:25:05.696047 -- MqttConnectionBase::_onDone - calling disconnected callback
I/flutter ( 9784): 2-2021-02-12 20:25:05.696120 -- SynchronousMqttServerConnectionHandler::internalConnect - post sleep, state = Connection status is disconnected with return code of identifierRejected and a disconnection origin of none
I/flutter ( 9784): 2-2021-02-12 20:25:05.696170 -- SynchronousMqttServerConnectionHandler::internalConnect - initiating connection try 2, auto reconnect in progress false
I/flutter ( 9784): 2-2021-02-12 20:25:05.696574 -- SynchronousMqttServerConnectionHandler::internalConnect - insecure TCP selected
I/flutter ( 9784): 2-2021-02-12 20:25:05.696646 -- SynchronousMqttServerConnectionHandler::internalConnect - calling connect
I/flutter ( 9784): 2-2021-02-12 20:25:05.696697 -- MqttNormalConnection::connect - entered
I/flutter ( 9784): 2-2021-02-12 20:25:05.708657 -- MqttServerConnection::_startListening
I/flutter ( 9784): 2-2021-02-12 20:25:05.708823 -- SynchronousMqttServerConnectionHandler::internalConnect - connection complete
I/flutter ( 9784): 2-2021-02-12 20:25:05.708878 -- SynchronousMqttServerConnectionHandler::internalConnect sending connect message
I/flutter ( 9784): 2-2021-02-12 20:25:05.708960 -- MqttConnectionHandlerBase::sendMessage - MQTTMessage of type MqttMessageType.connect
I/flutter ( 9784): Header: MessageType = MqttMessageType.connect, Duplicate = false, Retain = false, Qos = MqttQos.atMostOnce, Size = 38
I/flutter ( 9784): Connect Variable Header: ProtocolName=MQIsdp, ProtocolVersion=3, ConnectFlags=Connect Flags: Reserved1=false, CleanStart=true, WillFlag=true, WillQos=MqttQos.atLeastOnce, WillRetain=false, PasswordFlag=false, UserNameFlag=false, KeepAlive=60
I/flutter ( 9784): MqttConnectPayload - client identifier is : 
I/flutter ( 9784): 2-2021-02-12 20:25:05.709719 -- SynchronousMqttServerConnectionHandler::internalConnect - pre sleep, state = Connection status is connecting with return code of noneSpecified and a disconnection origin of none
I/flutter ( 9784): 2-2021-02-12 20:25:05.713511 -- MqttConnection::_onData
I/flutter ( 9784): 2-2021-02-12 20:25:05.713653 -- MqttServerConnection::_onData - message received MQTTMessage of type MqttMessageType.connectAck
I/flutter ( 9784): Header: MessageType = MqttMessageType.connectAck, Duplicate = false, Retain = false, Qos = MqttQos.atMostOnce, Size = 2
I/flutter ( 9784): Connect Variable Header: TopicNameCompressionResponse={0}, ReturnCode={MqttConnectReturnCode.identifierRejected}
I/flutter ( 9784): 2-2021-02-12 20:25:05.713730 -- MqttServerConnection::_onData - message available event fired
I/flutter ( 9784): 2-2021-02-12 20:25:05.713811 -- MqttConnectionHandlerBase::_connectAckProcessor
I/flutter ( 9784): 2-2021-02-12 20:25:05.713867 -- MqttConnectionHandlerBase::_connectAckProcessor connection rejected
I/flutter ( 9784): 2-2021-02-12 20:25:05.713920 -- MqttConnectionHandlerBase::_performConnectionDisconnect entered
I/flutter ( 9784): 2-2021-02-12 20:25:05.713973 -- MqttConnectionHandlerBase:: cancelling connect timer
I/flutter ( 9784): 2-2021-02-12 20:25:05.716320 -- MqttConnectionBase::_onDone - calling disconnected callback
I/flutter ( 9784): 2-2021-02-12 20:25:05.716455 -- SynchronousMqttServerConnectionHandler::internalConnect - post sleep, state = Connection status is disconnected with return code of identifierRejected and a disconnection origin of none
I/flutter ( 9784): 2-2021-02-12 20:25:05.716550 -- SynchronousMqttServerConnectionHandler::internalConnect failed
I/flutter ( 9784): Exception: mqtt-client::NoConnectionException: The maximum allowed connection attempts ({3}) were exceeded. The broker is not responding to the connection request message correctly The return code is MqttConnectReturnCode.identifierRejected
I/flutter ( 9784): 2-2021-02-12 20:25:05.716842 -- MqttConnectionHandlerBase::disconnect - entered
I/flutter ( 9784): 2-2021-02-12 20:25:05.716915 -- MqttConnectionHandlerBase::_performConnectionDisconnect entered
I/flutter ( 9784): Disconnected
shamblett commented 3 years ago

You are getting a connect ack back with a reason code of 'identifier rejected'.

Looking at the logs you are not setting a client identifier -

I/flutter ( 9784): MqttConnectPayload - client identifier is : 

This will affect some brokers, which broker are you using?

You don't say what number the closed issue is however this seems to not be an error with the client.

3gcodes commented 3 years ago

Thanks for the info. However, I am setting the client id.

MqttServerClient client = MqttServerClient.withPort('192.168.0.34', 'client-1', 1883);

I even tried

client.clientIdentifier = "client-1";

I have tried hivemq and emqx, but giving the same results. I can connect to both using MQTT X. The old issue number is https://github.com/ThomDietrich/miflora-mqtt-daemon/issues/55.

3gcodes commented 3 years ago

Okay, I figured it out. I had to add .withClientIdentifier("client-1") to my MqttConnectionMessage. But I'm unsure why, if I've set it on the client itself.

shamblett commented 3 years ago

Yep, if you supply your own connect message the client identifier you specify in the constructor isn't used, you are expected to supply this yourself as you have discovered. I think this is misleading, its not obvious you need to do this, I'll put a fix in so people don't get caught by this again.

3gcodes commented 3 years ago

Terrific! Thanks.

shamblett commented 3 years ago

Complete, package re published at version 9.1.0.