Closed lgLindstrom closed 4 years ago
I need to see the actual code you are using, as far as I know the example code works OK. Yes you can use an IP address, just pass it as a string e.g. '127.0.0.1'
Hi. My application i rather big,, and I just planned to att a MQTT client to it.... :) I've noticed the following:
Exception has occurred.
SocketException (SocketException: Failed host lookup: 'mosquitto' (OS Error: No address associated with hostname, errno = 7))
My guess is that is a problem in my network.
Giving a correct IP address gives the following log.
I/flutter (19991): EXAMPLE::Mosquitto client connecting.... I/flutter (19991): 2020-03-17 17:15:37.277936 -- SynchronousMqttConnectionHandler::internalConnect entered I/flutter (19991): 2020-03-17 17:15:37.281303 -- SynchronousMqttConnectionHandler::internalConnect - initiating connection try 0 I/flutter (19991): 2020-03-17 17:15:37.281619 -- SynchronousMqttConnectionHandler::internalConnect - websocket selected I/flutter (19991): 2020-03-17 17:15:37.288260 -- MqttWsConnection:: WS URL is ws://192.168.68.120:1883, protocols are [mqtt, mqttv3.1, mqttv3.11] I/flutter (19991): 2020-03-17 17:15:37.744404 -- MqttConnection::_onError - calling disconnected callback I/flutter (19991): 2020-03-17 17:15:37.745754 -- SynchronousMqttConnectionHandler::disconnect I/flutter (19991): 2020-03-17 17:15:37.747708 -- MqttConnectionHandler::sendMessage - MQTTMessage of type MqttMessageType.disconnect I/flutter (19991): Header: MessageType = MqttMessageType.disconnect, Duplicate = false, Retain = false, Qos = MqttQos.atMostOnce, Size = 0 I/flutter (19991): EXAMPLE::OnDisconnected client callback - Client disconnection I/flutter (19991): EXAMPLE::OnDisconnected callback is solicited, this is correct I/flutter (19991): EXAMPLE::client exception - HttpException: , uri = http://192.168.68.120:1883 I/flutter (19991): EXAMPLE::OnDisconnected client callback - Client disconnection I/flutter (19991): EXAMPLE::OnDisconnected callback is solicited, this is correct I/flutter (19991): EXAMPLE::ERROR Mosquitto client connection failed - disconnecting, status is Connection status is disconnected with return code solicited I/flutter (19991): EXAMPLE::OnDisconnected client callback - Client disconnection I/flutter (19991): EXAMPLE::OnDisconnected callback is solicited, this is correct Lost connection to device.
Can you advice from this information or should I try to send parts of my application to you?
Looks like this
MqttWsConnection:: WS URL is ws://192.168.68.120:1883, protocols are [mqtt, mqttv3.1, mqttv3.11] I/flutter (19991): 2020-03-17 17:15:37.744404 -- MqttConnection::_onError - calling disconnected
try setting your protocols to websocketProtocols = [mqtt] or even [].
I have tried all protocols including [], no change.
There is a connectionMessage. I have not changed anything from your example,,, can it cause the trouble.
My url is like this 'ws://192.168.68.120' correct ??
I getting desperat here :)
Some more info. I found a example on internet that are using mqtt_client ^5.6.2 This example works for me although it connects to "test.mosquitto.org"
I tried to use same url in my application,,, gives a exception
Exception has occurred. NoConnectionException (mqtt-client::NoConnectionException: MqttWsConnection::The URI supplied for the WS has an incorrect scheme - test.mosquitto.org)
I changed the uri to "ws://test.mosquitto.org" and are back to the old well non problems.
I also got this exeption:
Exception has occurred. HttpException (HttpException: , uri = http://test.mosquitto.org:1883)
This happens before _onError is called
Why http ??
test.mosquitto.org can be used as follows
1883 : MQTT, unencrypted
8883 : MQTT, encrypted
8884 : MQTT, encrypted, client certificate required
8080 : MQTT over WebSockets, unencrypted
8081 : MQTT over WebSockets, encrypted
The client does work with test.mosquitto.org using web sockets(and all others for that matter) as long as you use the correct port and client settings.
You don't need http, this won't work.
If your running mosquitto locally you need to be careful, unless you have a download with working websockets it wont work with ws or wss, from the mosquitto docs
The default Mosquitto install packages for Windows and Linux do not include support for WebSockets. If you want to test WebSockets with MQTT then you need to either: Compile and install your own Mosquitto broker with Websocket support. Use an oneline broker that has websocket support.
Hi
I planning to write a MQTT application in flutter. As first task I would try out your package. Copying your example from mqtt_server_client.dart and tried to run it.
Immediately some questions raises.
My small test case will not connect to my broker although I know that the broker runs nicely. I have connected to it from other applications. ( no password is set ). Lack of information will be a problem later,, what to give application user for information?
Is it possible to give a IP address instead for server name??
THis is my MqttClientConnectionStatus:
This is my debugger console: