h4nc
August 18, 2019, 11:07am
41
I’ll give that another try. I did not watch it on the serial monitor the last times, because I tried another power supply (not my laptop).
h4nc
August 18, 2019, 11:28am
42
Now back again on wifi manager (because made no difference) and and still on the newest version.
This is the output after connection is lost due to a router restart:
MQTT connection...
[E][WiFiClient.cpp:365] write(): fail on fd 57, errno: 113, "Software caused connection abort"
failure_number
1
failed, rc=
-4
try again in 5s
MQTT connection...
looks like it is stuck again after that first try, because even after minutes it doesn’t go to the second try.
I remember that I had a similiar issue with the ESP8266 when I did not use spiffs. But in this case it did not save the wifi settings.
Little differnt here because the restart of the ESP32 makes it work again, so the wifi settings are there.
Seems that the wifi state returned by the wifi library doesn’t correspond to the real state:
opened 10:16PM - 20 Sep 18 UTC
closed 12:52AM - 15 Aug 19 UTC
Status: Stale
**Hardware:**
Board: Adafruit HUZZAH32
Core Installation/update date: IDF & Ar… duino up to date
IDE name: PlatformIO
Flash Frequency: 40Mhz
Upload Speed: 115200
**Description**
I have an application that uses 2 FreeRTOS tasks. One of these tasks will eventually act as a server that clients connect to.
I attempted to implement auto reconnect to WiFi. To test this I uploaded my code, ensured the ESP32 connected to WiFi, unplugged my router from the wall, waited a few minutes, and plugged it back in.
It appears that while my router is disconnected the return value from WiFi.status() was WL_CONNECTED (3) which indicated the ESP32 thinks it's still connected to WiFi. I have waited for as long as 10 minutes and the WiFi status did not update.
I know my WiFi didn't work because all of my other devices couldn't connect.
### Sketch:
```cpp
#include <Arduino.h>
#include <WiFi.h>
#define SSID "**********"
#define PASSWORD "**********"
TaskHandle_t otherTask;
TaskHandle_t wifiTask;
unsigned long int tempTime = 0;
void otherThread(void*ptr)
{
while(1)
{
//do something else here
delay(100);
}
vTaskDelete( NULL );
}
void wifiThread(void *ptr)
{
WiFi.begin(SSID, PASSWORD);
Serial.print("WiFi status: "); Serial.println(WiFi.status());
while (WiFi.status() != WL_CONNECTED)
{
delay(300);
Serial.println("Connecting to WiFi....");
}
Serial.print("IP: ");Serial.println(WiFi.localIP());
while(1)
{
if((WiFi.status() != WL_CONNECTED))
{
Serial.println("WiFi Disconnected");
WiFi.disconnect();
delay(100);
WiFi.begin(SSID,PASSWORD);
while(WiFi.status() != WL_CONNECTED)
{
delay(300);
Serial.println("Attempting to reconnect to WiFi");
}
}
else
{
unsigned long int currentTime = millis();
if((currentTime - tempTime) > 700) //non blocking print every 700ms
{
Serial.print("WiFi status: "); Serial.println(WiFi.status());
tempTime = currentTime;
}
}
}
vTaskDelete( NULL );
}
void setup()
{
Serial.begin(115200);
xTaskCreatePinnedToCore(
otherThread,
"otherThread",
20000,
NULL,
3,
&otherTask,
0);
xTaskCreatePinnedToCore(
wifiThread,
"wifiThread",
25000,
NULL,
3,
&wifiTask,
1);
}
void loop()
{
}
```
It returns connected but we are not .
If you wait at least 5 minutes after this
The board should reset itself, could you try?
One test also that can be done is to attribute a fix IP adress to your ESP32 and see if you get the same behaviour.
h4nc
August 18, 2019, 3:47pm
44
I noticed something new. After the last wifi router restart it seems like the esp32 went online for some seconds just to go offline again. No ping.
After that I waited for more than 5 minutes and the board did not reset.
So
no things going on in the serial monitor-
no reconnecting to the broker (I watch it with MQTT Explorer)
no omg wifi manger
Nothing.
I have another router. I build a second wifi network to try if it’s something in my network. I will also try the fixed IP.
h4nc
August 18, 2019, 4:15pm
45
Quick update:
I opened another network and connected to this one. I turned off WiFi on that router and turned it on again.
This time I got some messages about WiFi connection loss (did see this the first time). And after turning WIFI on again the esp32 went online immediately.
Any suggestions why it works with on WiFi and not with the other one.
I don’t have any other issues with that first network.
However 5Ghz was deactivated on the new router.
I’m out of time for today and will test again tomorrow. Any suggestions appreciated.
I think we need to details both router model/configuration and enrich the issue below:
opened 10:16PM - 20 Sep 18 UTC
closed 12:52AM - 15 Aug 19 UTC
Status: Stale
**Hardware:**
Board: Adafruit HUZZAH32
Core Installation/update date: IDF & Ar… duino up to date
IDE name: PlatformIO
Flash Frequency: 40Mhz
Upload Speed: 115200
**Description**
I have an application that uses 2 FreeRTOS tasks. One of these tasks will eventually act as a server that clients connect to.
I attempted to implement auto reconnect to WiFi. To test this I uploaded my code, ensured the ESP32 connected to WiFi, unplugged my router from the wall, waited a few minutes, and plugged it back in.
It appears that while my router is disconnected the return value from WiFi.status() was WL_CONNECTED (3) which indicated the ESP32 thinks it's still connected to WiFi. I have waited for as long as 10 minutes and the WiFi status did not update.
I know my WiFi didn't work because all of my other devices couldn't connect.
### Sketch:
```cpp
#include <Arduino.h>
#include <WiFi.h>
#define SSID "**********"
#define PASSWORD "**********"
TaskHandle_t otherTask;
TaskHandle_t wifiTask;
unsigned long int tempTime = 0;
void otherThread(void*ptr)
{
while(1)
{
//do something else here
delay(100);
}
vTaskDelete( NULL );
}
void wifiThread(void *ptr)
{
WiFi.begin(SSID, PASSWORD);
Serial.print("WiFi status: "); Serial.println(WiFi.status());
while (WiFi.status() != WL_CONNECTED)
{
delay(300);
Serial.println("Connecting to WiFi....");
}
Serial.print("IP: ");Serial.println(WiFi.localIP());
while(1)
{
if((WiFi.status() != WL_CONNECTED))
{
Serial.println("WiFi Disconnected");
WiFi.disconnect();
delay(100);
WiFi.begin(SSID,PASSWORD);
while(WiFi.status() != WL_CONNECTED)
{
delay(300);
Serial.println("Attempting to reconnect to WiFi");
}
}
else
{
unsigned long int currentTime = millis();
if((currentTime - tempTime) > 700) //non blocking print every 700ms
{
Serial.print("WiFi status: "); Serial.println(WiFi.status());
tempTime = currentTime;
}
}
}
vTaskDelete( NULL );
}
void setup()
{
Serial.begin(115200);
xTaskCreatePinnedToCore(
otherThread,
"otherThread",
20000,
NULL,
3,
&otherTask,
0);
xTaskCreatePinnedToCore(
wifiThread,
"wifiThread",
25000,
NULL,
3,
&wifiTask,
1);
}
void loop()
{
}
```
As it is on wifi basement we should try first to solve it at this level.
h4nc
August 18, 2019, 8:10pm
47
It‘s a Apple Timecapsule. Like most of the times with Apple not much to configure. And as I said no issues with other devices.
I have 2 additional Apple Express which extend the network.
What specific configuration details should I look up?
Will try the fixed IP soon.
Currently I have the esp32 on the new network to see if it stays online.
h4nc
August 19, 2019, 6:02am
48
Ok, so the ESP32 is able to stay online on that second new network.
However there are still some interrupts detected by home assistant. Is this normal?
LWT value:
h4nc
August 19, 2019, 11:28am
49
Wasn’t able to set up a fixed IP. Seem like I would have to turn off DHCP on my router (but this would opnen up other issues, with other devices).
See the first line here:
// these values are only used if no dhcp configuration is available
const byte ip[] = { 192, 168, 0, 70 }; //ip adress
const byte gateway[] = { 192, 168, 0, 1 }; //ip adress, if first value is different from 0 advanced config network will be used and you should fill gateway & dns
const byte Dns[] = { 8, 8, 8, 8 }; //ip adress, if first value is different from 0 advanced config network will be used and you should fill gateway & dns
const byte subnet[] = { 255, 255, 255, 0 }; //ip adress
Normal I would not say that, but it is equivalent to what I got in my side. I think it is acceptable.
Is the esp32 far from your router?
You don’t have the possibility at router level to attribute a static IP corresponding to the MAC adress ?
On my router it is possible without any change on user_config.h for info.
h4nc
August 19, 2019, 8:01pm
52
Not very far but some walls between. The thing is that was just a test wifi network and yes I get the same behaviour like you. So it is able to reconnect with that network. But as it is only a test network I won’t keep that one.
This tells us the esp32 is flashed correctly and it is not defective.
I still think it’s some software issue on the esp32, because as I said no other devices have issues (and other esp’s work fine, tasmota devices).
ah you mean a dhcp address reservation, right? Yes, I had that from the beginning. I was once told that a dhcp address reservation is not a real static IP, which is why I missunderstood you.
Unfortunately no change with a fixed IP (address reservation).
When you are saying other software works fine. Are they on an esp32 also ?
h4nc
August 20, 2019, 6:09am
54
No, I mean all other wifi devices in my network work fine. But I don’t think any of them are ESP32. Mostly ESP8266 devices.
In this case could you give me the exact model of your router (if there is more to say) and I will reopen the issue on the esp32 arduino env.
h4nc
August 21, 2019, 8:22pm
56
It’s an Apple Timecapsule 5.gen A1470. Firmware 7.9.1 (so current version)
Thanks!
The new version v0.9.2 is now online on two of my ESP32 since one month, here is the outdoor temperature graph from a mi flora:
h4nc
September 11, 2019, 6:12am
58
So as we discussed before it must be something in my network.
Currently I don’t have the ESP32 in my network. But as it is still 0.92 I don’t think more tests will help, as I already tested this version some weeks ago.
Yep, I have added your config to the issue in github of arduino esp32:
opened 10:16PM - 20 Sep 18 UTC
closed 12:52AM - 15 Aug 19 UTC
Status: Stale
**Hardware:**
Board: Adafruit HUZZAH32
Core Installation/update date: IDF & Ar… duino up to date
IDE name: PlatformIO
Flash Frequency: 40Mhz
Upload Speed: 115200
**Description**
I have an application that uses 2 FreeRTOS tasks. One of these tasks will eventually act as a server that clients connect to.
I attempted to implement auto reconnect to WiFi. To test this I uploaded my code, ensured the ESP32 connected to WiFi, unplugged my router from the wall, waited a few minutes, and plugged it back in.
It appears that while my router is disconnected the return value from WiFi.status() was WL_CONNECTED (3) which indicated the ESP32 thinks it's still connected to WiFi. I have waited for as long as 10 minutes and the WiFi status did not update.
I know my WiFi didn't work because all of my other devices couldn't connect.
### Sketch:
```cpp
#include <Arduino.h>
#include <WiFi.h>
#define SSID "**********"
#define PASSWORD "**********"
TaskHandle_t otherTask;
TaskHandle_t wifiTask;
unsigned long int tempTime = 0;
void otherThread(void*ptr)
{
while(1)
{
//do something else here
delay(100);
}
vTaskDelete( NULL );
}
void wifiThread(void *ptr)
{
WiFi.begin(SSID, PASSWORD);
Serial.print("WiFi status: "); Serial.println(WiFi.status());
while (WiFi.status() != WL_CONNECTED)
{
delay(300);
Serial.println("Connecting to WiFi....");
}
Serial.print("IP: ");Serial.println(WiFi.localIP());
while(1)
{
if((WiFi.status() != WL_CONNECTED))
{
Serial.println("WiFi Disconnected");
WiFi.disconnect();
delay(100);
WiFi.begin(SSID,PASSWORD);
while(WiFi.status() != WL_CONNECTED)
{
delay(300);
Serial.println("Attempting to reconnect to WiFi");
}
}
else
{
unsigned long int currentTime = millis();
if((currentTime - tempTime) > 700) //non blocking print every 700ms
{
Serial.print("WiFi status: "); Serial.println(WiFi.status());
tempTime = currentTime;
}
}
}
vTaskDelete( NULL );
}
void setup()
{
Serial.begin(115200);
xTaskCreatePinnedToCore(
otherThread,
"otherThread",
20000,
NULL,
3,
&otherTask,
0);
xTaskCreatePinnedToCore(
wifiThread,
"wifiThread",
25000,
NULL,
3,
&wifiTask,
1);
}
void loop()
{
}
```
But this doesn’t seem to draw the crowds.
1 Like
h4nc
October 3, 2019, 3:09pm
60
Just here to add that I changed my network to Unifi. So no Apple Routers and Access Points in my house any more.
So from my side we will probably never find out what was the issue here, because I won’t set it up as router again (was time consuming to change it).
Now it seems like the OMG devices work fine with Unifi. I didn’t reflash the OMG.