-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
strange issue Attempting MQTT connection…failed, rc=-2 try again in 5 seconds #604
Comments
No idea - sorry. My guess would be that toggling D6 is causing some interference with the network hardware. A quick google doesn't reveal anything. You may want to ask on a more ESP-focussed forum - the PubSubClient uses whatever network client you give it. This issue is at a lower level then anything the PubSubClient has to handle. |
dear, I tried D6 and D7 and D8 same result this is the code at callback void callback(char* topic, byte* payload, unsigned int length) { if (strcmp(topic,string1) ==0){ if (stringTwo == "connect"){ if (out1_state == 0){ if (out2_state == 1){ if (out2_state == 0){ if (out3_state == 1){ if (out3_state == 0){
}
}
}
}
}
}
}
}
}
} if (stringTwo == "out3 on"){
}
} if (stringTwo == "out4 off"){
}
}
}
} |
Hello, regards, |
Hello, I can get the same "periodic reconnection" behavior with a simplified version of one of the git examples. And without changing pins, no hardware involved. Console Out:
Client:ESP8266 (Wemos d1 mini) Server:mosquitto version 1.6.1 The sketch is a simplified version of the git example
Did someone find a solution? Regards, Ric |
Maybe it`s power issue - try another port, cable, computer (or powerbank or phone charger). |
Thanks for your suggestion Dmytro. At this time it works better, only a few reconnections per day. The main problem was a strange configuration in the router's DHCP service. Regards, |
What strange configuration? |
I'm late to this party and have had the same issues. I tracked mine down to a Tp-link router configured with short (1 min) DHCP lease time. The continual lease expiry drags down the MQTT connection. |
Sorry for the late reply, |
Hi, |
I found this thread because I was having similar issues. The Wemos D1 Minis connect to my wireless access point just fine, dnsmasq assigns them fixed IPs based on their mac addresses and I can ping them without any problems. In my case, it does appear that changing my dhcp/dns server caused the problem but switching back is sadly not an option as the windows server suffered a hardware failure (the reason to switch to dnsmasq on the Pi). Other than this MQTT issue, the rest of my network is working fine with dnsmasq, I have 70+ networked devices, 30 of which connect via wifi and 10 of these are wemos minis. The other wifi devices work fine (phones, tablets, laptops, Amazon Echos, TP-Link HS100/HS110s) I'll continue testing and report back. |
I fixed my issue although I suspect my problem was unrelated to the problems others have reported in this thread. Strangely, Windows and Linux didn't have any issues pinging "mqtt" even before I added cname=mqtt,hs14 they just seem to understand that they all live in the same domain. Just a thought but now I can see why I was getting the Attempting MQTT connection...failed, rc=-2 it would make sense that the same error would be issued if the MQTT server had changed IP address or was otherwise uncontactable. Anyone getting that message should probably check that their MQTT server has a fixed IP and/or hostname name that can be resolved to the correct IP. Sorry I couldn't help with the OP's issue. |
This comment has been minimized.
This comment has been minimized.
I also installed back over Board Manager core 2.4.2, and it started working again! Thanks for your hint!! |
This was my issue and my solution: I have a mqtt server and a client in a Raspberry Pi and another client in a ESP8266. I had one or two reconnections per week, until I changed my router. I had the described issue, with 3 or 4 reconnections every 10 minutes, getting rc=-2 during attemps. I solved it checking free channels in the surrounding wifis and changing the channel of my wifi to a free channel. A lot of routers have an "Auto" to find free channels as well. Hope this helps :) |
I encouter this problem too. I want to briefly explain what got wrong. Firstly, I tried this library and it worked perfectly. Although, I worked with ThingSpeak.h module github/thingspeak-arduino where it worked. Thus I tested again the MQTT, implementing this module and I get this error. Any ideas will be valuable. |
I had the same issues and it was driving me mad because I had it working and after delivering a few working devices (and of course updating my code) it stopped working. I finally figured it out. I changed the mqttServer from a DNS name to an IP. This is what broke it. I just changed it back to a server name that can resolve on DNS without changing anything else and the error disappeared. |
Since a few days I have the same problems with a esp32 ttgo epaper board. I use the deep sleep mode. Therefore the board wents to sleep for 30 seconds, wakes up and tries to reconnect to the MQTT-server. That works fine for the probably first 5 times and then stucks. In the meantime I set the deep sleep time to 120 seconds and now it works fine. |
Hi, in my case it was the usesage of when i uncomment these my mqtt connection stays up. is there a solution for these on esp8266 (Wemos d1)? regards maik |
found another solution for my code
changed to:
when i put
in front off all the rest of the code, it works!? found this solution in regards maik |
more when i comment the line out, the mqtt errors comes back that could be a timing problem, because when add the a delay between
the connection stays good regards maik |
I got the same error and the problem was in the certificate string was missing letter. |
If you use Platformio, try to change platform version |
Use this solution #138 (comment) |
i get the same problem too.. and this i configure in my program for the first time i get the serial monitor : and i can solved it, when i turn on and turn off again my windown defender domain network and public network and i get the server is connected |
I've faced the same problem. Then I checked using another wifi, the nodemcu v2 was connected to the MQTT broker successfully. Then I had checked the wifi router , here I found that the IP which was assigned to the nodemcu v2 by wifi router, was bound to ARP Binding ( Address Resolution Protocol). I deleted the ARP Binding, and my nodemcu v2 had been started to work perfectly, it was connected to the MQTT broker. |
Hi, very similar issue. I added millis() to loop and then I was getting Attempting MQTT connection...failed, rc=-2 try again in 5 seconds ... the issue disapered after adding of delay(10) after millis() |
I found this video as a problem solver, This may help you. |
Thanks for the useful link! Kind regardsBeat-------- Ursprüngliche Nachricht --------Von: Veera Subrahmanyam Mediboina ***@***.***>Datum: Mo., 21. Juni 2021, 06:51An: knolleary/pubsubclient ***@***.***>Cc: Beat Arnet ***@***.***>, Comment ***@***.***>Betreff: Re: [knolleary/pubsubclient] strange issue Attempting MQTT connection…failed, rc=-2 try again in 5 seconds (#604)
I found this video as a problem solver, This may help you.
All MQTT Errors explained very well and Suggester Different trouble shooting techniques
https://youtu.be/CbodTTk-D18
—You are receiving this because you commented.Reply to this email directly, view it on GitHub, or unsubscribe.
|
i had same problem , i spend two days for "connection…failed, rc=-2 " error . But today i find solution . the error doesnt mean connection error always . i read server ip adres on SD card as char[] and set "client.setServer" as Parameter , but it is wrong , the funcstion request "IPAddress" object , and byte port . when i set values like this my problem solved . IPAddress server(mqttAdres[0],mqttAdres[1],mqttAdres[2],mqttAdres[3]); client.setServer(server, 1883); |
Hey, hopefully this helps someone.
then restart mosquitto service.
Also make sure you test with your WIFI IP as well as the Ethernet connected IP. The mosquitto broker binds to one of them, and I can't figure out how to print that once it's running. |
Winner winner chicken dinner! |
Thanks CarterMoody! (even though I got to the same answer by installing Wireshark, learning Wireshark, watching arduino make a gesture but PC just didn't respond, as though..... as though it wasn't even listening. Hmmmm.)
I used I also messed up my Win 10 Defender firewall rules by having 1883 as Local instead of Remote at the outbound rule. Create that port rule with the 'wizard' and it will set the respective direction for the in and out rules. |
Thanks for the direction. I ended up using this to check if the server name was an IP or an actual address.
|
Hi guys, I started facing this issue two days ago after my first Node-Red & MQTT crashed due to a power issue, I tried to make a fresh setup and this issue started my ESP32 refused to connect, but today I found a way to resolve this, follow the steps and copy commands without the quotes:
Please let me know if anyone finds this useful or encounters any issues while following this process. |
Hi, Guys
I have a very strange issue when add some lines in the void setup then then get this message
Attempting MQTT connection…failed, rc=-2 try again in 5 seconds
int R1 = D0;
int R2 = D1;
int R3 = D2;
int R4 = D3;
int R5 = D4;
int R6 = D5;
int R7 = D6;
pinMode(R1, OUTPUT); // sets the digital pin D0 as output
pinMode(R2, OUTPUT); // sets the digital pin D1 as output
pinMode(R3, OUTPUT); // sets the digital pin D2 as output
pinMode(R4, OUTPUT); // sets the digital pin D3 as output
pinMode(R5, OUTPUT); // sets the digital pin D4 as output
pinMode(R6, OUTPUT); // sets the digital pin D5 as output
pinMode(R7, OUTPUT); // sets the digital pin D6 as output
digitalWrite(R1, HIGH);
digitalWrite(R2, HIGH);
digitalWrite(R3, HIGH);
digitalWrite(R4, HIGH);
digitalWrite(R5 , HIGH);
digitalWrite(R6 , HIGH);
digitalWrite(R7 , HIGH);
then if I delete this line
digitalWrite(R7 , HIGH);
then esp8266 connected to mqtt server
could you please tell me what is the problem?
The text was updated successfully, but these errors were encountered: