0

Not publishing using mqtt client within Flutter/Dart
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Not publishing using mqtt client within Flutter/Dart

by sketchy on Mon Feb 11, 2019 3:10 pm

I am attempting to publish to a feed I have within a Flutter app using the mqtt client packagehttps://github.com/shamblett/mqtt_client

I am not able to publish.

I was wrong in my assumption so I am editing this post.

The matt Dart package I am using logs the warning:
```MqttConnectPayload::Client id exceeds spec value of 23``` . Adafruit.io has nothing to do with this, other than the AIO key is 40 bytes.

The author of the package (shamblett) https://github.com/shamblett/mqtt_client/issues/73told me:

This is just a warning in that the MQTT 3.1 spec states that the Client Identifier must be 23 characters in length. In practice this isn't always respected by most commercial brokers, also in V3.1.1 this is relaxed to 65535. I should really check the version you have set before printing this and only print it for v3.1, it can be safely ignored.
any advice appreciated. thank you.

It appears Adafruit.io confirms I am connected, but then disconnects me.

sketchy
 
Posts: 217
Joined: Thu Jun 28, 2012 11:37 pm

Re: Not publishing using mqtt client within Flutter/Dart

by sketchy on Tue Feb 12, 2019 9:41 am

Can you please check the logs to see what Adafruit.io is doing with the publish message i sent? I'm thinking the broker sees the publish message and disconnects. Here is the mqtt traffic from publishing
Code: Select all | TOGGLE FULL SIZE
flutter: 2019-02-12 05:42:40.293194 -- MqttConnectionHandler::sendMessage - MQTTMessage of type MqttMessageType.publish
Header: MessageType = MqttMessageType.publish, Duplicate = false, Retain = false, Qos = MqttQos.atMostOnce, Size = 0
Publish Variable Header: TopicName={sketchy/feeds/test}, MessageIdentifier={1}, VH Length={0}
Payload: {8 bytes={<24><0><0><0><0><0><0><0>
flutter: 2019-02-12 05:42:40.374700 -- MqttConnection::_onDone - calling disconnected callback
flutter: MQTT client disconnected

sketchy
 
Posts: 217
Joined: Thu Jun 28, 2012 11:37 pm

Re: Not publishing using mqtt client within Flutter/Dart

by sketchy on Tue Feb 12, 2019 9:50 am

Some of my original publish messages had a non-supported QoS (exactly once). The recent publish messages used a QoS of at most once or at least once.

sketchy
 
Posts: 217
Joined: Thu Jun 28, 2012 11:37 pm

Re: Not publishing using mqtt client within Flutter/Dart

by abachman on Tue Feb 12, 2019 7:00 pm

Hi sketchy,


It's difficult to fully interpret your logs, not being familiar with Dart or the library, but what value are you trying to publish? Adafruit IO only accepts and stores valid utf-8 encoded strings, so you may need to do some conversion in your app before publishing.


- Adam B.

abachman
 
Posts: 265
Joined: Mon Feb 01, 2010 12:48 pm

Re: Not publishing using mqtt client within Flutter/Dart

by sketchy on Tue Feb 12, 2019 7:25 pm

Thank you. I am trying to publish the int value 24.

sketchy
 
Posts: 217
Joined: Thu Jun 28, 2012 11:37 pm

Re: Not publishing using mqtt client within Flutter/Dart

by sketchy on Tue Feb 12, 2019 7:34 pm

I just tried sending a utf-8 encoded string. Same challenge. I can connect. However, when i publish, i am immediately disconnected. it is unfortunate there seems to be no way to determine what Adafruit.io did with the publish message.

sketchy
 
Posts: 217
Joined: Thu Jun 28, 2012 11:37 pm

Re: Not publishing using mqtt client within Flutter/Dart

by abachman on Thu Feb 14, 2019 12:27 pm

Hi sketchy,


Looking a bit deeper, there are a few ways publish events can trigger a disconnection:
  • failing to authenticate on connection. IO allows anonymous MQTT connections, but if you try to publish it'll drop the connection.
  • Attempting to publish to a feed you do not own.
  • Attempting to publish to a feed that was shared with you in read-only mode.
  • Attempting to publish after being temporarily banned for sending too many throttled messages in a short window.

Is it possible you're hitting one of those scenarios? Do you have any sample code or an example project that demonstrates the issue?

- adam b.

abachman
 
Posts: 265
Joined: Mon Feb 01, 2010 12:48 pm

Re: Not publishing using mqtt client within Flutter/Dart

by sketchy on Thu Feb 14, 2019 1:01 pm

THANK YOU for your detailed response. Actually, all I really need from the Flutter/Dart client is subscription - and I was able to get that to work. So I'm not going to pursue debugging any deeper at this point. I am using a 3rd party client, so part of the challenge is not fully understanding this code. On top of that, Dart programming is new to me. With all that said, i'm inclined to think the other thing I don't understand perhaps is correctly setting read/write permissions on a feed.

sketchy
 
Posts: 217
Joined: Thu Jun 28, 2012 11:37 pm

Re: Not publishing using mqtt client within Flutter/Dart

by abachman on Thu Feb 14, 2019 1:31 pm

If you're authenticating the MQTT connection with your username + AIO key, then there aren't any extra permissions you need to change.

Looking at the mqtt_client repo examples, I notice that the mqtt_client example and Flutter example code both log in anonymously, you'll have to add a username and password to the client.connect() call in both cases to properly authenticate. Your Adafruit IO username and key are what you're need in that case.

Is it possible you're putting your Adafruit IO key in the client identifier field instead of the password field? The client ID error message you originally got suggests you might be. For an MQTT client ID, It would be best to set it to a random string of 23 characters or fewer. If you're intending to run multiple instances of the same application (like a mobile app running on multiple devices), you'll also need to make sure each instance's client ID is unique.

I am using a 3rd party client, so part of the challenge is not fully understanding this code. On top of that, Dart programming is new to me.


No worries, new to me too, we can still take a good shot at debugging :D

If you are able to eventually share a working example on Github, though, it would be a huge help to anyone who wants to build an app like yours or hits a similar issue to this in the future.


- adam b.

abachman
 
Posts: 265
Joined: Mon Feb 01, 2010 12:48 pm

Please be positive and constructive with your questions and comments.