Description
Hi there,
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.setSleepMode(WIFI_NONE_SLEEP);
WiFi.mode(WIFI_STA);
WiFi.disconnect();
WiFi.begin(SSID, PSK);
Serial.println("Try to connect to wifi ");
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
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 i also set the "not go to sleep" command for wifi.
The problem is, that wifi connects only when i restart my wifi in router. If i don't restart it, then sometimes the wifi will connect properly, but only for a few times. Then the wifi connecting will get stuck with the following wifi debug message:
connected with <MY_SSID>, channel 11
dhcp client start...
wifi evt: 0
pm open,type:0 0
So it seems to be connected, but there is no ip address allocated and the wifi status never reaches the WL_CONNECTED state.
The connection got stuck at pm open,type:0 0
I thought this is a problem with 5GHz wifi, so i turned it off in my router, which is now only set up to 2,4 GHz.
And i also changed the wifi channel selection from below channel 11 in my router settings.
I am very looking forward for any hints.
Thanks in advance!