Arduino: undefined reference to `sntp_get_timezone'

Created on 20 Jun 2020  路  10Comments  路  Source: esp8266/Arduino

Hello, upgrading from 2.6.3 to 2.7.1 the following code does not compile anymore ...

#include <sntp.h>

void setup() {
    sntp_stop();
    sntp_setservername(0, "example.pool.com");
    sntp_set_timezone(0);
    sntp_init();
    const char* host = sntp_getservername(0);
    uint8_t tz = sntp_get_timezone();
    uint32_t ts = sntp_get_current_timestamp();
}

void loop() {

}

It throws this error:

/home/pulsartronic/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/2.5.0-4-b40a506/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld: sketch/example.ino.cpp.o:(.text.setup+0x4): undefined reference to `sntp_get_timezone'
/home/pulsartronic/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/2.5.0-4-b40a506/bin/../lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld: sketch/example.ino.cpp.o: in function `setup':
/home/pulsartronic/development/pulsartronic/Arduino/LoRaWANGatewaySC/example/example.ino:3: undefined reference to `sntp_get_timezone'
collect2: error: ld returned 1 exit status
exit status 1
Error compiling for board LOLIN(WEMOS) D1 R2 & mini.

Context:
SO: Ubuntu 18.04
IDE: Arduino IDE 1.8.12
Lib: esp8266 2.7.1

Am I doing something wrong ? ... any guide would be really apreciatted

waiting for feedback

All 10 comments

seems it is not present in lwip v2, you need to use v1.4

seems it is not present in lwip v2, you need to use v1.4

Where do i specify it ? ... is it a #define or something ?

thanks

in arduino ide check the esp8266 compilation settings

It has been removed in an optimization process because this function was an import from espressif timezone api (not part of lwIP), which was broken, and not used in the arduino API.
You can switch to the esp8266 arduino official configTime() API that recently evolved (#7234, #6993, #6373). The official NTP api is presented in the NTP-TZ-DST.ino example.

Now, you basically only need to use configTime(TZ_Europe_London, "example.pool.com"); to get always right and proper time.

If you really need to know time relative to UTC, you can do that with

time_t local, utc;
localtime(&local);
gmtime(&utc);

You'll get local time and UTC time in respective above time_t structures.

@pulsartronic lwIP 1.4 is removed in master and won't be available in next releases.
Is it OK with localtime and gmtime ?

@d-a-v sorry ... yes it is ok to me, thank you very much

@d-a-v hello
time_t local, utc;
localtime(&local);
gmtime(&utc);

local and utc end up having the exact same value, no matter what timezone is configured with
configTime(TZ_Europe_Madrid, "pool.ntp.org");

have you tried ? ... is it intended ?

Yes I tried
No it is not intended, I had got different values,
like when the ntp-tz-dst example is executed.
Is the time you get local or UTC or something else ?

Hi, this is the output of the example

localtime: isdst=1 yday=244 wday=2 year=120 mon=8 mday=1 hour=19 min=5 sec=30
gmtime: isdst=0 yday=244 wday=2 year=120 mon=8 mday=1 hour=17 min=5 sec=30
clock: 660s / 83065000ns
millis: 660083
micros: 660083087
gtod: 1598979930s / 286306us
time: 1598979930
timezone: CET-1CEST,M3.5.0,M10.5.0/3
ctime: Tue Sep 1 19:05:30 2020
sntp0: pool.ntp.org (147.156.7.26) IPv6: No Reachability: 1

localtime and gmtime have the right values when reading from tm structure, like this

time_t lt = time(nullptr);
tm* ltm = localtime(&lt);

time_t gt = time(nullptr);
tm* gtm = gtmtime(&gt);

yet "lt" and "gt" have the same value, it is the UTC value ... am i doing something wrong ?
In fact if i omit the "= time(nullptr);" values have no sense
I am trying to get local time in seconds since 1970, maybe it is not the correct way

should gtod and time be the same ?

yet "lt" and "gt" have the same value, it is the UTC value ...

https://linux.die.net/man/2/time

https://linux.die.net/man/3/localtime

I should revisit the example to use only one call to time() and add comments.

I am trying to get local time in seconds since 1970, maybe it is not the correct way

There's no proper/direct way for that to my knowledge.
One possible way is to use these functions and their inverse
https://linux.die.net/man/3/timegm while tweaking TZ to local or UTC

Was this page helpful?
0 / 5 - 0 ratings

Related issues

markusschweitzer picture markusschweitzer  路  3Comments

mechanic98 picture mechanic98  路  3Comments

SmartSouth picture SmartSouth  路  3Comments

pablotix20 picture pablotix20  路  3Comments

rudydevolder picture rudydevolder  路  3Comments