Code Monkey home page Code Monkey logo

Comments (9)

shamblett avatar shamblett commented on August 30, 2024

Looks as though the broker is closing the connection because of something it doesn't like in the connect message, the MQTT spec lists a number of things that can cause this, check your broker logs if you have access to them. The username and password length warnings look wrong for the lengths you are using, I'll look at this. Which broker a re you using?

from mqtt_client.

yolkhovyy avatar yolkhovyy commented on August 30, 2024

It's the Bluemix broker of IBM. The name/password sizes are defined by the IoT Watson platform of IBM - can't get around that.

The Bluemix broker works fine with the name/password if I use this lib: https://github.com/jnguillerme/mqtt.dart. The lib does not support secure sockets - the reason why I'm looking at yours.

I will try your examples with Bluemix and my settings. Will keep you updated.

from mqtt_client.

shamblett avatar shamblett commented on August 30, 2024

I've opened a bluemix trial account, I get the following on connect to my test device

Authenticating with username '{use-token-auth}' and password '{.....}'
Username length (14) exceeds the max recommended in the MQTT spec.
Password length (18) exceeds the max recommended in the MQTT spec.
2017-11-01 08:21:54.301613 -- MqttConnectPayload::Client id exceeds spec value of 23
2017-11-01 08:21:54.308094 -- SynchronousMqttConnectionHandler::internalConnect entered
2017-11-01 08:21:54.308155 -- SynchronousMqttConnectionHandler::internalConnect - initiating connection try 0
2017-11-01 08:21:54.308298 -- SynchronousMqttConnectionHandler::internalConnect - insecure TCP selected
2017-11-01 08:21:54.341810 -- MqttConnection::_startListening
2017-11-01 08:21:54.348286 -- SynchronousMqttConnectionHandler::internalConnect sending connect message
2017-11-01 08:21:54.350308 -- 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.atLeastOnce, WillRetain=false, PasswordFlag=true, UserNameFlag=true, KeepAlive=60
Instance of 'MqttConnectPayload'
2017-11-01 08:21:54.364631 -- SynchronousMqttConnectionHandler::internalConnect - pre sleep, state = ConnectionState.connecting
2017-11-01 08:21:54.373388 -- MqttConnection::_onData
2017-11-01 08:21:54.378817 -- MqttConnection::_onData - message received MQTTMessage of type MqttMessageType.connectAck
Header: MessageType = MqttMessageType.connectAck, Duplicate = false, Retain = false, Qos = MqttQos.atMostOnce, Size = 2
Connect Variable Header: TopicNameCompressionResponse={0}, ReturnCode={MqttConnectReturnCode.notAuthorized}

As you can see I'm getting a not authorised connect response, don't know why this is as I'm no bluemix expert but I am getting a response, you don't seem to be. Have a look at the test mqtt_client_broker_test_publish.dart, I edited this to produce the above

from mqtt_client.

yolkhovyy avatar yolkhovyy commented on August 30, 2024

Take a look at this: https://developer.ibm.com/answers/questions/405505/my-devices-get-connection-refused-not-authorised-w/

By default you should use secure connection. You can disable this somewhere in your Bluemix settings.

I've tried the iot_core.dart example with my settings - the same result as in my first post here.

I think this occurs after the "not authorized" - if you make the Default rule "TLS optional" you'll get to the point.

from mqtt_client.

shamblett avatar shamblett commented on August 30, 2024

OK, I've set my test client to use secure and left Bluemix on TLS with token auth so we are using TLS, it now connects 3 times and each time gets a connect ack of not authorised, no TLS handshake error. I'll look further, the iot-core example needs the google root certs installed on your machine if you do not have them. Whic version of Dart are you using BTW and on what host OS?

from mqtt_client.

yolkhovyy avatar yolkhovyy commented on August 30, 2024

Ubuntu 16.04
Dart 1.24.2

I used your iot_core example, replaced all google by Bluemix, unsecure connection - changed/commented out the secure pieces.

from mqtt_client.

yolkhovyy avatar yolkhovyy commented on August 30, 2024

Commented out this line:
client.setProtocolV311();

and everything looks much better now:

Authenticating with username '{use-token-auth}' and password '{.....}'
Username length (14) exceeds the max recommended in the MQTT spec.
Password length (18) exceeds the max recommended in the MQTT spec.
2017-11-02 21:07:15.203144 -- MqttConnectPayload::Client id exceeds spec value of 23
2017-11-02 21:07:15.208131 -- SynchronousMqttConnectionHandler::internalConnect entered
2017-11-02 21:07:15.208239 -- SynchronousMqttConnectionHandler::internalConnect - initiating connection try 0
2017-11-02 21:07:15.208367 -- SynchronousMqttConnectionHandler::internalConnect - insecure TCP selected
2017-11-02 21:07:15.285327 -- MqttConnection::_startListening
2017-11-02 21:07:15.292179 -- SynchronousMqttConnectionHandler::internalConnect sending connect message
2017-11-02 21:07:15.294346 -- 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.atLeastOnce, WillRetain=false, PasswordFlag=true, UserNameFlag=true, KeepAlive=60
Instance of 'MqttConnectPayload'

2017-11-02 21:07:15.311428 -- SynchronousMqttConnectionHandler::internalConnect - pre sleep, state = ConnectionState.connecting
2017-11-02 21:07:15.348656 -- MqttConnection::_onData
2017-11-02 21:07:15.352929 -- MqttConnection::_onData - message received MQTTMessage of type MqttMessageType.connectAck
Header: MessageType = MqttMessageType.connectAck, Duplicate = false, Retain = false, Qos = MqttQos.atMostOnce, Size = 2
Connect Variable Header: TopicNameCompressionResponse={0}, ReturnCode={MqttConnectReturnCode.connectionAccepted}

2017-11-02 21:07:15.355356 -- MqttConnection::_onData - message processed
2017-11-02 21:07:15.361936 -- SynchronousMqttConnectionHandler::_connectAckProcessor
2017-11-02 21:07:15.362102 -- SynchronousMqttConnectionHandler::_connectAckProcessor - state = connected
2017-11-02 21:07:20.313219 -- SynchronousMqttConnectionHandler::internalConnect - post sleep, state = ConnectionState.connected
2017-11-02 21:07:20.313309 -- SynchronousMqttConnectionHandler::internalConnect exited with state ConnectionState.connected
iotcore client connected
2017-11-02 21:07:20.316606 -- MqttConnectionHandler::sendMessage - MQTTMessage of type MqttMessageType.publish
Header: MessageType = MqttMessageType.publish, Duplicate = false, Retain = false, Qos = MqttQos.exactlyOnce, Size = 0
Publish Variable Header: TopicName={iot-2/type/OpenGHGateway/id/oghgwspike/evt/PubEnvData/fmt/json}, MessageIdentifier={1}, VH Length={0}
Payload: {4 bytes={<97><98><99><100>

Sleeping....
2017-11-02 21:07:20.390766 -- MqttConnection::_onData
2017-11-02 21:07:20.391839 -- MqttConnection::_onData - message received MQTTMessage of type MqttMessageType.publishReceived
Header: MessageType = MqttMessageType.publishReceived, Duplicate = false, Retain = false, Qos = MqttQos.atMostOnce, Size = 2
PublishReceived Variable Header: MessageIdentifier={1}

2017-11-02 21:07:20.391933 -- MqttConnection::_onData - message processed
2017-11-02 21:07:20.392845 -- MqttConnectionHandler::sendMessage - MQTTMessage of type MqttMessageType.publishRelease
Header: MessageType = MqttMessageType.publishRelease, Duplicate = false, Retain = false, Qos = MqttQos.atMostOnce, Size = 0
PublishRelease Variable Header: MessageIdentifier={1}

2017-11-02 21:07:20.413324 -- MqttConnection::_onData
2017-11-02 21:07:20.414184 -- MqttConnection::_onData - message received MQTTMessage of type MqttMessageType.publishComplete
Header: MessageType = MqttMessageType.publishComplete, Duplicate = false, Retain = false, Qos = MqttQos.atMostOnce, Size = 2
PublishComplete Variable Header: MessageIdentifier={1}

2017-11-02 21:07:20.414299 -- MqttConnection::_onData - message processed
Disconnecting
2017-11-02 21:07:30.318775 -- SynchronousMqttConnectionHandler::disconnect
2017-11-02 21:07:30.338152 -- MqttConnectionHandler::sendMessage - MQTTMessage of type MqttMessageType.disconnect
Header: MessageType = MqttMessageType.disconnect, Duplicate = false, Retain = false, Qos = MqttQos.atMostOnce, Size = 0

2017-11-02 21:07:30.338255 -- MqttConnectionHandler::sendMessage - not connected

from mqtt_client.

shamblett avatar shamblett commented on August 30, 2024

Glad its working, I'll leave this issue open for any feedback you may have, also please suggest any improvements/fixes/ etc. to the mqtt_client API itself, there's no better feedback than from people using it.

from mqtt_client.

shamblett avatar shamblett commented on August 30, 2024

Ok, nothing else heard, closing

from mqtt_client.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.