Comments (23)
Ok, I found the error...
It seems like AWS IOT does not like some header that it sent...
Changing
client.subscribe(topic, MqttQos.exactlyOnce);
To any other MqttQos, solves the problem... Example:
client.subscribe(topic, MqttQos.atLeastOnce);
No idea how I could fix it though
from mqtt_client.
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.
from mqtt_client.
Yes Ok I'll have a look
from mqtt_client.
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.
from mqtt_client.
OK, thanks for your work here, you uncovered a bug that has thus far gone unnoticed.
from mqtt_client.
OK thanks I'll have another look
from mqtt_client.
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.
from mqtt_client.
Ok, I found the error...
It seems like AWS IOT does not like some header that it is sent...
Changing
client.subscribe(topic, MqttQos.exactlyOnce);
To any other MqttQos, solves the problem... Example:
client.subscribe(topic, MqttQos.atLeastOnce);
No idea how I could fix it though
@RicardoRB Llevaba dias tratando de solucionar ese problema.. y ha sido tu respuesta la que me ha salvado T-T GRACIAAAAAAAAAAAAAS π β€οΈ
from mqtt_client.
Same thing happen on:
server: test.mosquitto.org
port: 1883
useWebSocket: false
Edit: this was due to MQTT version, So changing client.setProtocolV311()
to client.setProtocolV31()
fixes the problem but still i have problem with my local server
from mqtt_client.
@shamblett I hope the issue get fixed asap, thanks.
I know keepAlive is in MS but im going to keep my connection always alive ( + a reconnect logic on connection lost ).
from mqtt_client.
Client re-published at 5.0.0, please retest
from mqtt_client.
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:
I/flutter ( 6935): ==> MQTT: Publishing - Topic: u/1382327/884063
I/flutter ( 6935): 2018-11-27 09:17:29.117740 -- MqttConnectionHandler::sendMessage - MQTTMessage of type MqttMessageType.publish
I/flutter ( 6935): Header: MessageType = MqttMessageType.publish, Duplicate = false, Retain = false, Qos = MqttQos.atMostOnce, Size = 0
I/flutter ( 6935): Publish Variable Header: TopicName={u/1382327/884063}, MessageIdentifier={20}, VH Length={0}
I/flutter ( 6935): Payload: {63 bytes={<123><34><116><121><112><101><34><58><34><109><115><103><84><101><120><116><34><44><34><100><97><116><97><34><58><34><116><101><115><116><34><44><34><105><100><101><110><116><105><102><105><101><114><34><58><34><49><53><52><51><50><57><55><54><52><57><49><49><52><58><49><34><125>
I/flutter ( 6935): 2018-11-27 09:17:29.165945 -- MqttConnection::_onData
I/flutter ( 6935): 2018-11-27 09:17:29.166318 -- MqttConnection::_onData - message received MQTTMessage of type MqttMessageType.publish
I/flutter ( 6935): Header: MessageType = MqttMessageType.publish, Duplicate = false, Retain = false, Qos = MqttQos.atMostOnce, Size = 176
I/flutter ( 6935): Publish Variable Header: TopicName={u/1382327/884063}, MessageIdentifier={0}, VH Length={18}
I/flutter ( 6935): Payload: {158 bytes={<123><34><100><97><116><97><34><58><34><116><101><115><116><34><44><34><102><114><111><109><34><58><123><34><105><100><34><58><56><56><52><48><54><51><44><34><110><97><109><101><34><58><34><77><111><101><105><110><34><44><34><117><115><101><114><34><58><34><116><106><101><51><100><34><125><44><34><105><100><34><58><51><52><56><48><44><34><105><100><101><110><116><105><102><105><101><114><34><58><34><49><53><52><51><50><57><55><54><52><57><49><49><52><58><49><34><44><34><116><105><109><101><34><58><49><53><52><51><50><57><55><54><53><48><49><49><51><44><34><116><111><34><58><55><52><54><48><48><50><57><44><34><116><121><112><101><34><58><34><109><115><103><84><101><
I/flutter ( 6935): 2018-11-27 09:17:29.166451 -- MqttConnection::_onData - message processed
I/flutter ( 6935): 2018-11-27 09:17:42.421266 -- MqttConnection::_onData
I/flutter ( 6935): 2018-11-27 09:17:42.421721 -- MqttConnection::_onData - message received MQTTMessage of type MqttMessageType.publish
I/flutter ( 6935): Header: MessageType = MqttMessageType.publish, Duplicate = false, Retain = true, Qos = MqttQos.atLeastOnce, Size = 28
I/flutter ( 6935): Publish Variable Header: TopicName={p/884063/o}, MessageIdentifier={98}, VH Length={14}
I/flutter ( 6935): Payload: {14 bytes={<110><111><119><44><49><53><52><51><50><57><55><54><54><51>
I/flutter ( 6935): 2018-11-27 09:17:42.421868 -- MqttConnection::_onData - message processed
I/flutter ( 6935): 2018-11-27 09:17:42.422106 -- MqttConnectionHandler::sendMessage - MQTTMessage of type MqttMessageType.publishAck
I/flutter ( 6935): Header: MessageType = MqttMessageType.publishAck, Duplicate = false, Retain = false, Qos = MqttQos.atMostOnce, Size = 0
I/flutter ( 6935): PublishAck Variable Header: MessageIdentifier={98}
2nd msg:
I/flutter ( 6935): ==> MQTT: Publishing - Topic: u/1382327/884063
I/flutter ( 6935): 2018-11-27 09:17:49.499703 -- MqttConnectionHandler::sendMessage - MQTTMessage of type MqttMessageType.publish
I/flutter ( 6935): Header: MessageType = MqttMessageType.publish, Duplicate = false, Retain = false, Qos = MqttQos.atMostOnce, Size = 0
I/flutter ( 6935): Publish Variable Header: TopicName={u/1382327/884063}, MessageIdentifier={21}, VH Length={0}
I/flutter ( 6935): Payload: {64 bytes={<123><34><116><121><112><101><34><58><34><109><115><103><84><101><120><116><34><44><34><100><97><116><97><34><58><34><116><101><115><116><50><34><44><34><105><100><101><110><116><105><102><105><101><114><34><58><34><49><53><52><51><50><57><55><54><54><57><52><57><57><58><50><34><125>
I/flutter ( 6935): 2018-11-27 09:17:49.531567 -- MqttConnection::_onDone - calling disconnected callback
I/flutter ( 6935): ==> MQTT: Disconnected, Was Self: false
I/flutter ( 6935): 2018-11-27 09:17:49.532419 -- SynchronousMqttConnectionHandler::disconnect
I/flutter ( 6935): 2018-11-27 09:17:49.532758 -- MqttConnectionHandler::sendMessage - MQTTMessage of type MqttMessageType.disconnect
I/flutter ( 6935): Header: MessageType = MqttMessageType.disconnect, Duplicate = false, Retain = false, Qos = MqttQos.atMostOnce, Size = 0
I/flutter ( 6935): 2018-11-27 09:17:49.532839 -- MqttConnectionHandler::sendMessage - not connected
I/flutter ( 6935): 2018-11-27 09:17:49.535477 -- SynchronousMqttConnectionHandler::internalConnect entered
I/flutter ( 6935): 2018-11-27 09:17:49.535569 -- SynchronousMqttConnectionHandler::internalConnect - initiating connection try 0
I/flutter ( 6935): 2018-11-27 09:17:49.535611 -- SynchronousMqttConnectionHandler::internalConnect - websocket selected
I/flutter ( 6935): 2018-11-27 09:17:49.535684 -- MqttWsConnection:: WS URL is wss://server:443/mqtt
I/flutter ( 6935): 2018-11-27 09:17:49.909795 -- MqttConnection::_startListening
I/flutter ( 6935): 2018-11-27 09:17:49.911496 -- SynchronousMqttConnectionHandler::internalConnect sending connect message
I/flutter ( 6935): 2018-11-27 09:17:49.912996 -- MqttConnectionHandler::sendMessage - MQTTMessage of type MqttMessageType.connect
I/flutter ( 6935): Header: MessageType = MqttMessageType.connect, Duplicate = false, Retain = false, Qos = MqttQos.atMostOnce, Size = 85
I/flutter ( 6935): Connect Variable Header: ProtocolName=MQTT, ProtocolVersion=4, ConnectFlags=Connect Flags: Reserved1=false, CleanStart=true, WillFlag=false, WillQos=MqttQos.exactlyOnce, WillRetain=false, PasswordFlag=true, UserNameFlag=true, KeepAlive=0
I/flutter ( 6935): Instance of 'MqttConnectPayload'
Now also i get disconnected when trying to subscribe to a topic:
I/flutter (11173): 2018-11-27 10:41:21.541378 -- MqttConnectionHandler::sendMessage - MQTTMessage of type MqttMessageType.subscribe
I/flutter (11173): Header: MessageType = MqttMessageType.subscribe, Duplicate = false, Retain = false, Qos = MqttQos.atLeastOnce, Size = 0
I/flutter (11173): Subscribe Variable Header: MessageIdentifier={20}
I/flutter (11173): Payload: Subscription [{1}]
I/flutter (11173): {{ Topic={p/518153/a}, Qos={MqttQos.exactlyOnce} }}
I/flutter (11173):
I/flutter (11173): 2018-11-27 10:41:21.682626 -- MqttConnection::_onDone - calling disconnected callback
I/flutter (11173): ==> MQTT: Disconnected, Was Self: false
I/flutter (11173): 2018-11-27 10:41:21.683330 -- SynchronousMqttConnectionHandler::disconnect
I/flutter (11173): 2018-11-27 10:41:21.683567 -- MqttConnectionHandler::sendMessage - MQTTMessage of type MqttMessageType.disconnect
I/flutter (11173): Header: MessageType = MqttMessageType.disconnect, Duplicate = false, Retain = false, Qos = MqttQos.atMostOnce, Size = 0
I/flutter (11173): 2018-11-27 10:41:21.683613 -- MqttConnectionHandler::sendMessage - not connected
Maybe something is wrong with my MQTT server? I can give you access if you want.
from mqtt_client.
OK, could you try the above with test.mosquitto.org, this should rule out your broker.
from mqtt_client.
@shamblett Same thing happens on test.mosquitto.org
:
I/flutter (16038): Sending Message:
I/flutter (16038): 2018-11-27 12:43:30.842492 -- MqttConnectionHandler::sendMessage - MQTTMessage of type MqttMessageType.publish
I/flutter (16038): Header: MessageType = MqttMessageType.publish, Duplicate = false, Retain = false, Qos = MqttQos.exactlyOnce, Size = 0
I/flutter (16038): Publish Variable Header: TopicName={u/884063}, MessageIdentifier={2}, VH Length={0}
I/flutter (16038): Payload: {58 bytes={<123><34><116><121><112><101><34><58><34><109><115><103><84><101><120><116><34><44><34><100><97><116><97><34><58><34><116><101><115><116><32><49><50><55><48><49><54><34><44><34><105><100><101><110><116><105><102><105><101><114><34><58><56><54><57><50><53><125>
I/flutter (16038): 2018-11-27 12:43:30.958589 -- MqttConnection::_onData
I/flutter (16038): 2018-11-27 12:43:30.959480 -- MqttConnection::_onData - message received MQTTMessage of type MqttMessageType.publishReceived
I/flutter (16038): Header: MessageType = MqttMessageType.publishReceived, Duplicate = false, Retain = false, Qos = MqttQos.atMostOnce, Size = 2
I/flutter (16038): PublishReceived Variable Header: MessageIdentifier={2}
I/flutter (16038): 2018-11-27 12:43:30.959583 -- MqttConnection::_onData - message processed
I/flutter (16038): 2018-11-27 12:43:30.962287 -- MqttConnectionHandler::sendMessage - MQTTMessage of type MqttMessageType.publishRelease
I/flutter (16038): Header: MessageType = MqttMessageType.publishRelease, Duplicate = false, Retain = false, Qos = MqttQos.atMostOnce, Size = 0
I/flutter (16038): PublishRelease Variable Header: MessageIdentifier={2}
I/flutter (16038): 2018-11-27 12:43:31.076425 -- MqttConnection::_onDone - calling disconnected callback
I/flutter (16038): ==> Disconnected | Time: 2018-11-27 09:13:31.076743Z
I/flutter (16038): 2018-11-27 12:43:31.077644 -- SynchronousMqttConnectionHandler::disconnect
I/flutter (16038): 2018-11-27 12:43:31.079008 -- MqttConnectionHandler::sendMessage - MQTTMessage of type MqttMessageType.disconnect
I/flutter (16038): Header: MessageType = MqttMessageType.disconnect, Duplicate = false, Retain = false, Qos = MqttQos.atMostOnce, Size = 0
I/flutter (16038): 2018-11-27 12:43:31.079193 -- MqttConnectionHandler::sendMessage - not connected
Edit: honestly i don't know what happens but it works now.
Edit2: i still have issue in my server ( both publish and subscribe ) and the only difference is that i use secured websocket (WSS) to connect to my server.
Edit3: I can confirm this library works perfectly with test.mosquitto.org and it seems there is something wrong with my broker
from mqtt_client.
@shamblett Could you please check this piece of code on my broker? It's get disconnected when trying to publish to a topic (eg: u/$id/
), I asked this because i don't have this problem with other libraries like pahoJS.
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");
});
from mqtt_client.
This seems to work Ok for me using your broker credentials above I'm getting no disconnects on publish.
from mqtt_client.
@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.
I/flutter ( 2189): 2018-12-04 10:39:54.486382 -- MqttConnectionHandler::sendMessage - MQTTMessage of type MqttMessageType.publish
I/flutter ( 2189): Header: MessageType = MqttMessageType.publish, Duplicate = false, Retain = false, Qos = MqttQos.exactlyOnce, Size = 0
I/flutter ( 2189): Publish Variable Header: TopicName={u/2844865}, MessageIdentifier={1}, VH Length={0}
I/flutter ( 2189): Payload: {54 bytes={<123><34><116><121><112><101><34><58><34><109><115><103><84><101><120><116><34><44><34><100><97><116><97><34><58><34><87><111><114><107><115><33><34><44><34><105><100><101><110><116><105><102><105><101><114><34><58><50><57><52><50><49><56><125>
I/flutter ( 2189): 2018-12-04 10:39:54.490107 -- MqttConnection::_onData
I/flutter ( 2189): 2018-12-04 10:39:54.491982 -- MqttConnection::_onData - message received MQTTMessage of type MqttMessageType.publish
I/flutter ( 2189): Header: MessageType = MqttMessageType.publish, Duplicate = false, Retain = false, Qos = MqttQos.exactlyOnce, Size = 18
I/flutter ( 2189): Publish Variable Header: TopicName={time}, MessageIdentifier={1}, VH Length={8}
I/flutter ( 2189): Payload: {10 bytes={<49><53><52><51><57><48><55><51><57><52>
I/flutter ( 2189): 2018-12-04 10:39:54.492065 -- MqttConnection::_onData - message processed
I/flutter ( 2189): 2018-12-04 10:39:54.493726 -- MqttConnectionHandler::sendMessage - MQTTMessage of type MqttMessageType.publishReceived
I/flutter ( 2189): Header: MessageType = MqttMessageType.publishReceived, Duplicate = false, Retain = false, Qos = MqttQos.atMostOnce, Size = 0
I/flutter ( 2189): PublishReceived Variable Header: MessageIdentifier={1}
I/flutter ( 2189): 2018-12-04 10:39:54.494889 -- MqttConnection::_onData
I/flutter ( 2189): 2018-12-04 10:39:54.495290 -- MqttConnection::_onData - message received MQTTMessage of type MqttMessageType.publish
I/flutter ( 2189): Header: MessageType = MqttMessageType.publish, Duplicate = false, Retain = false, Qos = MqttQos.atLeastOnce, Size = 23
I/flutter ( 2189): Publish Variable Header: TopicName={p/2844865/n}, MessageIdentifier={2}, VH Length={15}
I/flutter ( 2189): Payload: {8 bytes={<217><133><216><185><219><140><217><134>
I/flutter ( 2189): 2018-12-04 10:39:54.495387 -- MqttConnection::_onData - message processed
I/flutter ( 2189): 2018-12-04 10:39:54.496636 -- MqttConnectionHandler::sendMessage - MQTTMessage of type MqttMessageType.publishAck
I/flutter ( 2189): Header: MessageType = MqttMessageType.publishAck, Duplicate = false, Retain = false, Qos = MqttQos.atMostOnce, Size = 0
I/flutter ( 2189): PublishAck Variable Header: MessageIdentifier={2}
I/flutter ( 2189): 2018-12-04 10:39:54.509424 -- MqttConnection::_onData
I/flutter ( 2189): 2018-12-04 10:39:54.510449 -- MqttConnection::_onData - message received MQTTMessage of type MqttMessageType.publishReceived
I/flutter ( 2189): Header: MessageType = MqttMessageType.publishReceived, Duplicate = false, Retain = false, Qos = MqttQos.atMostOnce, Size = 2
I/flutter ( 2189): PublishReceived Variable Header: MessageIdentifier={1}
I/flutter ( 2189): 2018-12-04 10:39:54.510647 -- MqttConnection::_onData - message processed
I/flutter ( 2189): 2018-12-04 10:39:54.512975 -- MqttConnectionHandler::sendMessage - MQTTMessage of type MqttMessageType.publishRelease
I/flutter ( 2189): Header: MessageType = MqttMessageType.publishRelease, Duplicate = false, Retain = false, Qos = MqttQos.atLeastOnce, Size = 0
I/flutter ( 2189): PublishRelease Variable Header: MessageIdentifier={1}
I/flutter ( 2189): 2018-12-04 10:39:54.527786 -- MqttConnection::_onData
I/flutter ( 2189): 2018-12-04 10:39:54.529568 -- MqttConnection::_onData - message received MQTTMessage of type MqttMessageType.publishRelease
I/flutter ( 2189): Header: MessageType = MqttMessageType.publishRelease, Duplicate = false, Retain = false, Qos = MqttQos.atLeastOnce, Size = 2
I/flutter ( 2189): PublishRelease Variable Header: MessageIdentifier={1}
I/flutter ( 2189): 2018-12-04 10:39:54.529824 -- MqttConnection::_onData - message processed
I/flutter ( 2189): 2018-12-04 10:39:54.534168 -- MqttConnectionHandler::sendMessage - MQTTMessage of type MqttMessageType.publishComplete
I/flutter ( 2189): Header: MessageType = MqttMessageType.publishComplete, Duplicate = false, Retain = false, Qos = MqttQos.atMostOnce, Size = 0
I/flutter ( 2189): PublishComplete Variable Header: MessageIdentifier={1}
I/flutter ( 2189): 2018-12-04 10:39:54.543602 -- MqttConnection::_onData
I/flutter ( 2189): 2018-12-04 10:39:54.544250 -- MqttConnection::_onData - message received MQTTMessage of type MqttMessageType.publishComplete
I/flutter ( 2189): Header: MessageType = MqttMessageType.publishComplete, Duplicate = false, Retain = false, Qos = MqttQos.atMostOnce, Size = 2
I/flutter ( 2189): PublishComplete Variable Header: MessageIdentifier={1}
I/flutter ( 2189): 2018-12-04 10:39:54.544394 -- MqttConnection::_onData - message processed
I/flutter ( 2189): 2018-12-04 10:39:54.552379 -- MqttConnection::_onData
I/flutter ( 2189): 2018-12-04 10:39:54.553282 -- MqttConnection::_onData - message received MQTTMessage of type MqttMessageType.publish
I/flutter ( 2189): Header: MessageType = MqttMessageType.publish, Duplicate = false, Retain = false, Qos = MqttQos.exactlyOnce, Size = 176
I/flutter ( 2189): Publish Variable Header: TopicName={u/2844865}, MessageIdentifier={3}, VH Length={13}
I/flutter ( 2189): Payload: {163 bytes={<123><34><100><97><116><97><34><58><34><87><111><114><107><115><33><34><44><34><102><114><111><109><34><58><123><34><105><100><34><58><50><56><52><52><56><54><53><44><34><110><97><109><101><34><58><34><92><117><48><54><52><53><92><117><48><54><51><57><92><117><48><54><99><99><92><117><48><54><52><54><34><44><34><117><115><101><114><34><58><34><34><125><44><34><105><100><34><58><49><51><44><34><105><100><101><110><116><105><102><105><101><114><34><58><50><57><52><50><49><56><44><34><116><105><109><101><34><58><49><53><52><51><57><48><55><51><57><52><56><50><53><44><34><116><111><34><58><50><56><56><52><53><55><57><53><44><34><116><121><112><101><34><58><34><109><115><103>
I/flutter ( 2189): 2018-12-04 10:39:54.553364 -- MqttConnection::_onData - message processed
I/flutter ( 2189): 2018-12-04 10:39:54.554569 -- MqttConnectionHandler::sendMessage - MQTTMessage of type MqttMessageType.publishReceived
I/flutter ( 2189): Header: MessageType = MqttMessageType.publishReceived, Duplicate = false, Retain = false, Qos = MqttQos.atMostOnce, Size = 0
I/flutter ( 2189): PublishReceived Variable Header: MessageIdentifier={3}
I/flutter ( 2189): 2018-12-04 10:39:54.622758 -- MqttConnection::_onData
I/flutter ( 2189): 2018-12-04 10:39:54.623264 -- MqttConnection::_onData - message received MQTTMessage of type MqttMessageType.publishRelease
I/flutter ( 2189): Header: MessageType = MqttMessageType.publishRelease, Duplicate = false, Retain = false, Qos = MqttQos.atLeastOnce, Size = 2
I/flutter ( 2189): PublishRelease Variable Header: MessageIdentifier={3}
I/flutter ( 2189): 2018-12-04 10:39:54.623445 -- MqttConnection::_onData - message processed
I/flutter ( 2189): 2018-12-04 10:39:54.623801 -- MqttConnectionHandler::sendMessage - MQTTMessage of type MqttMessageType.publishComplete
I/flutter ( 2189): Header: MessageType = MqttMessageType.publishComplete, Duplicate = false, Retain = false, Qos = MqttQos.atMostOnce, Size = 0
I/flutter ( 2189): PublishComplete Variable Header: MessageIdentifier={3}
I/flutter ( 2189): 2018-12-04 10:39:56.493550 -- MqttConnectionHandler::sendMessage - MQTTMessage of type MqttMessageType.publish
I/flutter ( 2189): Header: MessageType = MqttMessageType.publish, Duplicate = false, Retain = false, Qos = MqttQos.exactlyOnce, Size = 0
I/flutter ( 2189): Publish Variable Header: TopicName={u/2844865}, MessageIdentifier={2}, VH Length={0}
I/flutter ( 2189): Payload: {58 bytes={<123><34><116><121><112><101><34><58><34><109><115><103><84><101><120><116><34><44><34><100><97><116><97><34><58><34><78><111><116><32><119><111><114><107><115><33><34><44><34><105><100><101><110><116><105><102><105><101><114><34><58><52><51><57><48><53><52><125>
I/flutter ( 2189): 2018-12-04 10:39:56.561951 -- MqttConnection::_onDone - calling disconnected callback
I/flutter ( 2189):
I/flutter ( 2189):
I/flutter ( 2189):
I/flutter ( 2189): ==> Disconnected | Time: 2018-12-04 07:09:56.562250Z
I/flutter ( 2189):
I/flutter ( 2189):
from mqtt_client.
@shamblett Here is the full code
from mqtt_client.
Sorry for that, I've updated token. Please kindly test it again.
from mqtt_client.
The client works good with secure tcp!
closing, thanks.
from mqtt_client.
Unfortunately, the same for me
#168
@shamblett
here my code
try {
client = MqttServerClient(broker, clientIdentifier);
SecurityContext securityContext =
SecurityContext(withTrustedRoots: false);
final ByteData crtData =
await rootBundle.load('assets/AmazonRootCA1.pem');
securityContext.setTrustedCertificatesBytes(crtData.buffer.asUint8List());
final ByteData authoritiesBytes =
await rootBundle.load('assets/certificate.pem.crt');
securityContext
.useCertificateChainBytes(authoritiesBytes.buffer.asUint8List());
final ByteData keyBytes =
await rootBundle.load('assets/private.pem.key');
securityContext.usePrivateKeyBytes(keyBytes.buffer.asUint8List());
client.securityContext = securityContext;
} catch (e) {
logger.e('Error security', e);
}
client.port = port;
client.logging(on: true);
client.keepAlivePeriod = 60;
client.autoReconnect = false;
client.onConnected = () {
print("==> Connected | Time: ${DateTime.now().toUtc()}");
};
client.setProtocolV311();
client.secure = true;
client.setProtocolV311();
client.onBadCertificate = (dynamic a) => true;
final MqttConnectMessage connMess = MqttConnectMessage()
.withClientIdentifier(clientIdentifier)
.startClean() // Non persistent session for testing
.keepAliveFor(60);
client.connectionMessage = connMess;
client.onDisconnected = () {
print("==> Disconnected | Time: ${DateTime.now().toUtc()}");
};
and some logs
/flutter (10494): ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
I/flutter (10494): 2020-05-17 16:51:24.118523 -- SynchronousMqttServerConnectionHandler::internalConnect entered
I/flutter (10494): 2020-05-17 16:51:24.119296 -- SynchronousMqttServerConnectionHandler::internalConnect - initiating connection try 0
I/flutter (10494): 2020-05-17 16:51:24.119483 -- SynchronousMqttServerConnectionHandler::internalConnect - secure selected
I/flutter (10494): 2020-05-17 16:51:24.119739 -- MqttSecureConnection::connect
I/flutter (10494): 2020-05-17 16:51:25.033768 -- MqttSecureConnection::connect - securing socket
I/flutter (10494): 2020-05-17 16:51:25.034415 -- MqttSecureConnection::connect - start listening
I/flutter (10494): 2020-05-17 16:51:25.034671 -- MqttServerConnection::_startListening
I/flutter (10494): 2020-05-17 16:51:25.036366 -- SynchronousMqttServerConnectionHandler::internalConnect - connection complete
I/flutter (10494): 2020-05-17 16:51:25.036792 -- SynchronousMqttServerConnectionHandler::internalConnect sending connect message
I/flutter (10494): 2020-05-17 16:51:25.037680 -- MqttConnectionHandlerBase::sendMessage - MQTTMessage of type MqttMessageType.connect
I/flutter (10494): Header: MessageType = MqttMessageType.connect, Duplicate = false, Retain = false, Qos = MqttQos.atMostOnce, Size = 0
I/flutter (10494): Connect Variable Header: ProtocolName=MQTT, ProtocolVersion=4, ConnectFlags=Connect Flags: Reserved1=false, CleanStart=true, WillFlag=false, WillQos=MqttQos.atMostOnce, WillRetain=false, PasswordFlag=false, UserNameFlag=false, KeepAlive=60
I/flutter (10494): MqttConnectPayload - client identifier is : android
I/flutter (10494): 2020-05-17 16:51:25.043958 -- SynchronousMqttServerConnectionHandler::internalConnect - pre sleep, state = Connection status is connecting with return code of noneSpecified and a disconnection origin of none
I/flutter (10494): 2020-05-17 16:51:25.336272 -- MqttConnection::_onData
I/flutter (10494): 2020-05-17 16:51:25.338119 -- MqttServerConnection::_onData - message received MQTTMessage of type MqttMessageType.connectAck
I/flutter (10494): Header: MessageType = MqttMessageType.connectAck, Duplicate = false, Retain = false, Qos = MqttQos.atMostOnce, Size = 2
I/flutter (10494): Connect Variable Header: TopicNameCompressionResponse={0}, ReturnCode={MqttConnectReturnCode.connectionAccepted}
I/flutter (10494): 2020-05-17 16:51:25.339021 -- MqttServerConnection::_onData - message processed
I/flutter (10494): 2020-05-17 16:51:25.340315 -- SynchronousMqttServerConnectionHandler::_connectAckProcessor
I/flutter (10494): 2020-05-17 16:51:25.341016 -- SynchronousMqttServerConnectionHandler::_connectAckProcessor - state = connected
I/flutter (10494): ==> Connected | Time: 2020-05-17 14:51:25.342264Z
I/flutter (10494): 2020-05-17 16:51:25.342703 -- SynchronousMqttServerConnectionHandler:: cancelling connect timer
I/flutter (10494): 2020-05-17 16:51:25.344256 -- SynchronousMqttServerConnectionHandler::internalConnect - post sleep, state = Connection status is connected with return code of connectionAccepted and a disconnection origin of none
I/flutter (10494): 2020-05-17 16:51:25.344880 -- SynchronousMqttServerConnectionHandler::internalConnect exited with state Connection status is connected with return code of connectionAccepted and a disconnection origin of none
I/flutter (10494): 2020-05-17 16:51:25.349611 -- MqttConnectionHandlerBase::sendMessage - MQTTMessage of type MqttMessageType.publish
I/flutter (10494): Header: MessageType = MqttMessageType.publish, Duplicate = false, Retain = false, Qos = MqttQos.exactlyOnce, Size = 0
I/flutter (10494): Publish Variable Header: TopicName={prueba}, MessageIdentifier={39}, VH Length={0}
I/flutter (10494): Payload: {24 bytes={<123><34><109><101><115><115><97><103><101><34><58><34><104><111><108><97><32><108><111><99><111><33><34><125>
I/flutter (10494): 2020-05-17 16:51:25.356780 -- MqttConnectionHandlerBase::sendMessage - MQTTMessage of type MqttMessageType.subscribe
I/flutter (10494): Header: MessageType = MqttMessageType.subscribe, Duplicate = false, Retain = false, Qos = MqttQos.atLeastOnce, Size = 0
I/flutter (10494): Subscribe Variable Header: MessageIdentifier={40}
I/flutter (10494): Payload: Subscription [{1}]
I/flutter (10494): {{ Topic={prueba}, Qos={MqttQos.exactlyOnce} }}
I/flutter (10494):
I/flutter (10494): 2020-05-17 16:51:25.487768 -- MqttConnectionBase::_onDone - calling disconnected callback
I/flutter (10494): ==> Disconnected | Time: 2020-05-17 14:51:25.489805Z
from mqtt_client.
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
from mqtt_client.
Refer to this issue
from mqtt_client.
Related Issues (20)
- Failed to connect to mqtt, I donβt know where the problem lies HOT 1
- mqtt sets reconnection timeout to expire HOT 30
- Need shorter timeout when connection can't be established HOT 9
- feat: Added a connection timeout callback HOT 8
- Add Connection Ack message to connection status HOT 1
- MqttBrowserClient with self-signed certificate HOT 1
- How to add proxy to see content in proxy tools like Charles/Proxyman? HOT 1
- retain:true publishing issue (using IoT Core) HOT 3
- Differences in automatic reconnection between IOS and Android HOT 1
- '400 Bad Request' response while connecting with websocket to rabbitmq HOT 3
- How to connect mqtt with socket header options? HOT 3
- mqttjs:client _checkPing :: checking ping... Runs twice in rapid succession some times HOT 1
- How to determine the cause of the disconnect? HOT 1
- Available bytes is less than the message size HOT 4
- error:Bad state: Cannot add new events after calling close HOT 8
- AWS IoT Certificate - Use .bks file certificate HOT 1
- NoConnectionException: Missing Connection Acknowledgement HOT 4
- Ping triggers client.update and brings the same message multiple times HOT 1
- How can I receive a complete offline message? HOT 1
- Unhandled Exception: mqtt-client::NoConnectionException: MqttWs2Connection::TLS connection unexpectedly closed HOT 15
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mqtt_client.