-
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
Can't connect to Broker #203
Comments
What console output do you get from the sketch? Any indication where it is getting to in your code? |
Hi @knolleary, I'm having the exact same issue. I'm using Mosquitto, running inside Docker, and I have tested it using other MQTT clients with success: https://github.com/toke/docker-mosquitto But the client using this library does not connect. Please see the example code bellow. In this example, the code keep printing "Attempting MQTT connection..." indefinitely.
|
@averri sorry to hear that.. perhaps you could also answer the same questions I asked in my previous comment. I cannot help without that information. |
Sorry, see that you did... So is it just the 'attempting' message you get, or do you get the 'failed' message as well? |
Hi @knolleary , I get the 'failed' message. The result code is '-2':
|
Ok, -2 means the network connection couldn't be established - this is before it gets to anything in this library. I assume you get the Have you tried one of the ESP8266 example sketches (such as the http client one) to verify your hardware setup? |
Yes, I have tested, the WiFi is working fine:
The IP 192.168.99.100 is the Docker host IP, where the Mosquitto container is running. I have tested the Mosquitto using mqtt-spy client with success. Are you able to test with Mosquitto running on Docker? |
Where did you run mqtt-spy? Was it on the same machine as was running docker? Have you tried mqtt-spy from another machine on the network? |
Yes, mqtt-spy is running on the same machine as Docker. Tested on a different machine and it works too. Is it possible to enable debugging in the library? |
The |
I have the same issue also. |
Hi Averri, |
Hi, My sketches used to connect to the mqtt server about 2 months ago, however I have a number of boards that just give the above errors, has anyone had any luck with the issues ? Thanks |
Hi, Just tried the above fix but still get: Attempting MQTT connection...failed, rc=-2 try again in 5 seconds Thanks |
I have the same problem any solution plz |
Try This: Use: |
Hi, the following is in my output:
so the first time I do have a -4, all following connection attempts are -2 |
What versions of: I use the latest IDE. |
Same here, latest in Arduino IDE / Sloeber |
Interesting, the only difference i see between us is that i use Arduino Mega with Ethernet. on a different note i have a sonoff working with this: I Hope this Helps. |
Hii, Please find my reconnect loop below. void reconnect() { Immidiate support will be greatful. |
@mitesh6036 please don't add your own question onto someone else's issue. Raise a new issue and someone may be able to help there. |
ohkk.. sorry.. will make a new issue.. |
Just wanted to let you know, the failure is gone. |
Rannandas suggestion helped in my case. I had the same trouble with connection fails to mongoose mqtt broker. |
For ESP8266 the solution of the issue is; |
Same here, I run tasmota on 10 ESP-01 and 3 sonoffs. One ESP-01 and one sonoff cannot connect to mosquitto MQTT. The two devices get " Attempting MQTT connection...failed, rc=-2". Same hardware, same configuration, same network, same sw on the other devices work perfectly. Should I toss the two failing ESPs? |
Are you connecting all the devices at once? Also if ur changing them over quickly, you might have an ARP table issue, it depends how long your server caches MAC addresses. |
Thanks for the suggestion, but I'm not using an analog read I'm using a SoftwareSerial connection to the RFID reader. Furthermore, each time a tag rolls over the reader I need to get its value and due to the speed at which the reader works I don't try to read a tag any faster than one per second. So I recall somewhere there was a warning about the SoftwareSerial code interfering with the TCP of the ESP WiFi code. So I ran the "getTagId" function with no SoftwareSerial use by simply waiting for 30 seconds an the return a constant of a known RFID tag ie "0000000735". But alas I still get the dreaded rc=-2 response. |
Well it certainly helps if you read what others have written! I feel a little foolish... the problem identified above by chenirl is what mine was. I ended up reviewing the source code to the PubSubClient and saw that the connect uses a couple of different set of parameters. Once I declared IPAddress mqtt_server(192, 168, 0, 200); instead of a char* my sketch worked. :) |
The connection to my MQTT broker on a raspberry worked for months... probably after an upgrade it started to fail, but not always... just most of the time. The solution for me was to move to broker from wireless to wired. Now using the wired-ip it works, on the wireless-ip most of time not! |
Exactly what happened to me... |
What does mean -1 in mqttClient.state? I have problem with connection and state rc = - 1... What is this? |
https://github.com/knolleary/pubsubclient/blob/master/src/PubSubClient.h line 48. |
Could you help me? I have problem with connect to my Losant device I have mqttClient.state -1 I don't know how can I repair it... My issue: But closed.. I would like to help with it. :( |
I built a device based on homie on esp8266 which used to connect to mosquitto on raspberry 2 for months without any issues. After some investigation i found out that the rpi3 was connected both, wired and wireless, having two different IP adresses. A nslookup showed this (homer is the name of the rpi3):
After deactivating the Wifi and removing (force recreation) of all DNS entried in my router the problem disappeared. Even the device which was in the Attempt to connect - loop suddenly got a connection.
|
Just for completeness here my solution - my errorcode was rc=-1 (tried to connect via tasmota esp8226 firmware). Reason: I used a too long username/password in my mosquitto server. |
Thanks, This solution fixed my reboot issue. basically eliminating the PROGMEM. |
Use: i also tried all hack but now able to get communication with broker on cloud with above suggestion on this form. Thank you so much all. |
This worked perfectly! |
I had the same error. In my case the broker was rabbitmq and rabbitmq does not allow connection with guest user. You might wanna try providing user credentials. |
The solution to this problem is to enable authentication on the mosquitto broker and use user name and password on the client connect call. |
Just updated a device that's been running for years and ran into this same issue :( I'm running rabbitmq with authentication enabled and here's a snippet of the server-side output:
I get similar message every time it attempts to reconnect. |
What I found to be a problem is , if you leave the connection idle for more than a sec, it gets closed with socket errors, In the original example published for this library, if you remove the continuous message publish in the main loop, you can replicate the same error. |
I never get a connection. It fails to even make the connection successfully. All I did was update the board definitions in the IDE. Flashed and it failed so then I updated this lib..flashed again and failure. Failure all around now :) |
Are you using any sort of MDNS discovery or similar before attempting the MQTT broker connection ?For me this was also an issue, ESP8266 MDNS library seems to do something to the Wifi stack after running a mdns query. It would actually not even appear on the router's device list although connection status on wifi library would still return 3. The solution for me was to save the IP and port after discovery to eeprom and then do a restart and attempt connection with mqtt broker. |
I don't think that's the case or a I wouldn't be seeing the attempts on the rabbitmq server to authenticate. I have an IP etc and it is attempting to connect.. |
Seems to be a new issue , are you using authentication? I was using
Mosquitto broker on the raspberry pi. May be whatever I faced is typical to
Mosquitto.
…On Mon, Jun 1, 2020 at 12:11 PM Travis Glenn Hansen < ***@***.***> wrote:
I don't think that's the case or a I wouldn't be seeing the attempts on
the rabbitmq server to authenticate. I have an IP etc and it is attempting
to connect..
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#203 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ACL7KNJXVC5AA6ZSU5W4RS3RUNERZANCNFSM4CQNJPTQ>
.
|
I’ve been using authentication with rabbitmq on the device for years. |
Hi everyone. I'm using a Raspberry Pi running Mosquitto over websockets on port 9001 with username and password. The username and password are less than 10 characters I don't know why I'm getting error -1 in the client state. However, I can connect to the server with a JavaScript client with the same data. This is my code: #include <WiFi.h> const char* ssid = "my_ssid"; WiFiClient espClient; void setup() { void setup_wifi() { WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { Serial.println(""); void callback(char* topic, byte* payload, unsigned int length) { void reconnect() { void loop() { The output is: Attempting MQTT connection...failed, rc=-1 try again in 5 seconds. |
I don't see any websocket implementation in your sketch. And AFAIK this is not supported out of the box by Pubsubclient. Try the regular MQTT connection (1883) if your broker supports this. |
This issue is 4 years old and too generic to be worth keeping open. Lots of people have issues connecting and every single one is a different underlying reason. |
[ tested and workinf for my case ] check if your case it help ping function
in reconnec logic of mqtt do this
let know if it work in your case also, pub sub lib, generic async mqtt lib has same underlying issue , that breakage of internet from ISP causes continuous disconnection status, keep ing pending reconnect state, but in this patch try if working in your case |
Hi, i cant connect to broker on my raspberry.
Broker: Mosquitto 1.4.10
on serial i m getting rc=-2 acording to documentation it is network connection failed.
On mosquitto log i m getting
New connection from 192.168.1.111 on port 1883
for the first few minutes and then these errors occur:
As you can see networking seems fine and there is some other issue with communication between arduino and rpi.
Remote client on my laptop connects to the broker without any problems.
Hardware i m using is: arduino nano with ethernet shield (the one with the sd card slot)
my sketch:
basicly copied example with delay between connections rised to 20s:
if u need more information i will be happy to share
The text was updated successfully, but these errors were encountered: