arduino-libraries / ArduinoMqttClient

ArduinoMqttClient Library for Arduino
GNU Lesser General Public License v2.1
187 stars 73 forks source link

Document MQTT version support #26

Closed jiferrero closed 8 months ago

jiferrero commented 4 years ago

Hi,

Which MQTT version does the library currently support? We are struggling our heads to know why our arduino nano 33 iot always get a connection refused when connecting to EMQX 4.x broker but not when connecting to mosquito.

const char broker[] = "test.mosquitto.org";
int port = 1883;
WiFiClient wifiClient;
MqttClient mqttClient(wifiClient);

void setup() {
  Serial.begin(1000000);
  while (!Serial);

  while (WiFi.begin(ssid, pass) != WL_CONNECTED) {
    // failed, retry
    Serial.print(".");
    delay(5000);
  }

  Serial.println("Device connected to the network");

 if (!mqttClient.connect(broker, port)) {
    Serial.print("MQTT connection failed! Error code = ");
    Serial.println(mqttClient.connectError());
    while (1);
  }

  Serial.println("You're connected to the MQTT broker");
}

that ends up with a succesfully connection to "test.mosquitto.org".

But if we use for example: IPAddress broker(192, 168, 1, 33);

then we always ends up with an unsuccessfully connection. We have no idea why... port 1883 is open and accessible from local network but EMQX 4.x broker supports MQTT 3.1.1 and 5.0 Could be that the problem? Any other idea?

Thank you so much in advance

Rocketct commented 4 years ago

Hi @jiferrero i make some test with a nano 33 iot and with a wifi1010, it works fine in both case, i have used the following library and core version:

nina-fw: 1.3.0 WiFiNINA: 1.5.0 ArduinoMqttClient: 0.1.3 samd-core: 1.8.5

and of course EMQX 4.x broker the v. 4.0.3 listening on port: 1883, mosquitto completely disabled because listen on the same port

jjauzion commented 3 years ago

Hi, I also have my Arduino working well with EMQX and this library. But I came here as I was also looking for which version the MQTT protocol is used by this library. @Rocketct do you have the answer ?

chocolatkey commented 8 months ago

For anyone else is coming here looking for an answer to this question, the answer is version MQTT version 3.1.1. How do I know? The library has set level 0x04, which according to the MQTT spec is the identifier for 3.1.1

aentinger commented 8 months ago

@chocolatkey is correct 😉