shamblett / mqtt_client

A server and browser based MQTT client for dart
Other
548 stars 176 forks source link

AWS IOT - Calling unsubscribe() results in instant disconnection of client connection #188

Closed genjm closed 4 years ago

genjm commented 4 years ago

Afternoon,

I've recently started playing with AWS IOT & have managed to successfully get the client connected using a signed URL & I am able to subscribe to topics & send / receive messages without any issues.

However, when I try to unsubscribe from a topic ( that I have subscribed to ), the client disconnects as soon as the unsubscribe message is sent. If I subscribe to the topic which tracks disconnects, I see the following message:

{ "clientId": "XXXXXXXX", "timestamp": 1591108825531, "eventType": "disconnected", "clientInitiatedDisconnect": false, "sessionIdentifier": "a24e248e-b130-49e0-a106-f553a365517a", "principalIdentifier": "XXXXXXXXXXXXXXX:CognitoIdentityCredentials", "disconnectReason": "CLIENT_ERROR", "versionNumber": 46 }

And with logging enabled on the client, I get the following:

2020-06-02 15:40:25.536 -- MqttConnectionHandlerBase::sendMessage - MQTTMessage of type MqttMessageType.unsubscribe Header: MessageType = MqttMessageType.unsubscribe, Duplicate = false, Retain = false, Qos = MqttQos.atMostOnce, Size = 0 Unsubscribe VariableHeader Variable Header: MessageIdentifier={5} Payload: Unsubscription [{1}] {{ Topic={XXXXXXXXXXXXX}} 2020-06-02 15:40:25.550 -- MqttBrowserConnection::_startListening - websocket is closed 2020-06-02 15:40:25.550 -- MqttBrowserConnection::_onDone - calling disconnected callback

I have tried a variety of topics, both 'AWS Thing' topics, and custom ones but the end result is the same.

The permissions on the AWS side of things are for all 'iot:' calls for all resources ( ), so it shouldn't be a permissions issue, and if it was, I'd expect to see something on the AWS side of things to indicate that.

If you have any ideas about what could be causing this to happen or what I can do to resolve this, please let me know.

Thanks,

James

EDIT

Should have said, I'm using 'mqtt_client 7.1.0' & the current flutter dev channel.

shamblett commented 4 years ago

Off the top of my head it sounds like a version mismatch, please check that the AWS broke protocol version matches that of the client, you can set the client to be 3.1 or 3.1.1, this makes a difference to some brokers.

genjm commented 4 years ago

Literally was about to post this as you replied;

Should have read more of the closed issues, setting the protocol to 3.1.1 has resolved the problem.

Sorry for the unnecessary issue, everything else seems to work great, thanks for all your hard work. :)