shamblett / mqtt5_client

A server and browser based MQTT 5 client for dart
Other
51 stars 29 forks source link

byte integer is null or empty error #17

Closed shailu95 closed 3 years ago

shailu95 commented 3 years ago

While running your example is giving an error MqttByteIntegerEncoding::toInt byte integer is null or empty

shamblett commented 3 years ago

Which example? Please specify the example in question turn on logging and post the output.

shailu95 commented 3 years ago

mqtt5_client_publish_qos1.dart

I was trying to connect through local network (192.168.0.252) with topic 'GtoA'

Invalid argument(s): MqttByteIntegerEncoding::toInt byte integer is null or empty

0 MqttVariableByteIntegerEncoding.toInt (package:mqtt5_client/src/encoding/mqtt_variable_byte_integer_encoding.dart:25:7)

1 MqttPropertyContainer.readFrom (package:mqtt5_client/src/messages/properties/mqtt_property_container.dart:102:23)

2 MqttConnectAckVariableHeader.readFrom (package:mqtt5_client/src/messages/connectack/mqtt_connect_ack_variable_header.dart:265:18)

3 new MqttConnectAckVariableHeader.fromByteBuffer (package:mqtt5_client/src/messages/connectack/mqtt_connect_ack_variable_header.dart:18:5)

4 MqttConnectAckMessage.readFrom (package:mqtt5_client/src/messages/connectack/mqtt_connect_ack_message.dart:96:38)

5 new MqttConnectAckMessage.fromByteBuffer (package:mqtt5_client/src/messages/connectack/mqtt_connect_ack_message.dart:27:5)

