I have a esp01 which is normally in deepsleep. When I press a button connected to the RST it will
make connection to a server running on a Raspberry PI3.
This happens within 1.5 seconds.
I measure the connection time by using the millis() command. Sofar so good.
But! I am not able to duplicate this fast setup on a new hardware setup. All the new connections take more than 4 seconds.
I can’t find out why this happens.
I use the same little source. I tried different esp01’s. Even esp12’s take more than 4 seconds to connect.
The fast setup was installed 5 or 6 years ago.
Maybe the libs were different those day’s.
Who can explain what’s going on at my fast setup?
Extra info:
I use fixed IP address.
post the code and details about your boards
did you turn off automatic connection with remembered settings? is SoftAP off? (on new esp it is on)
esp8266 calibrates WiFi at boot sometimes.
Here is my source:
#include <ESP8266WiFi.h> // De WiFi lib.
#define wifi_ssid "Experia"
#define wifi_password "xxxxxxxx"
#define mqtt_server "192.168.2.235" // IP adres van de broker.
unsigned long WiFiCon1Millis, WiFiCon2Millis;
IPAddress ip(192, 168, 2, 161); // Eigen IP van dit device.
IPAddress gateway(192, 168, 2, 254);
IPAddress subnet(255, 255, 255, 0);
WiFiClient espClient;
void setup()
{
Serial.begin(9600);
WiFi_Start(); // Start eerst WiFi.
Serial.println("WiFi Connect Duration " + ( String ) (WiFiCon2Millis - WiFiCon1Millis));
}
void loop()
{
}
void WiFi_Start()
{
WiFiCon1Millis = millis();
Serial.println("\n\nWifi starten.");
WiFi.config(ip, gateway, subnet); // Fixed IP.
WiFi.begin(wifi_ssid, wifi_password); // WiFi verbinding maken.
while (WiFi.status() != WL_CONNECTED)
{
Serial.print("\n + ");
delay(100);
}
Serial.println("\nWifi connected.");
WiFiCon2Millis = millis();
}
Details about boards I don't have. The boards are just normal ESP01's.
Another interesstion thing is that in the check for the connection has succeeded there is a delay(300) for the retry.
This is never reached. The first attempt to connect works straight away because the total time of connection and program running is shorter than this 300mSec.
Problem solved by adding WiFi.persistent(true); in the WiFi connect section.
Thanks to Juraj for this tip!
The first run of the script still shows the long delay but all succeeding runs are ok.
Also after a power disconnect.
Thanks Juraj...
Last question to JuraJ , where did you find the existence of WiFi.persistence ? It is not in the standard documentation about the WiFi lib.
I noticed esp8266 remembered the connection.
https://arduino-esp8266.readthedocs.io/en/latest/esp8266wifi/generic-class.html?highlight=persistent#persistent
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.
