mqtt.connect() fails to connect returns -1

Moderators: adafruit_support_bill, adafruit

Forum rules
If you're posting code, please make sure your code does not include your Adafruit IO Active Key or WiFi network credentials.
User avatar
jimk123
 
Posts: 708
Joined: Sun Dec 26, 2010 7:04 pm

mqtt.connect() fails to connect returns -1

Post by jimk123 »

I have been using adafruit dataio for several years and have about a dozen adafruit esp32 boards deployed in remote locations and working great. About a year ago I wrote a new sketch using adafruit data io on my win10b machine and it worked fine. Not sure if this is related but a month or so ago I bought a Adafruit QT Py ESP32-S2 an had to upgrade the ESP32 board manager. Then I was adding a new feature to my mqtt sketch on the win10b machine the other day and it will no longer connect. I stripped out all the other code except for a basic connect and publish. It compiles and runs ok on my win10a PC but fails to connect on the win10b machine, it is failing on the mqtt.connect line in the code, I turned on debug in the Adafruit_MQTT.h file and this is the output on the failing machine in the serial window (see attached file)

win10a
arduino ide 1.8.5
C:\Users\Jim\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.4
adafruit io arduino 4.0.2
datafrut mqtt 1.0.3

win10b
arduino ide 1.8.10
C:\Users\JimKruk\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.2
adafruit io arduino 4.0.2
datafrut mqtt 1.0.3

I have been troubleshooting this for days and cannot think of why it no longer works on the win10b machine, other that the upgrade to the boards manager a few weeks ago but not sure how to further trouble shoot this ? I am really reluctant to start uninstalling code for fear of breaking other things on this machine.
Thanks
serial output.txt
(869 Bytes) Downloaded 29 times

Code: Select all

 [attachment=0]mqtt.txt[/attachment]
Attachments
mqtt.txt
(5.39 KiB) Downloaded 12 times

User avatar
jimk123
 
Posts: 708
Joined: Sun Dec 26, 2010 7:04 pm

Re: mqtt.connect() fails to connect returns -1

Post by jimk123 »

btw I noticed in the serial output:
Connecting to Adafruit IO... (my code)
Connecting to: io.adafruit.com (debug trace)
Connect result: 0 (debug trace)
mqtt.connect failed with return code: -1 (my code)
Connection failed (my code)
MQTT disconnect packet: (debug trace)
[0xE0], [0x00],
Connection failed! (debug trace)
Unable to send disconnect packet (debug trace)

User avatar
jwcooper
 
Posts: 1004
Joined: Tue May 01, 2012 9:08 pm

Re: mqtt.connect() fails to connect returns -1

Post by jwcooper »

Can you try with one of our examples? Plug your info in, and see if you can get past the connect phase.

That will help isolate if it's related to your account, or your code.

https://github.com/adafruit/Adafruit_IO ... 00_publish

User avatar
jimk123
 
Posts: 708
Joined: Sun Dec 26, 2010 7:04 pm

Re: mqtt.connect() fails to connect returns -1

Post by jimk123 »

I ran that code 'as is' it in the serial window it just loops:
Connecting to Adafruit IO.........................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................

but a couple q.
don't I need to include the libraries #include "Adafruit_MQTT.h" #include "Adafruit_MQTT_Client.h" and connnect to wifi, etc ?
Just trying understand how that code will how get out to the internet and even knows what commands like io.connect(); mean without any libraries, is it built in the the eps32 core ? thanks

User avatar
jimk123
 
Posts: 708
Joined: Sun Dec 26, 2010 7:04 pm

Re: mqtt.connect() fails to connect returns -1

Post by jimk123 »

