Connection issue ESP32, device disconnects immediately after connecting

I am using an ESP32 board and have followed the tutorial to get it connected to wifi. I am also using Bluetooth to supply the WiFi credentials and verify the device on losant for authorization and then supply the access keys back to the board for connection to losant.

All this works great, WiFI connects but the problem is the device connects to Losant only briefly and gets disconnected almost immediately which results in the device being stuck in the connection wait loop.

I have tried various different posts and answers on this forum but not able to figure out the issue.

I am using the latest losant mqtt module for arduino.

Screenshot 2020-08-26 at 1.11.42 PM


This seems like it could be something on the device side of things. Are there any device logs you can share?

Device just logs Connecting to Losant… and then just …

I maybe doing something wrong but sometimes it does seem to work but then the device again disconnects. Attaching screenshot from the code that i have currently.


You mentioned you were following a tutorial, could you provide a link to the tutorial you’re referring to?

Overall, we’ve improved the ESP32 example, you may find the latest code here:

Would you be able to give that a try and see if you get the same results?

@anaptfox I am actually following that tutorial. The problem is when i run the esp32.ino sketch without modifying anything with just my device id and keys hardcoded. Everything seems to work as expected.

But in my use case, i am authenticating through ble and transferring the keys, deviceId over ble to the device and making an attempt to connect to losant.

I moved to platformio and i have got a log that seems to be originating from the underneath ssl client, not sure what is causing the issue here.


I was able to reproduce what you’re seeing.

However, it seems to be an issue with an underlying library that the Losant MQTT Arduino uses:

I’m going to add some details to that issue for the library developer to see if we can get this resolved.

However, as a path forward, for recent development using the ESP32, we recommend using the ESP-idf.

You may find instructions on getting your environment set up here:

Also, to help, we are working on a new guide for connecting the ESP32 to Losant using the ESP-idf to provide a solid example. We’ll follow up on this post when that is complete.

Thanks @anaptfox for looking into it.

What is strange is that sometimes it does work as expected and connects perfectly without being disconnected but then that is 1 out of 3 tries. Not sure what is the core issue, i will keep looking into it to see if there is a memory or heap availability issue on it.

I will also check out the IDF environment. Thanks

Hi @anaptfox - any chance this could be impacting the ESP8266 platform? I am experiencing the disconnect after adding some more data to my report section.

Actually, I have figured out what is causing my issue. It seems that any more than nine items cannot be reported at one time. My workaround was to create a unique report function for each group of data and send the reports individually.