Code compiles in Arduino IDE, several errors in Platformio

Newbe here… I’m working on a project that becomes too bloated for Arduino IDE so I decided to see if Platformio is for me.
Small steps. I first did a blink project on the D1 Mini Pro I’m using for this project and that runs fine.
Then I loaded part of the code I use in my project. This compiles and runs fine in Arduino, but I get several errors in Platformio. The compiler complains it cannot find header files and expects different data types for a function. The code for this can be found here:

NTP-TZ-DTS

First of all, the compiler cannot find PolledTimeout.h. That library is part of the core esp8266 library so I would think that if it can find ESP8266WiFi.h it should also find PolledTimeout.h.
Next step I removed all ‘unnecessary’ code so I ended up with this:

#ifndef STASSID
#define STASSID "blah"                            // set your SSID
#define STAPSK  "blah"                        // set your wifi password
#endif

#define MY_NTP_SERVER "at.pool.ntp.org"           
#define MY_TZ "CET-1CEST,M3.5.0/02,M10.5.0/03"   

/* Necessary Includes */
#include <ESP8266WiFi.h>            // we need wifi to get internet access
#include <time.h>                   // time() ctime()

/* Globals */
time_t now;                         // this is the epoch
tm tm;                              // the structure tm holds time information in a more convient way

void showTime() {
  time(&now);                       // read the current time
  localtime_r(&now, &tm);           // update the structure tm with the current time
  Serial.print("year:");
  Serial.print(tm.tm_year + 1900);  // years since 1900
  Serial.print("\tmonth:");
  Serial.print(tm.tm_mon + 1);      // January = 0 (!)
  Serial.print("\tday:");
  Serial.print(tm.tm_mday);         // day of month
  Serial.print("\thour:");
  Serial.print(tm.tm_hour);         // hours since midnight  0-23
  Serial.print("\tmin:");
  Serial.print(tm.tm_min);          // minutes after the hour  0-59
  Serial.print("\tsec:");
  Serial.print(tm.tm_sec);          // seconds after the minute  0-61*
  Serial.print("\twday");
  Serial.print(tm.tm_wday);         // days since Sunday 0-6
  if (tm.tm_isdst == 1)             // Daylight Saving Time flag
    Serial.print("\tDST");
  else
    Serial.print("\tstandard");
  Serial.println();
}

void setup() {
  Serial.begin(115200);
  Serial.println("\nNTP TZ DST - bare minimum");

  configTime(MY_TZ, MY_NTP_SERVER); // --> Here is the IMPORTANT ONE LINER needed in your sketch!

  // start network
  WiFi.persistent(false);
  WiFi.mode(WIFI_STA);
  WiFi.begin(STASSID, STAPSK);
  while (WiFi.status() != WL_CONNECTED) {
    delay(200);
    Serial.print ( "." );
  }
  Serial.println("\nWiFi connected");
  // by default, the NTP will be started after 60 secs
}

void loop() {
  showTime();
  delay(10000); // dirty delay
}

This compiles and runs fine in Arduino IDE, but gives the following error in Platformio:

