shamblett / mqtt_client

A server and browser based MQTT client for dart
Other
552 stars 179 forks source link

Getting to more info #162

Closed lgLindstrom closed 4 years ago

lgLindstrom commented 4 years ago

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.

THis is my MqttClientConnectionStatus:

MqttClientConnectionStatus (Connection status is connecting with return code noneSpecified)
returnCode:MqttConnectReturnCode
_name:"MqttConnectReturnCode.noneSpecified"
index:8
hashCode:213219350
runtimeType:Type (MqttConnectReturnCode)
hashCode:647849688
runtimeType:Type (_Type)
hashCode:505247321
runtimeType:Type (_Type)
state:MqttConnectionState
_name:"MqttConnectionState.connecting"
index:2
hashCode:317193012
runtimeType:Type (MqttConnectionState)
hashCode:27290961
runtimeType:Type (MqttClientConnectionStatus)
hashCode:1049478003
runtimeType:Type (_Type)
connectionSt

This is my debugger console:

EXAMPLE::Mosquitto client connecting....
2020-03-15 15:34:53.718260 -- SynchronousMqttConnectionHandler::internalConnect entered
2020-03-15 15:34:53.720247 -- SynchronousMqttConnectionHandler::internalConnect - initiating connection try 0
2020-03-15 15:34:53.720247 -- SynchronousMqttConnectionHandler::internalConnect - insecure TCP selected
Connection status is connecting with return code noneSpecified
shamblett commented 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'

lgLindstrom commented 4 years ago

Hi. My application i rather big,, and I just planned to att a MQTT client to it.... :) I've noticed the following:

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?

shamblett commented 4 years ago

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 [].

lgLindstrom commented 4 years ago

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 :)

lgLindstrom commented 4 years ago

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 ??

shamblett commented 4 years ago

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.