Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ESP32 SNTP sys.tz_spec weird result #595

Closed
alnunez opened this issue Jan 25, 2022 · 6 comments
Closed

ESP32 SNTP sys.tz_spec weird result #595

alnunez opened this issue Jan 25, 2022 · 6 comments

Comments

@alnunez
Copy link

alnunez commented Jan 25, 2022

Hi
I'm working with an ESP32 with mongoose OS V2.19.1.
Added SNTP library and setup and tried tho configure time zone for AMERICA/BOGOTA adding the following line to mos.yml

  • ["sys.tz_spec", "<-05>5"]

Bogota Time is UTC-5, however, after rebooting and SNTP sync the time showed was Greenwich plus 5 hours!!. Just for curiosity, changed the line this time to:

  • ["sys.tz_spec", "<+05>5"]

Rebooted, and SNTP synced. Now the time is correct!. Does somebody experienced the same thing?

@scaprile
Copy link

May I suggest you go to the forum and search there ? I've answered this at the forum and even have working examples in Spanish

@DrBomb
Copy link
Collaborator

DrBomb commented Jan 25, 2022

Some questions:

  • How did you read the time shown? Because the SNTP library shows you the unix timestamp on update regardless of your tz_spec value
  • tz_spec only affects a very specific subset of functions. localtime_r is one of them, while other functions like the widely used mg_time() will only return unix time as it should. What are you using?

Time inside C functions, and specially on mongoose can be complicated for begginers. I would suggest, @alnunez, that you make a sample app if you think that indeed, this is a bug on the code.

Good luck!

@alnunez
Copy link
Author

alnunez commented Jan 26, 2022

Here is the exact piece of code. A function that builds a message, including datetime. Timer.fmt() seems affected by tz_spec, because i tried different values, and all of them changed the time zone when printing timestamp.

function buildMsgUl(){

message_ul.sensor_id=DEVICE_ID;	
let extTemperatureCstr = roundNdigitsTostr(getTempC(),2);
message_ul.temperature_ext=extTemperatureCstr;
let intTemperatureCstr = roundNdigitsTostr((5/9)*(ESP32.temp()-32),2);
message_ul.temperature_int=intTemperatureCstr;	
let batVstr = getBatV();
message_ul.battery=roundNdigitsTostr(batVstr,2);
let timeunix = Timer.now();
let timestamp = Timer.fmt('%Y-%m-%d %H:%M:%S',timeunix);	
message_ul.timestamp = timestamp;

}

@DrBomb
Copy link
Collaborator

DrBomb commented Jan 26, 2022

mJS is outside my expertise, I don't use it.

That said, here's your reason https://unix.stackexchange.com/questions/104088/why-does-tz-utc-8-produce-dates-that-are-utc8

Basically the POSIX tz formats are 3 letters plus the offset. But the offset has to be on the opposite sign. Hence why ["sys.tz_spec", "<+05>5"] worked for you. Just use that one.

@DrBomb DrBomb closed this as completed Jan 26, 2022
@alnunez
Copy link
Author

alnunez commented Jan 26, 2022

Well after some more experimentation i found some discrepancies in tz for America/Bogota as follows:

from: https://github.com/mamuesp/timezones "America/Bogota":"<-05>5"
This value doesn't work, gave time UTC+5

from: https://github.com/openwisp/netjsonconfig/blob/master/netjsonconfig/backends/openwrt/timezones.py "America/Bogota", "COT5"
This value Works OK as expected (gave time UTC-5 )

@alnunez
Copy link
Author

alnunez commented Jan 26, 2022

mJS is outside my expertise, I don't use it.

That said, here's your reason https://unix.stackexchange.com/questions/104088/why-does-tz-utc-8-produce-dates-that-are-utc8

Basically the POSIX tz formats are 3 letters plus the offset. But the offset has to be on the opposite sign. Hence why ["sys.tz_spec", "<+05>5"] worked for you. Just use that one.

That's the answer i was looking for! thanks again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants