Closed DhavalRKansara closed 5 years ago
You don't show where this is called from
void unSubscribeWithTopic( String topic)async { client.unsubscribe(topic); }
also its marked as async, it needn't be, the unsubscribe method does not return a future so you can't await it. That said, the problem seems to be here
flutter: 2019-05-08 16:24:14.880625 -- MqttConnectionHandler::sendMessage - MQTTMessage of type MqttMessageType.unsubscribe
Header: MessageType = MqttMessageType.unsubscribe, Duplicate = false, Retain = false, Qos = MqttQos.atMostOnce, Size = 0
Unsubscribe VariableHeader Variable Header: MessageIdentifier={3}
Payload: Unsubscription [{1}]
{{ Topic={websockets/stations/stats/fastUpdates/e4eed60a-c308-49ad-92c9-049deaf652ed}}
flutter: MAIN DICTIONARY {websockets/stations/list/e4eed60a-c308-49ad-92c9-049deaf652ed: {_DashboardScreenState#536fe(lifecycle state: defunct, not mounted)}}
flutter: 2019-05-08 16:24:14.883441 -- MqttConnectionHandler::sendMessage - MQTTMessage of type MqttMessageType.unsubscribe
Header: MessageType = MqttMessageType.unsubscribe, Duplicate = false, Retain = false, Qos = MqttQos.atMostOnce, Size = 0
Unsubscribe VariableHeader Variable Header: MessageIdentifier={4}
Payload: Unsubscription [{1}]
Your unsubscribing twice, in each case the message size is 0 which is a bit odd, I'll look at this, the broker log shows that this bad message was picked up, which is why you re-connected, which seemed to work Ok.
I need to see how you are using your MQTTHelper class really.
I use nodejs to create local mqtt server.The MQTTBox can connect the local mqtt server and subscribe & push.But in flutter , the app i crated which can't connected the local mqtt server.
here is my nodejs mqtt server.
var mosca = require('mosca');
var ascoltatore = {
//using ascoltatore
//type: 'mongo',
//url: 'mongodb://localhost:27017/mqtt',
//pubsubCollection: 'ascoltatori',
//mongo: {}
};
var settings = {
port: 1883,
backend: ascoltatore
};
var server = new mosca.Server(settings);
server.on('clientConnected', function(client) {
console.log('client connected', client.id);
});
// fired when a message is received
server.on('published', function(packet, client) {
console.log('Published', packet.payload);
});
server.on('ready', setup);
// fired when the mqtt server is ready
function setup() {
console.log('Mosca server is up and running');
}
the flutter app code just like your example.But i change the broker is 192.168.1.16. the client.port is 1883.
I see the error, it confused to me.The port change to 48359.
Does it always print the same port number?
Does it always print the same port number?
No.some times the port number will change
Ok this is your local port number then it looks like a network error could you post the code of how you initialise the mqtt client
Just a note, when working with RabbitMQ's MQTT plugin, the topic unsubscribing payload should come with Qos as MqttQos.atLeastOnce or the MQTT plugin would throw an unparseable payload error.
@tsing in my case your comment solved my problem! Thank you! The library does not add Qos to unsubscribe as I see? I opened an issue for this, I am not sure if I am correct here of if I am missing something: https://github.com/shamblett/mqtt_client/issues/312
I am trying to unsubscribe topic on a local broker and getting the following exception, could you please check and tell if there is some error from my side? My Code
Below is the error log when I tried to unsubscribe after subscription of the topic :
Error log from broker side: