Comments (9)
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.
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.
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.
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.
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.
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.
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.
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.
Ok, nothing else heard, closing
from mqtt_client.
Related Issues (20)
- retain:true publishing issue (using IoT Core) HOT 3
- Differences in automatic reconnection between IOS and Android HOT 1
- '400 Bad Request' response while connecting with websocket to rabbitmq HOT 3
- How to connect mqtt with socket header options? HOT 3
- mqttjs:client _checkPing :: checking ping... Runs twice in rapid succession some times HOT 1
- How to determine the cause of the disconnect? HOT 1
- Available bytes is less than the message size HOT 4
- error:Bad state: Cannot add new events after calling close HOT 8
- AWS IoT Certificate - Use .bks file certificate HOT 1
- NoConnectionException: Missing Connection Acknowledgement HOT 4
- Ping triggers client.update and brings the same message multiple times HOT 1
- How can I receive a complete offline message? HOT 1
- Unhandled Exception: mqtt-client::NoConnectionException: MqttWs2Connection::TLS connection unexpectedly closed HOT 15
- onDisconnect callback when autoconnect is false or onAutoReconnect callback when autoconnect is set to true not invoking immediately in ios when wifi is turned off HOT 2
- Review outdated packages in version 10.3.0 HOT 1
- Parsing problems for web socket URLs HOT 2
- How can i subscribe multi topic? HOT 2
- CERTIFICATE_VERIFY_FAILED: unable to get local issuer certificate HOT 4
- Dependency Resolution Failure after upgrading to 10.4.0 HOT 8
- Problems maintaining connection to AWS IoT MQTT broker: Connection was not upgraded to websocket HOT 11
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mqtt_client.