i had some more time after work to review the code example provided and saw in the config.h you need to specify a SSID and password. I am using this on a adafruit esp32 feather. I compiled it on the win10b machine and saw this in the output window ( i changed the serial.print to add 'win10b' so I knew which machine it is running on.

win10b Connecting to Adafruit IO......Connecting to: io.adafruit.com
Connect result: 0
................................................................................................

looks like the same issue I had with my code, it fails to connect to adafruit IO.

then i moved the code to my win10a machine, compiled it and it runs ok and my other mqtt code works on win10a also,
Connecting to Adafruit IO..
Adafruit IO connected.
sending -> 0
sending -> 1
sending -> 2

as I mentioned earlier the adafruit libraries are the same between my two laptops
adafruit io arduino 4.0.2
adatafrut mqtt 1.0.3

one difference is the EPS32 library is Arduino15\packages\esp32\hardware\esp32\2.0.2 on the win10b machine (where it fails) and 1.04 on the win10a machine where the code works. I feel like this all started when I tried to ugrade my ESP32 install to use a new adafruit QT PY ESP32 board a few weeks ago. I am really hesitant uninstall and reinstall 1.0.4 on the win10b machine, knowing it will break my newer adafruit boards, still hoping you can see something in the error codes from the first output:

Connecting to Adafruit IO...
Connecting to: io.adafruit.com
Connect result: 0
mqtt.connect failed with return code: -1
Connection failed
MQTT disconnect packet:
[0xE0], [0x00],
Connection failed!
Unable to send disconnect packet

Would a fiddler http trace provide any clues ? It has been a long time since i used that tracing tool but it may reveal something in the http traffic that is different between the two laptops, or if you use a similar http trace tool let me know.
thanks

User avatar
jimk123
 
Posts: 708
Joined: Sun Dec 26, 2010 7:04 pm

Re: mqtt.connect() fails to connect returns -1

Post by jimk123 »

as another test I compiled it, ran it on the win10a machine (that has the older version of esp32) where it works, then unplugged it, plugged it into the win10b machine and it connects fine, so it feels like something in the compiled code ? thanks

User avatar
brubell
Learn User Page
 
Posts: 2017
Joined: Fri Jul 17, 2015 10:33 pm

Re: mqtt.connect() fails to connect returns -1

Post by brubell »

Hi Jimk123,
an had to upgrade the ESP32 board manager
Could you check the version of the ESP32 board support package you're using with Arduino IDE?

I'll try to replicate it on my end.

User avatar
jimk123
 
Posts: 708
Joined: Sun Dec 26, 2010 7:04 pm

Re: mqtt.connect() fails to connect returns -1

Post by jimk123 »

not sure if this is what you wanted to see: ?

C:\Users\Jim\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.2
thanks

User avatar
Franklin97355
 
Posts: 23940
Joined: Mon Apr 21, 2008 2:33 pm

Re: mqtt.connect() fails to connect returns -1

Post by Franklin97355 »

You can go into board manager and install a previous version to see if it is the upgrade. I know I would be curious.

User avatar
jimk123
 
Posts: 708
Joined: Sun Dec 26, 2010 7:04 pm

Re: mqtt.connect() fails to connect returns -1

Post by jimk123 »

Hi Franklin
I know it is growing to a long post but I have two win pc’s, one at esp32 1.0.4, the other that I recently upgraded to esp32 2.0.2, same Adafruit Io v 4.0.2 and that’s when my code stop working. Would prefer not to uninstall, reinstall esp32 to the older ver on the failing machine until the folks at Adafruit can confirm, thanks

User avatar
Franklin97355
 
Posts: 23940
Joined: Mon Apr 21, 2008 2:33 pm

Re: mqtt.connect() fails to connect returns -1

Post by Franklin97355 »

OK, I have a HUZZAH32 Feather running on Arduino 1.8.9 with Adafruit MQTT 2.4.2 and Adafruit IO 4.2.0 with ESP 2.0.3 and ran the adafruitio_secure_esp32 example with a connect. Can you try that?

User avatar
jimk123
 
Posts: 708
Joined: Sun Dec 26, 2010 7:04 pm

Re: mqtt.connect() fails to connect returns -1

Post by jimk123 »

Hi Franklin
Thanks for the suggestions, I will try upgrading the esp32 board mgr to 2.0.3. Back when I upgraded 2.0.2 was the latest stable prod release. I see your mqtt version is much newer, if the esp32 upgrade does not help I may try upgrading the mqtt library.

Further up in this post was a comment by jwcooper with a link to a sample connection test program Adafruit recommended. I would be curious if that runs on your setup ?

Thanks

User avatar
jimk123
 
Posts: 708
Joined: Sun Dec 26, 2010 7:04 pm

Re: mqtt.connect() fails to connect returns -1

Post by jimk123 »

here are the results after upgrading the esp32 board, it still loops trying to get a connection. As i posted earlier if I take that code on my win10a pc using an older version of the esp32 board it compiles and runs ok.

on 5/26/22 on the win10b machine I upgraded esp32 under tools, boards, board mgr to 2.0.3

and verified in file explorer that path - C:\Users\Jim\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.3

in the ide using board type 'adafruit esp32 feather'

code: // Adafruit IO Publish Example provided by jwcooper in an earlier post here

compiled and uploaded,
on the serial console I see: ( I added the 'win10b' line to be sure this was on my win10b pc)

win10b Connecting to Adafruit IO.....Connecting to: io.adafruit.com
Connect result: 0 (not sure where this line comes from, library ?)
.................................................................................................................

I think it is just looping in this code

// wait for a connection
while(io.status() < AIO_CONNECTED) {
Serial.print(".");
delay(500);
}

User avatar
Franklin97355
 
Posts: 23940
Joined: Mon Apr 21, 2008 2:33 pm

Re: mqtt.connect() fails to connect returns -1

Post by Franklin97355 »

Try including:

Code: Select all

// wait for a connection
while(io.status() < AIO_CONNECTED) {
Serial.println(io.status());
delay(10000);
}
and see what you get.

User avatar
jimk123
 
Posts: 708
Joined: Sun Dec 26, 2010 7:04 pm

Re: mqtt.connect() fails to connect returns -1

Post by jimk123 »

thanks for the reply and tip, here are the results using the sample code adafruit tech support suggested earlier in this thread.

.........win10b Connecting to Adafruit IO
0
0
0
0
0
0
Connecting to: io.adafruit.com
Connect result: 0
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2

Locked
Forum rules
If you're posting code, please make sure your code does not include your Adafruit IO Active Key or WiFi network credentials.

Return to “Internet of Things: Adafruit IO and Wippersnapper”