Git Product home page Git Product logo

Comments (9)

256dpi avatar 256dpi commented on July 30, 2024

Most likely there is some null pointer exception when calling disconnect while not beeing connected. This should be an easy fix in the library.

But the difference between the mega2560 and the esp8266 is weird, since the same code is executed on both platforms. Maybe we can check this again when the issue has been fixed. I'll work on this as soon as I'm back.

from arduino-mqtt.

256dpi avatar 256dpi commented on July 30, 2024

I fixed a bug that might have caused a crash when disconnecting without having any previous connection. Can you give the new v2.1.0 version a try?

from arduino-mqtt.

Teddyz avatar Teddyz commented on July 30, 2024
void mqConnect() {
  uint8_t loops = 0;
  toggle (24, HIGH);
  mq.setWill("node/" MQTT_CLIENTID "/status", "0", true, 0); // ... retained, QoS
  while (!mq.connect(MQTT_CLIENTID, MQTT_USERNAME, MQTT_KEY)) {
    Serial.print('.');
    if (++loops >= 2) {
      toggle (24, LOW);
      return;
    }
    delay(400);
    //mq.disconnect();
  }
  toggle (24, LOW);

  Serial.print(F("\nConnected to mqtt-broker\n"));

  mq.subscribe("node/#");

Tested on v2.1.4. On Mega2560 it still does not reconnect after broker has been offline for a while. (code above). If the broker is offline when Arduino boots up, Mega2560 has no problem connecting to the broker. If I uncomment mq.disconnect(); it works.

Other info:
-ESP8266 now sometimes 'hangs' after I disconnect from broker, use the WiFiClientSecure for another connection and then reconnects to the broker again. They hangs forever, so I physically have to disconnect power to them. The built in watchdog fails. This did not happen on v2.1.3 and earlier.
-One ESP8266 sent information very seldom, often forcing the library to PINGRREQ. This did not work when the client had been online for like 8 hours or more in previous versions. Instead the client was forced offline and then immediately reconnected. This is OK in v2.1.4.

from arduino-mqtt.

giacomopastore avatar giacomopastore commented on July 30, 2024

Hello!

I'm working on Genuino MKR1000 (SAMD21 + ATWINC1500 WiFi module), I'm using connect and publish functions as described in the example.
If I stop/start MQTT broker (Mosquitto) the client is able to recconnects to the broker without problems but often, after some publish commands, the client looses the connection to the broker and it is not able to recover this state, on the server I've got this error:

Client <unknown> has exceeded timeout, disconnecting.
1508254942: Socket error on client <unknown>, disconnecting.

When the program is working correctly all messages in Mosquito log are identified with the correct client id; in this case I have client id. (I don't have other clients running).

from arduino-mqtt.

256dpi avatar 256dpi commented on July 30, 2024

Hi all, I just pushed some commits that may fix the metioned problem (check the git history for what has been changed). It would be awesome if you could rerun your tests with master branch of the library before I release a new version

from arduino-mqtt.

256dpi avatar 256dpi commented on July 30, 2024

I just released v2.2.0 (might take some time to appear in the library manager) that fixes more related issues. Can you check again?

from arduino-mqtt.

skedone avatar skedone commented on July 30, 2024

@256dpi I have the same issue using the latest version (v2.2.0).
I use 800L GPRS modem with a ClientInterface compatible interface (a library I have built).
Whenever a timeout disconnection happens, it doesn't reconnect.

1508819521: Client <IMEI> has exceeded timeout, disconnecting.
1508819521: Socket error on client <IMEI>, disconnecting.

It run for almost 38 hours without a glitch (thanks for the amazing library).
Any idea where to look into?

Here is the code I use:

void setup() {
  mqtt.begin(MQTT_SERVER, client);
  mqtt.setOptions(60, false, 2500);
  mqtt.onMessage(messageReceived);
  mqtt_subscribe();
}

void loop() {
  mqtt.loop();
  if(!mqtt.connected()) {
    mqtt_subscribe();
  }
  ....
}

bool mqtt_subscribe() {
  if (!mqtt.connected()) mqtt_connect();
  mqtt.subscribe("topic/p/" + IMEI, MQTT_QOS);
  mqtt_event_subscribe(); # sending events as soon as the device subscribes
  return true;
}

bool mqtt_connect() {
  if (!mqtt.connected()) {
    Serial.print("\nConnecting to MQTT server...");
    while (!mqtt.connect(IMEI.c_str(), MQTT_USER, MQTT_PASS)) {
      Serial.print(".");
      delay(500);
    }
    mqtt.setWill("topic/testament", IMEI.c_str());
    Serial.print(" [OK]");
  }

  return true;
}

from arduino-mqtt.

giacomopastore avatar giacomopastore commented on July 30, 2024

Now, with my hardware and v2.2.0 runs without problems. Thanks!

from arduino-mqtt.

Teddyz avatar Teddyz commented on July 30, 2024

The first issue, that the code refuse to reconnect when the broker is online again is solved in v2.2.0. Good work!
Second issue with ESP rebooting if a disconnect() is issued while having no connection on ESP8266 also passed the test. No restarts.

Thanks!

from arduino-mqtt.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.