jnguillerme / mqtt.dart

dart mqtt client
BSD 2-Clause "Simplified" License
51 stars 16 forks source link

ecodeVariableHeader not in range error #10

Closed Hecatoncheir closed 6 years ago

Hecatoncheir commented 6 years ago

For subscribe to message with that route: server.log.web.test.a8fe5020-d2d0-11e7-d08b-6d9310df6f6b I try use : subscribe("server.*.*.*.*") or subscribe("server.#") and I get error: RangeError (end): Invalid value: Not in range

 RangeError (end): Invalid value: Not in range 2..162, inclusive: 258
  dart:typed_data                                    _TypedListBase.sublist
  package:mqtt/mqtt_message_publish.dart 90:31       MqttMessagePublish.decodeVariableHeader
  package:mqtt/mqtt_message.dart 45:17               new MqttMessage.decode
  package:mqtt/mqtt_message_publish.dart 29:140      new MqttMessagePublish.decode
  package:mqtt/mqtt_client.dart 316:34               MqttClient._handlePublish
  package:mqtt/mqtt_client.dart 218:30               MqttClient._processMqttMessage
  package:mqtt/mqtt_client.dart 193:16               MqttClient._processData
  package:mqtt/mqtt_connection_io_socket.dart 32:29  MqttConnectionIOSocket.startListening.<fn>
  ===== asynchronous gap ===========================
  dart:io                                            _Socket.listen
  package:mqtt/mqtt_connection_io_socket.dart 31:13  MqttConnectionIOSocket.startListening
  package:mqtt/mqtt_client.dart 162:21               MqttClient._handleConnected
  package:mqtt/mqtt_client.dart 54:49                MqttClient.connect.<fn>
  ===== asynchronous gap ===========================
  dart:async                                         _Future.then
  package:mqtt/mqtt_client.dart 54:31                MqttClient.connect

But for route server.log.web.test subscribe:subscribe("server.*.*.*") work fine.

I miss something?

jnguillerme commented 6 years ago

Hi, I would actually not expect server...* to work. In MQTT, the topic level separator is /. Wildcards characters are + and #. For route server/log/web/test.a8fe5020-d2d0-11e7-d08b-6d9310df6f6b, I've tested subscribe server/+/+/+ and subscribe server/# and both work fine.

You can get more details there: https://www.hivemq.com/blog/mqtt-essentials-part-5-mqtt-topics-best-practices

kind regards,

Jean-Noel

Hecatoncheir commented 6 years ago

Hi,thanks for your answer. I make test like: https://gist.github.com/Rasarts/01d94b122ee1a96f259aa8353f57afd4 And I get error. Maybe it didn't work with QOS_1?

jnguillerme commented 6 years ago

Hi, I didn't manage to reproduce your error. I tried with QOS_1 and that worked. Could you please confirm the MQTT version of your broker? I've tested with Mosquitto, but you may be using a different broker. If so I would try to test using the same broker as yours. thanks.

Hecatoncheir commented 6 years ago

I use RabbitMQ with Web MQTT Plugin. With route like client1.subscribe('test queue', QOS_1,...)and await client2.publish('test queue',..) work fine.

jnguillerme commented 6 years ago

Hi, As you are connecting through websocket you shouldn't use a MqttConnectionIOSocket to create your connection. Instead you should use a MqttConnectionIOWebSocket

There is a sample of using mqtt.dart over websocked under examples/mqtt_web.

Let me know if that fixes the issue.

Hecatoncheir commented 6 years ago

Hi, It's not work, too.

https://gist.github.com/Rasarts/01d94b122ee1a96f259aa8353f57afd4 If I replace:

await client2.publish(
          'server.log.web.test.a8fe5020-d2d0-11e7-d08b-6d9310df6f6b',
          JSON.encode(sendedEntity));

to

await client2.publish(
          'server.log.web.test',
          JSON.encode(sendedEntity));

Then it's work, I can get message. But I need that uuid in path.

ewoutp commented 6 years ago

I'm getting the same error message when using a message payload that is a bit longer.

The topic is always the same: /binkyrailways/data

The payload is UTF8 encoded: Short payloads work. E.g.

{"type":"running"}

Longer payloads fail. E.g.

{"description":"Zwitserlandbaan (Dortmund)","locs":[{"description":"foo","owner":"Ewout"},{"description":"foo","owner":"Sjraar"},{"description":"foo","owner":"Sjraar"},{"description":"foo","owner":"Sjraar"},{"description":"foo","owner":"Sjraar"},{"description":"foo","owner":"Ewout"},{"description":"foo","owner":"Ewout"},{"description":"foo","owner":"Sjraar"},{"description":"foo","owner":"Ewout"},{"description":"foo","owner":"Sjraar"},{"description":"foo","owner":"Ewout"},{"description":"foo","owner":"Sjraar"},{"description":"foo","owner":"Ewout"},{"description":"foo","owner":"Sjraar"},{"description":"foo","owner":"Ewout"}],"type":"railway"}

Using mosquito broker. mqttcli shows the topic as I expected it.

Additional info. I'm using it in flutter with socket IO.

Hecatoncheir commented 6 years ago

I get error now: Connection Refused: bad user name or password It's worked before.

  Connection Refused: bad user name or password
  dart:async                                         _Completer.completeError
  package:mqtt/mqtt_client.dart 295:18               MqttClient._handleConnack
  package:mqtt/mqtt_client.dart 226:30               MqttClient._processMqttMessage
  package:mqtt/mqtt_client.dart 207:19               MqttClient._processData
  package:mqtt/mqtt_connection_io_socket.dart 32:29  MqttConnectionIOSocket.startListening.<fn>
  ===== asynchronous gap ===========================
  dart:io                                            _Socket.listen
  package:mqtt/mqtt_connection_io_socket.dart 31:13  MqttConnectionIOSocket.startListening
  package:mqtt/mqtt_client.dart 169:21               MqttClient._handleConnected
  package:mqtt/mqtt_client.dart 52:49                MqttClient.connect.<fn>
  ===== asynchronous gap ===========================
  dart:async                                         _Future.then
  package:mqtt/mqtt_client.dart 52:31                MqttClient.connect
  test/server/mqtt_test.dart 46:21                   main.<fn>.<fn>
  ===== asynchronous gap ===========================
  dart:async                                         new Future.microtask
  test/server/mqtt_test.dart 34:65                   main.<fn>.<fn>
jnguillerme commented 6 years ago

It could be the pull request I merged yesterday. Did you updated to the latest version?

Hecatoncheir commented 6 years ago

Yes, in pubspec.lock I get:

  mqtt:
    description:
      ref: master
      resolved-ref: b115db58f1918906662d7ceb3fd092c94986d52c
      url: "https://github.com/jnguillerme/mqtt.dart"
    source: git
    version: "1.0.1"
Hecatoncheir commented 6 years ago

For experiment, to method _openSession I add:

m._userName = this._userName;
m._password =this._password;

Like:

   void _openSession() {
     print("Opening session");
     MqttMessageConnect m = new MqttMessageConnect.setOptions(_clientID, _qos, _cleanSession);

     m._userName = this._userName;
     m._password =this._password;

     if (_userName != null && _password != null) {
       m.setUserNameAndPassword(_userName, _password);
     }

     // set will
     m.setWill(_will);
     _mqttConnection.sendMessageToBroker(m, debugMessage);
   }

And it work now.

jnguillerme commented 6 years ago

It should be fixed with package 1.1.3.