platformio / platform-espressif8266

Espressif 8266: development platform for PlatformIO
https://registry.platformio.org/platforms/platformio/espressif8266
Apache License 2.0
323 stars 219 forks source link

wifi issues with version 2.3.2 #194

Open powergt opened 4 years ago

powergt commented 4 years ago

with version 2.3.2 I encountered problems on wifi: in the main loop it is necessary to insert a delay line of at least 6-7ms otherwise the wifi will not connect or if it connects it will disconnect continuously. with version 2.3.1 this does not happen detail: platformio Home 3.0.1·Core 4.1.0

platformio.ini [env:d1] platform = espressif8266 board = d1_mini framework = arduino monitor_port = COM3 monitor_speed = 115200 upload_speed = 921600 upload_port = COM3

relevant parts of sketch:

include

include

enum Status_enum {IDLE,WIFI_PREPARE,WIFI_CONNECTION,MQTT_CONNECTION}; Status_enum status; unsigned long time;

void setup() { Serial.begin(115200); delay(1000); }

void loop() { delay(10); <--without this wifi don't work correctly Network_update(); //..other code... yield(); }

void Network_update(){ if (status!=IDLE || WiFi.status()!=WL_CONNECTED) { connectToWiFi(); } }

void connectToWiFi() { static int retry; if (status==IDLE) {WiFi.disconnect();status=WIFI_PREPARE;time=millis();} else if (status==WIFI_PREPARE && millis()-time>200) { WiFi.mode(WIFI_STA); WiFi.setSleepMode(WIFI_NONE_SLEEP); //evita lo sleep del wifi che con alcuni AP fa disconnettere WiFi.begin(ssid, pass); Serial_printf(PSTR("connessione al wifi: %s"),ssid); status=WIFI_CONNECTION; time=millis(); } else if (status==WIFI_CONNECTION && millis()-time>1000) { status=IDLE; } else { retry++; if (retry>60) {retry=0;status=IDLE;Serial.printf("WiFi.status:%d\r\n",WiFi.status());} Serial.print("."); time=millis(); } } }

valeros commented 4 years ago

Hi @powergt ! Sorry for the late reply, could you please retest your project with the upstream version of the platform:

[env:d1]
platform = https://github.com/platformio/platform-espressif8266.git
board = d1_mini
framework = arduino
monitor_port = COM3
monitor_speed = 115200
upload_speed = 921600
upload_port = COM3