Closed crnaosa closed 5 years ago
If I try with ws instead of wss, we get this
I/flutter (11525): EXAMPLE::Mosquitto client connecting.... I/flutter (11525): 2019-09-12 16:59:19.910144 -- SynchronousMqttConnectionHandler::internalConnect entered I/flutter (11525): 2019-09-12 16:59:19.917224 -- SynchronousMqttConnectionHandler::internalConnect - initiating connection try 0 I/flutter (11525): 2019-09-12 16:59:19.917453 -- SynchronousMqttConnectionHandler::internalConnect - websocket selected I/flutter (11525): 2019-09-12 16:59:19.952159 -- MqttWsConnection:: WS URL is ws://xxx.yyy.zzz.fff:1882, protocols are [mqtt] Syncing files to device Android SDK built for x86... I/flutter (11525): 2019-09-12 16:59:20.289330 -- MqttConnection::_onError - calling disconnected callback I/flutter (11525): EXAMPLE::client exception - HttpException: , uri = http://xxx.yyy.zzz.fff:1882 I/flutter (11525): 2019-09-12 16:59:20.290754 -- SynchronousMqttConnectionHandler::disconnect I/flutter (11525): 2019-09-12 16:59:20.291831 -- MqttConnectionHandler::sendMessage - MQTTMessage of type MqttMessageType.disconnect I/flutter (11525): Header: MessageType = MqttMessageType.disconnect, Duplicate = false, Retain = false, Qos = MqttQos.atMostOnce, Size = 0 I/flutter (11525): 2019-09-12 16:59:20.291884 -- MqttConnectionHandler::sendMessage - not connected I/flutter (11525): EXAMPLE::OnDisconnected client callback - Client disconnection D/ (11525): HostConnection::get() New Host Connection established 0xa9787100, tid 11548 Lost connection to device. Could not update files on device: HttpException: Connection closed before full header was received, uri = http://127.0.0.1:58877/H89EMW0zz8k=/
Looks as though the broker is not happy with the connection message, if you are using the client code trim the connection message down, the example shows
final MqttConnectMessage connMess = MqttConnectMessage() .withClientIdentifier('Mqtt_MyClientUniqueId') .keepAliveFor(20) // Must agree with the keep alive set above or not set .withWillTopic('willtopic') // If you set this you must set a will message .withWillMessage('My Will message') .startClean() // Non persistent session for testing .withWillQos(MqttQos.atLeastOnce);
Get rid of everything except the client id if you need this and try that, some brokers seem to be funny with these settings. If you still have no joy you will need to examine your broker logs to see why its rejecting the connection message.
Thank you for the response. We have solved the problem. It turned out it wasn't the websockets connection at all, altough we have to use ip address and port. Here's how we set it:
final MqttClient client = MqttClient('aaa.bbb.ccc.ddd', '');
Future<int> main() async {
client.useWebSocket = false;
client.port = 1882;
Hello, here is what we get in the logcat. And also tried with each protocol or with empty list. If you have any suggestion, it would be much appreciated.
And here is part of our clients setting that's different than yours:
If you have any working of how it works with websockets it would be great :)