6 MqttMessageFactory.getMessage (package:mqtt5_client/src/messages/mqtt_message_facto<…>

flutter: EXAMPLE::client exception - mqtt-client::NoConnectionException: The maximum allowed connection attempts ({3}) were exceeded. The broker is not responding to the connection request message (Missing Connection Acknowledgement? flutter: EXAMPLE::OnDisconnected client callback - Client disconnection flutter: EXAMPLE::OnDisconnected callback is solicited, topic has NOT been notified - this is an ERROR

shamblett commented 3 years ago

Your problem is here -

flutter: EXAMPLE::client exception - mqtt-client::NoConnectionException: The maximum allowed connection attempts ({3}) were exceeded. The broker is not responding to the connection request message (Missing Connection Acknowledgement?

You are not connecting to the broker.

shailu95 commented 3 years ago

flutter: EXAMPLE::Mqtt5 client connecting.... flutter: 2021-10-11 13:01:21.957950 -- MqttConnectionHandlerBase::connect - server 192.168.0.252, port 1883 flutter: 2021-10-11 13:01:21.969776 -- MqttSynchronousServerConnectionHandler::internalConnect entered flutter: 2021-10-11 13:01:21.973088 -- MqttSynchronousServerConnectionHandler::internalConnect - initiating connection try 0, auto reconnect in progress false flutter: 2021-10-11 13:01:21.974978 -- MqttSynchronousServerConnectionHandler::internalConnect - insecure TCP selected flutter: 2021-10-11 13:01:21.976851 -- MqttSynchronousServerConnectionHandler::internalConnect - calling connect flutter: 2021-10-11 13:01:21.978557 -- MqttNormalConnection::connect- entered flutter: 2021-10-11 13:01:22.300028 -- MqttServerConnection::_startListening flutter: 2021-10-11 13:01:22.302509 -- MqttSynchronousServerConnectionHandler::internalConnect - connection complete flutter: 2021-10-11 13:01:22.302764 -- MqttSynchronousServerConnectionHandler::internalConnect sending connect message flutter: 2021-10-11 13:01:22.303423 -- MqttConnectionHandlerBase::sendMessage - sending message started >>> -> MQTTMessage of type MqttMessageType.connect MessageType = MqttMessageType.connect Duplicate = false Retain = false Qos = atMostOnce Size = 0 ProtocolName = MQTT ProtocolVersion = 5 ConnectFlags = CleanStart=true, WillFlag=false, WillQos=atMostOnce, WillRetain=false, PasswordFlag=false, UserNameFlag=false KeepAlive = 0 Properties = No properties setWill topic = null User name = not set Password = not set flutter: 2021-10-11 13:01:22.319219 -- MqttConnectionHandlerBase::sendMessage - sending message ended >>> flutter: 2021-10-11 13:01:22.321133 -- MqttSynchronousServerConnectionHandler::internalConnect - pre sleep, state = Connection status is connecting with return code of notSet and a disconnection origin of none flutter: 2021-10-11 13:01:22.799692 -- MqttServerConnection::_onData - Message Received Started <<< flutter: 2021-10-11 13:01:22.800169 -- MqttServerConnection::_ondata - adding incoming data, data length is 4, message stream length is 0, message stream position is 0 [VERBOSE-2:ui_dart_state.cc(199)] Unhandled Exception: Invalid argument(s): MqttByteIntegerEncoding::toInt byte integer is null or empty

0 MqttVariableByteIntegerEncoding.toInt (package:mqtt5_client/src/encoding/mqtt_variable_byte_integer_encoding.dart:25:7)

1 MqttPropertyContainer.readFrom (package:mqtt5_client/src/messages/properties/mqtt_property_container.dart:102:23)

2 MqttConnectAckVariableHeader.readFrom (package:mqtt5_client/src/messages/connectack/mqtt_connect_ack_variable_header.dart:265:18)

3 new MqttConnectAckVariableHeader.fromByteBuffer (package:mqtt5_client/src/messages/connectack/mqtt_connect_ack_variable_header.dart:18:5)

4 MqttConnectAckMessage.readFrom (package:mqtt5_client/src/messages/connectack/mqtt_connect_ack_message.dart:96:38)

5 new MqttConnectAckMessage.fromByteBuffer (package:mqtt5_client/src/messages/connectack/mqtt_connect_ack_message.dart:27:5)

6 MqttMessageFactory.getMessage (package:mqtt5_client/src/messages/mqtt_message_facto<…>

flutter: 2021-10-11 13:01:27.323957 -- MqttSynchronousServerConnectionHandler::internalConnect - post sleep, state = Connection status is connecting with return code of notSet and a disconnection origin of none flutter: 2021-10-11 13:01:27.324512 -- MqttSynchronousServerConnectionHandler::internalConnect - initiating connection try 1, auto reconnect in progress false flutter: 2021-10-11 13:01:27.325249 -- MqttSynchronousServerConnectionHandler::internalConnect - insecure TCP selected flutter: 2021-10-11 13:01:27.325717 -- MqttSynchronousServerConnectionHandler::internalConnect - calling connect flutter: 2021-10-11 13:01:27.326753 -- MqttNormalConnection::connect- entered flutter: 2021-10-11 13:01:27.332799 -- MqttServerConnection::_startListening flutter: 2021-10-11 13:01:27.333613 -- MqttSynchronousServerConnectionHandler::internalConnect - connection complete flutter: 2021-10-11 13:01:27.334004 -- MqttSynchronousServerConnectionHandler::internalConnect sending connect message flutter: 2021-10-11 13:01:27.334304 -- MqttConnectionHandlerBase::sendMessage - sending message started >>> -> MQTTMessage of type MqttMessageType.connect MessageType = MqttMessageType.connect Duplicate = false Retain = false Qos = atMostOnce Size = 58 ProtocolName = MQTT ProtocolVersion = 5 ConnectFlags = CleanStart=true, WillFlag=false, WillQos=atMostOnce, WillRetain=false, PasswordFlag=false, UserNameFlag=false KeepAlive = 0 Properties = No properties setWill topic = null User name = not set Password = not set flutter: 2021-10-11 13:01:27.335622 -- MqttConnectionHandlerBase::sendMessage - sending message ended >>> flutter: 2021-10-11 13:01:27.335897 -- MqttSynchronousServerConnectionHandler::internalConnect - pre sleep, state = Connection status is connecting with return code of notSet and a disconnection origin of none flutter: 2021-10-11 13:01:27.425119 -- MqttConnectionBase::_onDone - calling disconnected callback flutter: 2021-10-11 13:01:27.428415 -- MqttServerConnection::_onData - Message Received Started <<< flutter: 2021-10-11 13:01:27.428886 -- MqttServerConnection::_ondata - adding incoming data, data length is 4, message stream length is 0, message stream position is 0 [VERBOSE-2:ui_dart_state.cc(199)] Unhandled Exception: Invalid argument(s): MqttByteIntegerEncoding::toInt byte integer is null or empty

0 MqttVariableByteIntegerEncoding.toInt (package:mqtt5_client/src/encoding/mqtt_variable_byte_integer_encoding.dart:25:7)

1 MqttPropertyContainer.readFrom (package:mqtt5_client/src/messages/properties/mqtt_property_container.dart:102:23)

2 MqttConnectAckVariableHeader.readFrom (package:mqtt5_client/src/messages/connectack/mqtt_connect_ack_variable_header.dart:265:18)

3 new MqttConnectAckVariableHeader.fromByteBuffer (package:mqtt5_client/src/messages/connectack/mqtt_connect_ack_variable_header.dart:18:5)

4 MqttConnectAckMessage.readFrom (package:mqtt5_client/src/messages/connectack/mqtt_connect_ack_message.dart:96:38)

5 new MqttConnectAckMessage.fromByteBuffer (package:mqtt5_client/src/messages/connectack/mqtt_connect_ack_message.dart:27:5)

6 MqttMessageFactory.getMessage (package:mqtt5_client/src/messages/mqtt_message_facto<…>

flutter: 2021-10-11 13:01:32.342373 -- MqttSynchronousServerConnectionHandler::internalConnect - post sleep, state = Connection status is connecting with return code of notSet and a disconnection origin of none flutter: 2021-10-11 13:01:32.342991 -- MqttSynchronousServerConnectionHandler::internalConnect - initiating connection try 2, auto reconnect in progress false flutter: 2021-10-11 13:01:32.343330 -- MqttSynchronousServerConnectionHandler::internalConnect - insecure TCP selected flutter: 2021-10-11 13:01:32.344122 -- MqttSynchronousServerConnectionHandler::internalConnect - calling connect flutter: 2021-10-11 13:01:32.344979 -- MqttNormalConnection::connect- entered flutter: 2021-10-11 13:01:32.417624 -- MqttServerConnection::_startListening flutter: 2021-10-11 13:01:32.418173 -- MqttSynchronousServerConnectionHandler::internalConnect - connection complete flutter: 2021-10-11 13:01:32.419149 -- MqttSynchronousServerConnectionHandler::internalConnect sending connect message flutter: 2021-10-11 13:01:32.420201 -- MqttConnectionHandlerBase::sendMessage - sending message started >>> -> MQTTMessage of type MqttMessageType.connect MessageType = MqttMessageType.connect Duplicate = false Retain = false Qos = atMostOnce Size = 58 ProtocolName = MQTT ProtocolVersion = 5 ConnectFlags = CleanStart=true, WillFlag=false, WillQos=atMostOnce, WillRetain=false, PasswordFlag=false, UserNameFlag=false KeepAlive = 0 Properties = No properties setWill topic = null User name = not set Password = not set flutter: 2021-10-11 13:01:32.421662 -- MqttConnectionHandlerBase::sendMessage - sending message ended >>> flutter: 2021-10-11 13:01:32.421959 -- MqttSynchronousServerConnectionHandler::internalConnect - pre sleep, state = Connection status is connecting with return code of notSet and a disconnection origin of none flutter: 2021-10-11 13:01:32.485119 -- MqttConnectionBase::_onDone - calling disconnected callback flutter: 2021-10-11 13:01:32.640800 -- MqttServerConnection::_onData - Message Received Started <<< flutter: 2021-10-11 13:01:32.641362 -- MqttServerConnection::_ondata - adding incoming data, data length is 4, message stream length is 0, message stream position is 0 [VERBOSE-2:ui_dart_state.cc(199)] Unhandled Exception: Invalid argument(s): MqttByteIntegerEncoding::toInt byte integer is null or empty

0 MqttVariableByteIntegerEncoding.toInt (package:mqtt5_client/src/encoding/mqtt_variable_byte_integer_encoding.dart:25:7)

1 MqttPropertyContainer.readFrom (package:mqtt5_client/src/messages/properties/mqtt_property_container.dart:102:23)

2 MqttConnectAckVariableHeader.readFrom (package:mqtt5_client/src/messages/connectack/mqtt_connect_ack_variable_header.dart:265:18)

3 new MqttConnectAckVariableHeader.fromByteBuffer (package:mqtt5_client/src/messages/connectack/mqtt_connect_ack_variable_header.dart:18:5)

4 MqttConnectAckMessage.readFrom (package:mqtt5_client/src/messages/connectack/mqtt_connect_ack_message.dart:96:38)

5 new MqttConnectAckMessage.fromByteBuffer (package:mqtt5_client/src/messages/connectack/mqtt_connect_ack_message.dart:27:5)

6 MqttMessageFactory.getMessage (package:mqtt5_client/src/messages/mqtt_message_facto<…>

flutter: 2021-10-11 13:01:37.428013 -- MqttSynchronousServerConnectionHandler::internalConnect - post sleep, state = Connection status is connecting with return code of notSet and a disconnection origin of none flutter: 2021-10-11 13:01:37.428633 -- MqttSynchronousServerConnectionHandler::internalConnect failed flutter: EXAMPLE::client exception - mqtt-client::NoConnectionException: The maximum allowed connection attempts ({3}) were exceeded. The broker is not responding to the connection request message (Missing Connection Acknowledgement? flutter: 2021-10-11 13:01:37.434148 -- MqttConnectionHandlerBase::disconnect flutter: 2021-10-11 13:01:37.434653 -- MqttConnectionHandlerBase::_performConnectionDisconnect entered flutter: EXAMPLE::OnDisconnected client callback - Client disconnection flutter: EXAMPLE::OnDisconnected callback is solicited, topic has NOT been notified - this is an ERROR

shamblett commented 3 years ago

Connection isn't complete until a connect ack message is received, this is not happening -

flutter: 2021-10-11 13:01:22.800169 -- MqttServerConnection::_ondata - adding incoming data, data length is 4, message stream length is 0, message stream position is 0
[VERBOSE-2:ui_dart_state.cc(199)] Unhandled Exception: Invalid argument(s): MqttByteIntegerEncoding::toInt byte integer is null or empty

This should be a valid connect ack message, it can't have a length of 4, if your broker finds something wrong with the connect message it should close the connection, if not it should send a connect ack. It shouldn't send an empty packet. Maybe check your broker logs.

shamblett commented 3 years ago

This is an mqtt5 client not a 3 client your broker must bevable to use the mqtt5 protocol

shailu95 commented 3 years ago

Thank you, I was using wrong version