Closed tobeedelafuente closed 5 years ago
Your client id in the example above is .withClientIdentifier('Mqtt_MyClientUniqueId'), however in the picture it seems to be a user generated string, you may need to check the broker docs about how to generate the client id.
Thanks for the reply Steve. As long as the client identifier string is unique there is no problem with the broker. MQTT.fx has a feature to generate a unique string though I could use any.
OK, found the bug, for now add this to your connection message setup
.authenticateAs(username, password);
The username/password passed in to the connect method id not being reflected into the connect method correctly.
Thanks Steve! The .authenticateAs(username, password)
clearly solved the issue! Kudos to you for this library 👍
Here's the updated code:
String broker = "mq.meeo.xyz";
String username = "md-hi75gqj";
String password = "some-password";
void _connect() async {
client = mqtt.MqttClient(broker, '');
client.logging(on: true);
client.onDisconnected = _onDisconnected;
....
final mqtt.MqttConnectMessage connMess = mqtt.MqttConnectMessage()
.withClientIdentifier('Mqtt_MyClientUniqueId')
.keepAliveFor(20) // Must agree with the keep alive set above or not set
.withWillTopic('willtopic') // If you set this you must set a will message
.withWillMessage('My Will message')
.startClean() // Non persistent session for testing
.authenticateAs(username, password) // additional code when connecting to a broker w/ creds
.withWillQos(mqtt.MqttQos.atLeastOnce);
print('EXAMPLE::Mosquitto client connecting....');
client.connectionMessage = connMess;
...
try {
await client.connect(username, password);
} catch (e) {
print("ERROR: " + e.toString());
}
}
Hello! I am trying to make a flutter app that connects to the MQTT server of meeo.xyz. I verified that I am able to connect to it by setting the credentials using MQTT.fx
When I try with mqtt_client, I get this error:
Here's my code:
I don't get it as to why I am getting a badUsernameOrPassword error but it is fine in MQTT.fx. Am I missing something for the setup? I've tried setting the
useWebsocket
as well but I am still having a problem connecting to the MQTT server.Any help would be deeply appreciated