0

I use an MQTT to communicate with an ESP8266. I'm using cloudmqtt.com and PubSubClient. Sometimes the ESP disconnects from the MQTT and reconnects. I checked the log from cloud and I got this data

2019-02-18 20:11:18: New connection from 89.64.15.184 on port 18127.

2019-02-18 20:11:22: New connection from 89.64.15.184 on port 18127.

2019-02-18 20:11:35: New connection from 89.64.15.184 on port 18127.

2019-02-18 20:11:35: New client connected from 89.64.15.184 as ESP8266Client-80:7D:3A:69:6C:2E (c1, k15, u'userName').

2019-02-18 20:11:53: Client <unknown> has exceeded timeout, disconnecting.

2019-02-18 20:11:53: Socket error on client <unknown>, disconnecting.

2019-02-18 20:11:56: Saving in-memory database to /var/lib/mosquitto/18127/db.

2019-02-18 20:11:58: Client ESP8266Client-80:7D:3A:69:6C:2E has exceeded timeout, disconnecting.

in setup I have this method:

void setupMQTT() {

  while (!client.connected()) {
    Serial.println("Connecting to MQTT...");
    String clientId = "ESP8266Client-";
    clientId += WiFi.macAddress();
    if (client.connect(clientId.c_str(), mqttUser, mqttPassword )) {

      Serial.println("connected");

    } else {

      Serial.print("failed with state ");
      Serial.print(client.state());
      delay(2000);

    }
  }
  client.publish("esp/blind/out", "hello world");
  client.subscribe("esp/blind/in");
}

and in loop I have

client.loop();

without any delay.

I think that the ESP id in MQTT cloud is unique, because I use the MAC address.

  • which version of arduino/esp8266 are you using - I ask, because I had to put in a delay(10) or so in loop for some ESP chips when using the latest (2.5.0dev) branch – Jaromanda X Feb 19 at 0:42
  • I use wemos D1 mini with ESP-12F and about month ago I update firmware because I wanted to try micropython – Michał Urban Feb 19 at 8:40
  • but your code isn't written in micropython .... it looks like typical arduino (i.e. C/C++) ... which version of the esp8266 arduino core are you using? Actually, nevermind, try adding a delay(10) in your main loop or even a yield() – Jaromanda X Feb 19 at 9:26
  • no it isn't written in micropython it's written in c++, adding delay(10) do nothing. How can I check a esp8266 arduino core version ? – Michał Urban Feb 19 at 20:30
  • you downloaded it and installed it ... what did you download and install ... another possibility is the router you connect to- which make model? (e.g I have a linksys wrt32x - and ESP's have lots of issues staying connected to it)\ – Jaromanda X Feb 19 at 20:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.