src/main.cpp: In function 'void setup()':
src/main.cpp:45:34: error: invalid conversion from 'const char*' to 'long int' [-fpermissive]
   configTime(MY_TZ, MY_NTP_SERVER); // --> Here is the IMPORTANT ONE LINER needed in your sketch!
                                  ^
    src/main.cpp:45:34: error: invalid conversion from 'const char*' to 'int' [-fpermissive]
    src/main.cpp:45:34: error: too few arguments to function 'void configTime(long int, int, const char*, const char*, const char*)'
    In file included from /Users/arjen/.platformio/packages/framework-arduinoespressif8266@src-31d658a59f41540201fc3726a1394910/libraries/ESP8266WiFi/src/WiFiClient.h:25:0,
                     from /Users/arjen/.platformio/packages/framework-arduinoespressif8266@src-31d658a59f41540201fc3726a1394910/libraries/ESP8266WiFi/src/ESP8266WiFi.h:39,
                     from src/main.cpp:10:
    /Users/arjen/.platformio/packages/framework-arduinoespressif8266@src-31d658a59f41540201fc3726a1394910/cores/esp8266/Arduino.h:292:17: note: declared here
     extern "C" void configTime(long timezone, int daylightOffset_sec,
                     ^
    *** [.pio/build/d1_mini_pro/src/main.cpp.o] Error 1

Seems Platformio uses another definition for the configTime() function than the Arduino IDE.
As I understand it Platformio loads the esp8266 libraries when needed, unlike Arduino where it is installed in the Arduino15 folder.
I’m not a very experienced programmer, so I’m probably missing something obvious but I have tried finding what could be wrong for two days now getting nowhere…

Careful - you’re linking to the master-branch version here, the bleeding edge development. In the latest platform-espressif8266 release, Arduino core version 2.7.4 is bundled. Changing that file to its version in its 2.7.4 release gives Arduino/libraries/esp8266/examples/NTP-TZ-DST/NTP-TZ-DST.ino at 2.7.4 · esp8266/Arduino · GitHub.

Using that code as src\main.cpp and a standard platformio.ini of

[env:nodemcuv2]
platform = espressif8266
board = nodemcuv2
framework = arduino

gives

Checking size .pio\build\nodemcuv2_serial\firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [===       ]  33.9% (used 27780 bytes from 81920 bytes)
Flash: [===       ]  26.7% (used 278792 bytes from 1044464 bytes)
======================== [SUCCESS] Took 1.72 seconds ========================

Is that what you want or do you need the bleeding-edge code and Arduino core?

Hi maxgerhardt,

Thanks for your reply. I did indeed not realise the code I linked to is ‘beta’ code. If, however I use the code you link to (and even change the ini file to your ‘nodemcu’ settings), I still get the error about PolledTimeout.h not being found. Furthermore, the other code I tested using only the two header files, still gives the type-error. So there must be more to it than not using the latest-and-maybe-not-so-greatest code :wink:

This path also shows that some git-version of the Arduino core is being used. What’s your platformio.ini?

My ini file is:

[env:nodemcuv2]

platform = espressif8266

board = nodemcuv2

framework = arduino

Like I said, I am new to Platformio so I don’t have a clue where it finds necessary libraries. A system search reveals that PolledTimeout.h is found only in /Users/arjen/Arduino15/etc. but not anywhere in /Users/arjen/.platformio/etc.
The function configTime() is only found in Arduino.h which in turn is only found in an esp32 directory inside the Arduino documents folder. So I have no clue where Platformio (or Arduino for that matter) finds its function definition.

By the way, I just did a complete clean system install on this computer (OSX11, Big Sur), installed Visual Studio with Platformio and nothing else. Arduino IDE is not installed on this system yet. So if Platformio is using a non-standard core for esp8266 it is Platformio that installed it. It cannot be some leftover stuff from a previous install…

Well somehow it seems it installed the wrong Arduino core version.

Can you open a PIO CLI and execute

rm -rf /Users/arjen/.platformio/packages/framework-arduinoespressif8266@src-31d658a59f41540201fc3726a1394910/
pio upgrade --dev 
pio run

and see if that compilation goes through?

The CLI commands ended in an error…

Compiling .pio/build/nodemcuv2/libd80/ESP8266WiFi/ESP8266WiFiGratuitous.cpp.o
xtensa-lx106-elf-g++: error: unrecognized command line option '-std=gnu++17'
Archiving .pio/build/nodemcuv2/lib1df/libTZ.a
*** [.pio/build/nodemcuv2/libd80/ESP8266WiFi/ESP8266WiFiGratuitous.cpp.o] Error 1
Indexing .pio/build/nodemcuv2/lib1df/libTZ.a

And compiling now gives all kinds of errors that look (to my inexperienced eye) like the error above:

Compiling .pio/build/nodemcuv2/src/main.cpp.o
xtensa-lx106-elf-g++: error: unrecognized command line option '-std=gnu++17'
Compiling .pio/build/nodemcuv2/libd80/ESP8266WiFi/BearSSLHelpers.cpp.o
Compiling .pio/build/nodemcuv2/libd80/ESP8266WiFi/CertStoreBearSSL.cpp.o
xtensa-lx106-elf-g++: error: unrecognized command line option '-std=gnu++17'
*** [.pio/build/nodemcuv2/src/main.cpp.o] Error 1
Compiling .pio/build/nodemcuv2/libd80/ESP8266WiFi/ESP8266WiFi.cpp.o
*** [.pio/build/nodemcuv2/libd80/ESP8266WiFi/BearSSLHelpers.cpp.o] Error 1
xtensa-lx106-elf-g++: error: unrecognized command line option '-std=gnu++17'
*** [.pio/build/nodemcuv2/libd80/ESP8266WiFi/CertStoreBearSSL.cpp.o] Error 1
xtensa-lx106-elf-g++: error: unrecognized command line option '-std=gnu++17'
*** [.pio/build/nodemcuv2/libd80/ESP8266WiFi/ESP8266WiFi.cpp.o] Error 1
=================================================== [FAILED] Took 1.12 seconds ===================================================

So I deleted the framework-etc again (via the mac-terminal) and tried again. This time no errors in the CLI, but compiling gives me another error:

Error: Could not find 'eagle.flash.16m.ld' LD script in LDPATH `'/Users/arjen/Documents/PlatformIO/Projects/DST_Test/.pio/build/d1_mini_pro /Us``ers/arjen/Documents/PlatformIO/Projects/DST_Test/.pio/build/d1_mini_pro/ld /Users/arjen/.platformio/packages/framework-arduinoespressif8266/tools/sdk/lib /Users/arjen/.platformio/packages/framework-arduinoespressif8266/tools/sdk/ld /Users/arjen/.platformio/packages/framework-arduinoespressif8266/tools/sdk/libc/xtensa-lx106-elf/lib /Users/arjen/.platformio/packages/framework-arduinoespressif8266/tools/sdk/lib/NONOSDK22x_190703'`
Error: Could not find 'eagle.flash.16m.ld' LD script in LDPATH '/Users/arjen/Documents/PlatformIO/Projects/DST_Test/.pio/build/d1_mini_pro /Users/arjen/Documents/PlatformIO/Projects/DST_Test/.pio/build/d1_mini_pro/ld /Users/arjen/.platformio/packages/framework-arduinoespressif8266/tools/sdk/lib /Users/arjen/.platformio/packages/framework-arduinoespressif8266/tools/sdk/ld /Users/arjen/.platformio/packages/framework-arduinoespressif8266/tools/sdk/libc/xtensa-lx106-elf/lib /Users/arjen/.platformio/packages/framework-arduinoespressif8266/tools/sdk/lib/NONOSDK22x_190703'

BTW, the 77 secs is including the time upgrade took.

Can you please delete the folder(s) /Users/arjen/.platformio/packages/platforms/espressif8266* too? Something is really wrong here…

=================================================== [SUCCESS] Took 2.02 seconds ===================================================
Threw out everything related to esp8266 in /Users/arjen/.platformio/etc and ran ‘upgrade’ and ‘run’ again.
Now it compiles! Something was indeed terribly wrong. I never like it when something goes wrong without me understanding why, but at least it appears to be solved.
Thanks very much for taking the time to help me. I hope I will learn to love Platformio, the Arduino IDE is not useable these days…