-
Notifications
You must be signed in to change notification settings - Fork 176
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Instant disconnect when publishing message #53
Comments
Same thing happen on:
Edit: this was due to MQTT version, So changing |
Yes I can reproduce this, I'll have a look at why if fails with a protocol of 311, also the keep alive period is in seconds, so I assume you mean 60, not 6000. |
@shamblett I hope the issue get fixed asap, thanks. |
OK, the client is not setting the correct QOS in the pubrel message, the spec specifies this should be 1(atLeastOnce), the code works OK now with this fix. I'll re-release the client later today/tomorrow. |
Client re-published at 5.0.0, please retest |
Still broken for me, For example i've tried to publish same message two times, but the second time failed (but sometimes i get disconnect on first msg too): 1st msg:
2nd msg:
Now also i get disconnected when trying to subscribe to a topic:
Maybe something is wrong with my MQTT server? I can give you access if you want. |
OK, could you try the above with test.mosquitto.org, this should rule out your broker. |
@shamblett Same thing happens on
Edit: honestly i don't know what happens but it works now. Edit3: I can confirm this library works perfectly with test.mosquitto.org and it seems there is something wrong with my broker |
OK, thanks for your work here, you uncovered a bug that has thus far gone unnoticed. |
@shamblett Could you please check this piece of code on my broker? It's get disconnected when trying to publish to a topic (eg: String clientId = "5bc71e3ea74ad804cc04a856";
String token = "2844865:94da2a801302660754642a85592f7755";
String id = "2844865";
MqttClient client = MqttClient("wss://m4.gap.im/mqtt", clientId);
client.setProtocolV311();
client.keepAlivePeriod = 60;
client.port = 443;
client.useWebSocket = true;
client.logging(on: true);
client.onDisconnected = () {
print("\n\n\n==> Disconnected | Time: ${DateTime.now().toUtc()}\n\n\n");
client.disconnect();
};
client.connectionMessage = MqttConnectMessage()
.authenticateAs(id, token)
.withClientIdentifier(clientId);
client.connectionMessage.startClean();
client.connect()
.then(() async {
client.subscribe("u/$id", MqttQos.exactlyOnce);
await MqttUtilities.asyncSleep(2);
MqttClientPayloadBuilder builder = MqttClientPayloadBuilder();
builder.addString(
json.encode(
{
"type": "msgText",
"data": "TextMessage",
"identifier": Random().nextInt(1000000),
},
),
);
client.publishMessage("u/$id", MqttQos.exactlyOnce, builder.payload);
})
.catch((){
print("Connection failed");
}); |
Yes Ok I'll have a look |
This seems to work Ok for me using your broker credentials above I'm getting no disconnects on publish. |
@shamblett Thanks for your time. Yes you are right, but publish message only works if you do it immediately after making connection. // This Works!
MqttClientPayloadBuilder builder1 = MqttClientPayloadBuilder();
builder1.addString(
json.encode(
{
"type": "msgText",
"data": "Works!",
"identifier": Random().nextInt(1000000),
},
),
);
client.publishMessage("u/$id", MqttQos.exactlyOnce, builder1.payload);
// This will not works because of delay
await MqttUtilities.asyncSleep(2);
MqttClientPayloadBuilder builder2 = MqttClientPayloadBuilder();
builder2.addString(
json.encode(
{
"type": "msgText",
"data": "Not works!",
"identifier": Random().nextInt(1000000),
},
),
);
client.publishMessage("u/$id", MqttQos.exactlyOnce, builder2.payload); Connection is stable, i don't know what happens.
|
OK thanks I'll have another look |
Ok, I'm getting bad username or password authing to your broker, however if I use mosquitto wss broker it all seems to be fine, I've put the pubsub in a loop, I can do this an number of times, 10 at the mo and it all works Ok, no unexpected disconnects. |
Sorry for that, I've updated token. Please kindly test it again. |
The client works good with secure tcp! |
Unfortunately, the same for me here my code
and some logs
|
Ok, I found the error... It seems like AWS IOT does not like some header that it sent... Changing To any other MqttQos, solves the problem... Example:
No idea how I could fix it though |
Check the MQTT version you are using im not sure what aws uses but you must set the client vearsion to match, try setting it to 3.1.1 |
Refer to this issue |
@RicardoRB Llevaba dias tratando de solucionar ese problema.. y ha sido tu respuesta la que me ha salvado T-T GRACIAAAAAAAAAAAAAS 😭 ❤️ |
Description:
I've got instantly disconnect when publishing any message.
Here is how i make a connection made:
Message:
Call stack to _onDone:
The text was updated successfully, but these errors were encountered: