Connecting to Losant through Mqtt with Flutter App

Hi,

I am able to connect to Losant through an insecure port 1883 with the following details but not able to connect with secure port 8883.

String _broker = ‘broker.losant.com’;
int _port = 1883;

Also when I am connected in the insecure port I am not able to disconnect.

Please advise

  1. How to connect on the secure port
  2. What could be the issue with disconnect.

Hi @Brindha_Shayana,

The port for a secure connection is 8883. If you haven’t, you should check out these docs:

If you have any more issues connecting to the Losant Broker, any error messages, screenshots, or further information you could provide would be helpful.

Hi

Thanks for your reply. Yes I have been through the Losant documentation. I have been trying this for some time with success just using the insecure port.

I am using the mqtt_client Dart package (FYI https://pub.dev/packages/mqtt_client) to link my Flutter app with my Losant account. I am able to successfully communicate with Losant on the insecure port 1883. However once I change the port number to 8883 I get the following error.

Error message as below:
flutter: 2020-01-02 18:07:28.096329 – Authenticating with username ‘{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}’ and password ‘{xxx 64 char password xxx}’
flutter: 2020-01-02 18:07:28.097055 – Username length (36) exceeds the max recommended in the MQTT spec.
flutter: 2020-01-02 18:07:28.097405 – Password length (64) exceeds the max recommended in the MQTT spec.
flutter: 2020-01-02 18:07:28.109708 – SynchronousMqttConnectionHandler::internalConnect entered
flutter: 2020-01-02 18:07:28.109953 – SynchronousMqttConnectionHandler::internalConnect - initiating connection try 0
flutter: 2020-01-02 18:07:28.110386 – SynchronousMqttConnectionHandler::internalConnect - insecure TCP selected
flutter: 2020-01-02 18:07:28.336029 – MqttConnection::_startListening
flutter: 2020-01-02 18:07:28.341588 – SynchronousMqttConnectionHandler::internalConnect sending connect message
flutter: 2020-01-02 18:07:28.349624 – MqttConnectionHandler::sendMessage - MQTTMessage of type MqttMessageType.connect
Header: MessageType = MqttMessageType.connect, Duplicate = false, Retain = false, Qos = MqttQos.atMostOnce, Size = 0
Connect Variable Header: ProtocolName=MQIsdp, ProtocolVersion=3, ConnectFlags=Connect Flags: Reserved1=false, CleanStart=true, WillFlag=false, WillQos=MqttQos.atMostOnce, WillRetain=false, PasswordFlag=true, UserNameFlag=true, KeepAlive=36000
Instance of ‘MqttConnectPayload’
flutter: 2020-01-02 18:07:28.402430 – SynchronousMqttConnectionHandler::internalConnect - pre sleep, state = Connection status is connecting with return code noneSpecified
[C110.1.1 C478C0B9-81EC-4F58-9FDC-8502F2A16777 2a02:c7f:c33:8800:2018:bdb5:b82a:5f68.59953<->2a00:1450:4009:808::200a.443]
Connected Path: satisfied (Path is satisfied), interface: en0
Duration: 1.705s, DNS @1.367s took 0.006s, TCP @1.374s took 0.026s, TLS took 0.055s
bytes in/out: 5370/1262, packets in/out: 9/10, rtt: 0.027s, retransmitted packets: 0, out-of-order packets: 0
flutter: 2020-01-02 18:07:28.542708 – MqttConnection::_onDone - calling disconnected callback

Hi @Brindha_Shayana,

I have not previously worked with these resources before, but I noticed a couple of lines with issues. Which line is of the most concern?

I want to preface that our expertise lies within Losant, and that I have linked some external documentation below that may solve your error. It may also be beneficial to open a Github issue for the library you are using.

I hope to hear your primary concerns, but I do find it strange that, though you configured a secure connection, the log reads “insecure TCP selected,” which could point to a configuration error within your client. If the following articles do not provide clarity, I would recommend following up with some screenshots of your configuration.



Thanks!
Julia

Hi,

Thanks for your reply. The resources where useful.

I am now able to connect through the secure WebSockets transport (wss://broker.losant.com:443)

It looks like the Flutter mqtt_client package does not support TLS port 8883.

Regards,
Sathya