Problem connecting ESP8266 to Wifi; library-problem?

I am a huge fan of PlatformIO but I recently am strugling with a Wifi-connection-problem which does not occur when I use the Arduino IDE (with the EXACT same code)…

I used PlatformIO a lot but had some problems with Atom-updates so installed all of it new.
Revisiting some old code I got into a problem with my ESP-modules not connecting to my Wifi after updating the firmware.

When I write a super-simple program (just to connect to my Wifi) and burn it on my ESP with the Arduino-IDE it connects in 0,5 seconds… when I use the EXACT same program in PlatformIO (copy-paste) it does not connect (only sometimes after a hardware reset -which, when it is builtin, in combination with OTA could be a problem-).

All my platformio modules and boards are up to date (IDE 1.4.0)… is this SDK related? (maybe my arduino IDE 1.6.9 uses an older version?)

It looks like my arduino IDE uses an older version of ESP8266wifi (dated januari 2016) versus newer projects in platformio use a version from may 2016. I tried deleting .pioenvs it generates the new ESP8266wifi from may 2016.

Does anyone recognise this problem? (or better: solved it?)

THNX

Hi @RobbbdeVries! Could you please provide your sketch here?

Here is the BasicOTA I use:

#include <ESP8266WiFi.h>
#include <ESP8266mDNS.h>
#include <WiFiUdp.h>
#include <ArduinoOTA.h>

const char* ssid = "..........";
const char* password = "..........";
const int ledPin = 13;

void setupOTA() {
    // Port defaults to 8266
    // ArduinoOTA.setPort(8266);

    // Hostname defaults to esp8266-[ChipID]
    // ArduinoOTA.setHostname("myesp8266");

    // No authentication by default
    // ArduinoOTA.setPassword((const char *)"123");

    ArduinoOTA.onStart([]() {
      Serial.println("Start");
    });
    ArduinoOTA.onEnd([]() {
      Serial.println("\nEnd");
    });
    ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
      Serial.printf("Progress: %u%%\r", (progress / (total / 100)));
    });
    ArduinoOTA.onError([](ota_error_t error) {
      Serial.printf("Error[%u]: ", error);
      if (error == OTA_AUTH_ERROR) Serial.println("Auth Failed");
      else if (error == OTA_BEGIN_ERROR) Serial.println("Begin Failed");
      else if (error == OTA_CONNECT_ERROR) Serial.println("Connect Failed");
      else if (error == OTA_RECEIVE_ERROR) Serial.println("Receive Failed");
      else if (error == OTA_END_ERROR) Serial.println("End Failed");
    });
    ArduinoOTA.begin();
}

void setupwifi () {
  Serial.begin(115200);
  delay(5000);
  Serial.println("Booting---");
  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);
  int teltje = 0;
  pinMode(ledPin, OUTPUT);     // Initialize the BUILTIN_LED pin as an output
  while (WiFi.status()!= WL_CONNECTED) {
    delay(250);
    digitalWrite(ledPin, HIGH); 
    delay(250);
    digitalWrite(ledPin, LOW);  
    teltje++;
    Serial.print(".");
    if (teltje>20) {
      Serial.println("Connection Failed! Rebooting...");
      delay(500);
      ESP.restart();
    }
  }
  Serial.println("Ready");
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());
}

void setup() {
  setupwifi();
  setupOTA();
}

void loop() {
  ArduinoOTA.handle();

}

@RobbbdeVries Indeed, your sketch doesn’t work with the latest framework version. So probably the best solution is to rewrite your code.

Shouldn’t it be downward compatible??

(I am just connecting to a Wifi-network with the most basic functions)

[SOLVED] Found it!
Because of the improved re-connect in the library my “WiFi.begin” was now in the wrong place…
first test if not already connected… if not THEN WiFi.begin…

  void setupWifi() {
    Serial.begin(115200);
    delay(2000);
    Serial.println("Booting...---");
    WiFi.mode(WIFI_STA);
    int teltje = 0;
    pinMode(pinLed, OUTPUT);     // Initialize the BUILTIN_LED pin as an output
    while (WiFi.status()!= WL_CONNECTED) {
      delay(250);
      digitalWrite(pinLed, HIGH);   
      delay(250);
      digitalWrite(pinLed, LOW);   
      if (teltje==0) {
        WiFi.begin(ssid, password); // only do WiFi.begin if not already connected
      }
      teltje++;
      Serial.print(".");
      if (teltje>20) {
        Serial.println("Connection Failed! Rebooting...");
        delay(500);
        ESP.restart();
      }
    }
    Serial.println("Ready");
    Serial.print("IP address: ");
    Serial.println(WiFi.localIP());
  }