Time library issue for NodeMCU in PlatformIO / VS Code on Windows 10

Hi

I’ve pasted code into this development environment that worked perfectly ok in the Arduino IDE with no compiler warnings or runtime issues.

It relates to using the built-in ESP8266 NTP library.

I’ve looked online and can see pretty much the same issue elsewhere but there was no solution -

https://community.platformio.org/t/issue-with-esp-idf-time-h/6986

This could also be related -

https://community.platformio.org/t/time-not-declared-in-platformio-but-works-in-arduino-ide/9417

I get an IntelliSense warning (‘identifier “setenv” is undefinedC/C++(20)’) for this line of code -

setenv("TZ", "GMT+0BST-1,M3.5.0/01:00:00,M10.5.0/02:00:00", 1);

Here’s the start of my code -

#include <Arduino.h>
#include "Wire.h"
#include "RTClib.h"
#include <ESP8266WiFi.h>
#include <time.h>

Here’s my platformio.ini file -

[env:nodemcuv2]
platform = espressif8266
board = nodemcuv2
framework = arduino
lib_deps =
  RTClib
lib_ignore = TinyWireM

I’ve read that this could be related to the fact that there are other time libraries and that I could be using the wrong one, meaning that setenv isn’t declared. However, the code does look like it may be workin ok.

Please would someone be able to suggest how I can get IntelliSense to deal with the code properly ?

Thanks

IntelliSense errors can be misleading. Does the code compile?

Thanks for the prompt reply :slight_smile:

I believe that it does compile ok as I see this -

> Executing task in folder Nixie clock - NODEMCU: C:\Users\xxxxx.platformio\penv\Scripts\platformio.exe run <

Processing nodemcuv2 (platform: espressif8266; board: nodemcuv2; framework: arduino)
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------Verbose mode can be enabled via -v, --verbose option
CONFIGURATION: Redirecting...
PLATFORM: Espressif 8266 (2.6.2) > NodeMCU 1.0 (ESP-12E Module)
HARDWARE: ESP8266 80MHz, 80KB RAM, 4MB Flash
PACKAGES:

    • framework-arduinoespressif8266 3.20704.0 (2.7.4)*
    • tool-esptool 1.413.0 (4.13)*
    • tool-esptoolpy 1.20800.0 (2.8.0)*
    • toolchain-xtensa 2.40802.200502 (4.8.2)*
      LDF: Library Dependency Finder → Library Dependency Finder (LDF) — PlatformIO latest documentation
      LDF Modes: Finder ~ chain, Compatibility ~ soft
      Found 31 compatible libraries
      Scanning dependencies…
      Dependency Graph
      *|-- 1.12.1 *
      *| |-- 1.0 *
      *|-- 1.0 *
      |-- 1.0
      Building in release mode
      Retrieving maximum program size .pio\build\nodemcuv2\firmware.elf
      Checking size .pio\build\nodemcuv2\firmware.elf
      Advanced Memory Usage is available via “PlatformIO Home > Project Inspect”
      RAM: [=== ] 34.1% (used 27948 bytes from 81920 bytes)
      Flash: [=== ] 26.4% (used 275784 bytes from 1044464 bytes)
      ================================================================================================== [SUCCESS] Took 1.42 seconds ==================================================================================================

The clock that I’m working on does show the correct time (after a few seconds, which I believe is caused by something else) for my location and daylight saving condition. Changing the string for another country also seems to get the correct results.

Still, it doesn’t feel right that I have the warnings in the code. It always looks wrong.

Thanks again.

The warning is coming from what the Microsoft C/C++ Intellisense extensions thinks about the code, given the header files as and a list of activated macros. The “error” comes from a mismatch of macros regarding __STRICT_ANSI__, which should be undefined in order to have this extended functionality. The thread Identifier is undefined - setenv tzset is already exactly about that with a workaround.