i have a Wemos D1 mini with ESP8266 on it and can connect to my wifi with the following code:
#include <ESP8266WiFi.h>
#include <NTPClient.h>
#include <WiFiUdp.h>
#include <string>
WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP, "pool.ntp.org");
const char* SSID = "MYSSID";
const char* PSK = "MYPSK";
WiFiClientSecure espClient; /* Secure client connection class, as opposed to WiFiClient */
PublicKey key(pubkey);
void setup_wifi() {
WiFi.mode(WIFI_STA);
WiFi.begin(SSID, PSK);
Serial.println("Try to connect to wifi ");
while (WiFi.status() != WL_CONNECTED) {
delay(100);
}
Serial.println(WiFi.localIP());
espClient.setX509Time(timeClient.getEpochTime());
Serial.write(timeClient.getEpochTime());
}
void setup() {
// Serial Monitor
Serial.begin(115200);
// STATUS LED
pinMode(LED_BUILTIN, OUTPUT); // Initialize the LED_BUILTIN pin as an output
// WIFI
setup_wifi();
}
void loop()
{
}
So far, everything is fine, it connects as expected and it. But when i turn off the power supply of the ESP and restart it a few hours (or a day) later then the only solution to get an wifi connection again is to go to my routers settings and change the wifi channel from 11 to 10 or something else below 11. After that channel change the ESP is properly connecting to wifi again. Without changing the wifi channel, there will no wifi connection be established.
It's not a known problem as far as I know. I have experienced one router (not my home router) which refused to allow a wemos to connect even one time.
Have you tried other code with this wemos and router? Do you think the problem is unique to this code or could it be a problem with your router or wemos?
thanks for your reply.
Do you have an other code for me to test? That's the only code i have tested so far.
I exchanged the Wemos right now with another one, but that's no solution.
Another strange behavior is, that when i turn on Debug for Wifi i can see, that Wifi is connected, but return code is still (6) from Wifi.status(). Therefore the while loop will still be executed .... i don't get it...
connected with <MY_SSID>, channel 11
dhcp client start...
wifi evt: 0
6
Mode: STA
PHY mode: N
Channel: 11
AP id: 0
Status: 1
Auto connect: 1
SSID (6): <MY_SSID>
Passphrase (20): <MY_PSK>
BSSID set: 0
wifi.status(): 6
Hi, I have the same problem. I need to change ch in my router (asus AX58U) to get my Wemos D1 mini v4.0.0 reconnect after reboot or reflash. Did you find a cure?
I probably have a similar issue. The D1 mini only connects after I change the 2.4GHz channels. Then it is able to connect if I reset it within a short time.
But if I try to connect again in an hours time, it needs a channel change again from the router. Very strange. Am using the same WiFiClient library and a Virgin Media HUB 6 modem/router.
The only change I've made to the board is to solder header pins facing upwards on the antenna side of the board where the 8266 is also housed. The chip and antenna are sort of jailed within those headers; unlikely that's causing it, I also thought my soldering might have killed something!
Update: If I assign it a static IP address, the problem goes away. It immediately gets onto the WiFi now. Wondering if this is related to how different routers implement DHCP and how long IPv4 addresses are reserved, leased or cached