mirror of
https://github.com/esp8266/Arduino.git
synced 2025-04-19 23:22:16 +03:00
time: import IANA timezone definitions, expose SNTP API (#6373)
* time: import IANA timezone definitions - `configTime("timezone", "ntp servers...")` added - timezone definitions by country/cities (TZ.h) - script to update timezone definitions - updated example * fix former configTime non-matching signature * +include * example: add scheduled function in callback * crlf fix * +missing license for napt * SNTP: expose configuration helpers * update submodule * update precompiled libraries * optional: change SNTP startup delay * makes SNTP_UPDATE_DELAY a weak function update example fix for lwip1.4 * on the proper use of polledTimeout api... thanks @mcspr :] * improve update script (per review) * update lwIP submodule * update submodule * hide harmless shell message * update the release process by asking first to update TZ.h [ci skip] * minor update in release documentation * update in release documentation * update in release documentation * clarify release documentation * fix release documentation - sorry for the noise :( * fixes per review * example style * useless variable in example * update lwip2 submodule reference, to include espressif missing declaration fixes
This commit is contained in:
parent
4489e239bb
commit
ffe5476fc4
@ -275,10 +275,13 @@ long secureRandom(long);
|
||||
long secureRandom(long, long);
|
||||
long map(long, long, long, long, long);
|
||||
|
||||
extern "C" void configTime(long timezone, int daylightOffset_sec,
|
||||
const char* server1, const char* server2 = nullptr, const char* server3 = nullptr);
|
||||
void configTime(int timezone, int daylightOffset_sec, const char* server1,
|
||||
const char* server2 = nullptr, const char* server3 = nullptr);
|
||||
|
||||
#endif
|
||||
void configTime(const char* tz, const char* server1,
|
||||
const char* server2 = nullptr, const char* server3 = nullptr);
|
||||
|
||||
#endif // __cplusplus
|
||||
|
||||
#include "pins_arduino.h"
|
||||
|
||||
|
475
cores/esp8266/TZ.h
Normal file
475
cores/esp8266/TZ.h
Normal file
@ -0,0 +1,475 @@
|
||||
|
||||
// autogenerated from https://raw.githubusercontent.com/nayarsystems/posix_tz_db/master/zones.csv
|
||||
// by script <esp8266 arduino core>/tools/TZupdate.sh
|
||||
// Mon Sep 9 20:58:30 UTC 2019
|
||||
//
|
||||
// This database is autogenerated from IANA timezone database
|
||||
// https://www.iana.org/time-zones
|
||||
// and can be updated on demand in this repository
|
||||
// or by yourself using the above script
|
||||
|
||||
#ifndef TZDB_H
|
||||
#define TZDB_H
|
||||
|
||||
#define TZ_Africa_Abidjan PSTR("GMT0")
|
||||
#define TZ_Africa_Accra PSTR("GMT0")
|
||||
#define TZ_Africa_Addis_Ababa PSTR("EAT-3")
|
||||
#define TZ_Africa_Algiers PSTR("CET-1")
|
||||
#define TZ_Africa_Asmara PSTR("EAT-3")
|
||||
#define TZ_Africa_Bamako PSTR("GMT0")
|
||||
#define TZ_Africa_Bangui PSTR("WAT-1")
|
||||
#define TZ_Africa_Banjul PSTR("GMT0")
|
||||
#define TZ_Africa_Bissau PSTR("GMT0")
|
||||
#define TZ_Africa_Blantyre PSTR("CAT-2")
|
||||
#define TZ_Africa_Brazzaville PSTR("WAT-1")
|
||||
#define TZ_Africa_Bujumbura PSTR("CAT-2")
|
||||
#define TZ_Africa_Cairo PSTR("EET-2")
|
||||
#define TZ_Africa_Casablanca PSTR("<+01>-1")
|
||||
#define TZ_Africa_Ceuta PSTR("CET-1CEST,M3.5.0,M10.5.0/3")
|
||||
#define TZ_Africa_Conakry PSTR("GMT0")
|
||||
#define TZ_Africa_Dakar PSTR("GMT0")
|
||||
#define TZ_Africa_Dar_es_Salaam PSTR("EAT-3")
|
||||
#define TZ_Africa_Djibouti PSTR("EAT-3")
|
||||
#define TZ_Africa_Douala PSTR("WAT-1")
|
||||
#define TZ_Africa_El_Aaiun PSTR("<+01>-1")
|
||||
#define TZ_Africa_Freetown PSTR("GMT0")
|
||||
#define TZ_Africa_Gaborone PSTR("CAT-2")
|
||||
#define TZ_Africa_Harare PSTR("CAT-2")
|
||||
#define TZ_Africa_Johannesburg PSTR("SAST-2")
|
||||
#define TZ_Africa_Juba PSTR("EAT-3")
|
||||
#define TZ_Africa_Kampala PSTR("EAT-3")
|
||||
#define TZ_Africa_Khartoum PSTR("CAT-2")
|
||||
#define TZ_Africa_Kigali PSTR("CAT-2")
|
||||
#define TZ_Africa_Kinshasa PSTR("WAT-1")
|
||||
#define TZ_Africa_Lagos PSTR("WAT-1")
|
||||
#define TZ_Africa_Libreville PSTR("WAT-1")
|
||||
#define TZ_Africa_Lome PSTR("GMT0")
|
||||
#define TZ_Africa_Luanda PSTR("WAT-1")
|
||||
#define TZ_Africa_Lubumbashi PSTR("CAT-2")
|
||||
#define TZ_Africa_Lusaka PSTR("CAT-2")
|
||||
#define TZ_Africa_Malabo PSTR("WAT-1")
|
||||
#define TZ_Africa_Maputo PSTR("CAT-2")
|
||||
#define TZ_Africa_Maseru PSTR("SAST-2")
|
||||
#define TZ_Africa_Mbabane PSTR("SAST-2")
|
||||
#define TZ_Africa_Mogadishu PSTR("EAT-3")
|
||||
#define TZ_Africa_Monrovia PSTR("GMT0")
|
||||
#define TZ_Africa_Nairobi PSTR("EAT-3")
|
||||
#define TZ_Africa_Ndjamena PSTR("WAT-1")
|
||||
#define TZ_Africa_Niamey PSTR("WAT-1")
|
||||
#define TZ_Africa_Nouakchott PSTR("GMT0")
|
||||
#define TZ_Africa_Ouagadougou PSTR("GMT0")
|
||||
#define TZ_Africa_PortomNovo PSTR("WAT-1")
|
||||
#define TZ_Africa_Sao_Tome PSTR("GMT0")
|
||||
#define TZ_Africa_Tripoli PSTR("EET-2")
|
||||
#define TZ_Africa_Tunis PSTR("CET-1")
|
||||
#define TZ_Africa_Windhoek PSTR("CAT-2")
|
||||
#define TZ_America_Adak PSTR("HST10HDT,M3.2.0,M11.1.0")
|
||||
#define TZ_America_Anchorage PSTR("AKST9AKDT,M3.2.0,M11.1.0")
|
||||
#define TZ_America_Anguilla PSTR("AST4")
|
||||
#define TZ_America_Antigua PSTR("AST4")
|
||||
#define TZ_America_Araguaina PSTR("<-03>3")
|
||||
#define TZ_America_Argentina_Buenos_Aires PSTR("<-03>3")
|
||||
#define TZ_America_Argentina_Catamarca PSTR("<-03>3")
|
||||
#define TZ_America_Argentina_Cordoba PSTR("<-03>3")
|
||||
#define TZ_America_Argentina_Jujuy PSTR("<-03>3")
|
||||
#define TZ_America_Argentina_La_Rioja PSTR("<-03>3")
|
||||
#define TZ_America_Argentina_Mendoza PSTR("<-03>3")
|
||||
#define TZ_America_Argentina_Rio_Gallegos PSTR("<-03>3")
|
||||
#define TZ_America_Argentina_Salta PSTR("<-03>3")
|
||||
#define TZ_America_Argentina_San_Juan PSTR("<-03>3")
|
||||
#define TZ_America_Argentina_San_Luis PSTR("<-03>3")
|
||||
#define TZ_America_Argentina_Tucuman PSTR("<-03>3")
|
||||
#define TZ_America_Argentina_Ushuaia PSTR("<-03>3")
|
||||
#define TZ_America_Aruba PSTR("AST4")
|
||||
#define TZ_America_Asuncion PSTR("<-04>4<-03>,M10.1.0/0,M3.4.0/0")
|
||||
#define TZ_America_Atikokan PSTR("EST5")
|
||||
#define TZ_America_Bahia PSTR("<-03>3")
|
||||
#define TZ_America_Bahia_Banderas PSTR("CST6CDT,M4.1.0,M10.5.0")
|
||||
#define TZ_America_Barbados PSTR("AST4")
|
||||
#define TZ_America_Belem PSTR("<-03>3")
|
||||
#define TZ_America_Belize PSTR("CST6")
|
||||
#define TZ_America_BlancmSablon PSTR("AST4")
|
||||
#define TZ_America_Boa_Vista PSTR("<-04>4")
|
||||
#define TZ_America_Bogota PSTR("<-05>5")
|
||||
#define TZ_America_Boise PSTR("MST7MDT,M3.2.0,M11.1.0")
|
||||
#define TZ_America_Cambridge_Bay PSTR("MST7MDT,M3.2.0,M11.1.0")
|
||||
#define TZ_America_Campo_Grande PSTR("<-04>4")
|
||||
#define TZ_America_Cancun PSTR("EST5")
|
||||
#define TZ_America_Caracas PSTR("<-04>4")
|
||||
#define TZ_America_Cayenne PSTR("<-03>3")
|
||||
#define TZ_America_Cayman PSTR("EST5")
|
||||
#define TZ_America_Chicago PSTR("CST6CDT,M3.2.0,M11.1.0")
|
||||
#define TZ_America_Chihuahua PSTR("MST7MDT,M4.1.0,M10.5.0")
|
||||
#define TZ_America_Costa_Rica PSTR("CST6")
|
||||
#define TZ_America_Creston PSTR("MST7")
|
||||
#define TZ_America_Cuiaba PSTR("<-04>4")
|
||||
#define TZ_America_Curacao PSTR("AST4")
|
||||
#define TZ_America_Danmarkshavn PSTR("GMT0")
|
||||
#define TZ_America_Dawson PSTR("PST8PDT,M3.2.0,M11.1.0")
|
||||
#define TZ_America_Dawson_Creek PSTR("MST7")
|
||||
#define TZ_America_Denver PSTR("MST7MDT,M3.2.0,M11.1.0")
|
||||
#define TZ_America_Detroit PSTR("EST5EDT,M3.2.0,M11.1.0")
|
||||
#define TZ_America_Dominica PSTR("AST4")
|
||||
#define TZ_America_Edmonton PSTR("MST7MDT,M3.2.0,M11.1.0")
|
||||
#define TZ_America_Eirunepe PSTR("<-05>5")
|
||||
#define TZ_America_El_Salvador PSTR("CST6")
|
||||
#define TZ_America_Fortaleza PSTR("<-03>3")
|
||||
#define TZ_America_Fort_Nelson PSTR("MST7")
|
||||
#define TZ_America_Glace_Bay PSTR("AST4ADT,M3.2.0,M11.1.0")
|
||||
#define TZ_America_Godthab PSTR("<-03>3<-02>,M3.5.0/-2,M10.5.0/-1")
|
||||
#define TZ_America_Goose_Bay PSTR("AST4ADT,M3.2.0,M11.1.0")
|
||||
#define TZ_America_Grand_Turk PSTR("EST5EDT,M3.2.0,M11.1.0")
|
||||
#define TZ_America_Grenada PSTR("AST4")
|
||||
#define TZ_America_Guadeloupe PSTR("AST4")
|
||||
#define TZ_America_Guatemala PSTR("CST6")
|
||||
#define TZ_America_Guayaquil PSTR("<-05>5")
|
||||
#define TZ_America_Guyana PSTR("<-04>4")
|
||||
#define TZ_America_Halifax PSTR("AST4ADT,M3.2.0,M11.1.0")
|
||||
#define TZ_America_Havana PSTR("CST5CDT,M3.2.0/0,M11.1.0/1")
|
||||
#define TZ_America_Hermosillo PSTR("MST7")
|
||||
#define TZ_America_Indiana_Indianapolis PSTR("EST5EDT,M3.2.0,M11.1.0")
|
||||
#define TZ_America_Indiana_Knox PSTR("CST6CDT,M3.2.0,M11.1.0")
|
||||
#define TZ_America_Indiana_Marengo PSTR("EST5EDT,M3.2.0,M11.1.0")
|
||||
#define TZ_America_Indiana_Petersburg PSTR("EST5EDT,M3.2.0,M11.1.0")
|
||||
#define TZ_America_Indiana_Tell_City PSTR("CST6CDT,M3.2.0,M11.1.0")
|
||||
#define TZ_America_Indiana_Vevay PSTR("EST5EDT,M3.2.0,M11.1.0")
|
||||
#define TZ_America_Indiana_Vincennes PSTR("EST5EDT,M3.2.0,M11.1.0")
|
||||
#define TZ_America_Indiana_Winamac PSTR("EST5EDT,M3.2.0,M11.1.0")
|
||||
#define TZ_America_Inuvik PSTR("MST7MDT,M3.2.0,M11.1.0")
|
||||
#define TZ_America_Iqaluit PSTR("EST5EDT,M3.2.0,M11.1.0")
|
||||
#define TZ_America_Jamaica PSTR("EST5")
|
||||
#define TZ_America_Juneau PSTR("AKST9AKDT,M3.2.0,M11.1.0")
|
||||
#define TZ_America_Kentucky_Louisville PSTR("EST5EDT,M3.2.0,M11.1.0")
|
||||
#define TZ_America_Kentucky_Monticello PSTR("EST5EDT,M3.2.0,M11.1.0")
|
||||
#define TZ_America_Kralendijk PSTR("AST4")
|
||||
#define TZ_America_La_Paz PSTR("<-04>4")
|
||||
#define TZ_America_Lima PSTR("<-05>5")
|
||||
#define TZ_America_Los_Angeles PSTR("PST8PDT,M3.2.0,M11.1.0")
|
||||
#define TZ_America_Lower_Princes PSTR("AST4")
|
||||
#define TZ_America_Maceio PSTR("<-03>3")
|
||||
#define TZ_America_Managua PSTR("CST6")
|
||||
#define TZ_America_Manaus PSTR("<-04>4")
|
||||
#define TZ_America_Marigot PSTR("AST4")
|
||||
#define TZ_America_Martinique PSTR("AST4")
|
||||
#define TZ_America_Matamoros PSTR("CST6CDT,M3.2.0,M11.1.0")
|
||||
#define TZ_America_Mazatlan PSTR("MST7MDT,M4.1.0,M10.5.0")
|
||||
#define TZ_America_Menominee PSTR("CST6CDT,M3.2.0,M11.1.0")
|
||||
#define TZ_America_Merida PSTR("CST6CDT,M4.1.0,M10.5.0")
|
||||
#define TZ_America_Metlakatla PSTR("AKST9AKDT,M3.2.0,M11.1.0")
|
||||
#define TZ_America_Mexico_City PSTR("CST6CDT,M4.1.0,M10.5.0")
|
||||
#define TZ_America_Miquelon PSTR("<-03>3<-02>,M3.2.0,M11.1.0")
|
||||
#define TZ_America_Moncton PSTR("AST4ADT,M3.2.0,M11.1.0")
|
||||
#define TZ_America_Monterrey PSTR("CST6CDT,M4.1.0,M10.5.0")
|
||||
#define TZ_America_Montevideo PSTR("<-03>3")
|
||||
#define TZ_America_Montreal PSTR("EST5EDT,M3.2.0,M11.1.0")
|
||||
#define TZ_America_Montserrat PSTR("AST4")
|
||||
#define TZ_America_Nassau PSTR("EST5EDT,M3.2.0,M11.1.0")
|
||||
#define TZ_America_New_York PSTR("EST5EDT,M3.2.0,M11.1.0")
|
||||
#define TZ_America_Nipigon PSTR("EST5EDT,M3.2.0,M11.1.0")
|
||||
#define TZ_America_Nome PSTR("AKST9AKDT,M3.2.0,M11.1.0")
|
||||
#define TZ_America_Noronha PSTR("<-02>2")
|
||||
#define TZ_America_North_Dakota_Beulah PSTR("CST6CDT,M3.2.0,M11.1.0")
|
||||
#define TZ_America_North_Dakota_Center PSTR("CST6CDT,M3.2.0,M11.1.0")
|
||||
#define TZ_America_North_Dakota_New_Salem PSTR("CST6CDT,M3.2.0,M11.1.0")
|
||||
#define TZ_America_Ojinaga PSTR("MST7MDT,M3.2.0,M11.1.0")
|
||||
#define TZ_America_Panama PSTR("EST5")
|
||||
#define TZ_America_Pangnirtung PSTR("EST5EDT,M3.2.0,M11.1.0")
|
||||
#define TZ_America_Paramaribo PSTR("<-03>3")
|
||||
#define TZ_America_Phoenix PSTR("MST7")
|
||||
#define TZ_America_PortmaumPrince PSTR("EST5EDT,M3.2.0,M11.1.0")
|
||||
#define TZ_America_Port_of_Spain PSTR("AST4")
|
||||
#define TZ_America_Porto_Velho PSTR("<-04>4")
|
||||
#define TZ_America_Puerto_Rico PSTR("AST4")
|
||||
#define TZ_America_Punta_Arenas PSTR("<-03>3")
|
||||
#define TZ_America_Rainy_River PSTR("CST6CDT,M3.2.0,M11.1.0")
|
||||
#define TZ_America_Rankin_Inlet PSTR("CST6CDT,M3.2.0,M11.1.0")
|
||||
#define TZ_America_Recife PSTR("<-03>3")
|
||||
#define TZ_America_Regina PSTR("CST6")
|
||||
#define TZ_America_Resolute PSTR("CST6CDT,M3.2.0,M11.1.0")
|
||||
#define TZ_America_Rio_Branco PSTR("<-05>5")
|
||||
#define TZ_America_Santarem PSTR("<-03>3")
|
||||
#define TZ_America_Santiago PSTR("<-04>4<-03>,M9.1.6/24,M4.1.6/24")
|
||||
#define TZ_America_Santo_Domingo PSTR("AST4")
|
||||
#define TZ_America_Sao_Paulo PSTR("<-03>3")
|
||||
#define TZ_America_Scoresbysund PSTR("<-01>1<+00>,M3.5.0/0,M10.5.0/1")
|
||||
#define TZ_America_Sitka PSTR("AKST9AKDT,M3.2.0,M11.1.0")
|
||||
#define TZ_America_St_Barthelemy PSTR("AST4")
|
||||
#define TZ_America_St_Johns PSTR("NST3:30NDT,M3.2.0,M11.1.0")
|
||||
#define TZ_America_St_Kitts PSTR("AST4")
|
||||
#define TZ_America_St_Lucia PSTR("AST4")
|
||||
#define TZ_America_St_Thomas PSTR("AST4")
|
||||
#define TZ_America_St_Vincent PSTR("AST4")
|
||||
#define TZ_America_Swift_Current PSTR("CST6")
|
||||
#define TZ_America_Tegucigalpa PSTR("CST6")
|
||||
#define TZ_America_Thule PSTR("AST4ADT,M3.2.0,M11.1.0")
|
||||
#define TZ_America_Thunder_Bay PSTR("EST5EDT,M3.2.0,M11.1.0")
|
||||
#define TZ_America_Tijuana PSTR("PST8PDT,M3.2.0,M11.1.0")
|
||||
#define TZ_America_Toronto PSTR("EST5EDT,M3.2.0,M11.1.0")
|
||||
#define TZ_America_Tortola PSTR("AST4")
|
||||
#define TZ_America_Vancouver PSTR("PST8PDT,M3.2.0,M11.1.0")
|
||||
#define TZ_America_Whitehorse PSTR("PST8PDT,M3.2.0,M11.1.0")
|
||||
#define TZ_America_Winnipeg PSTR("CST6CDT,M3.2.0,M11.1.0")
|
||||
#define TZ_America_Yakutat PSTR("AKST9AKDT,M3.2.0,M11.1.0")
|
||||
#define TZ_America_Yellowknife PSTR("MST7MDT,M3.2.0,M11.1.0")
|
||||
#define TZ_Antarctica_Casey PSTR("<+08>-8")
|
||||
#define TZ_Antarctica_Davis PSTR("<+07>-7")
|
||||
#define TZ_Antarctica_DumontDUrville PSTR("<+10>-10")
|
||||
#define TZ_Antarctica_Macquarie PSTR("<+11>-11")
|
||||
#define TZ_Antarctica_Mawson PSTR("<+05>-5")
|
||||
#define TZ_Antarctica_McMurdo PSTR("NZST-12NZDT,M9.5.0,M4.1.0/3")
|
||||
#define TZ_Antarctica_Palmer PSTR("<-03>3")
|
||||
#define TZ_Antarctica_Rothera PSTR("<-03>3")
|
||||
#define TZ_Antarctica_Syowa PSTR("<+03>-3")
|
||||
#define TZ_Antarctica_Troll PSTR("<+00>0<+02>-2,M3.5.0/1,M10.5.0/3")
|
||||
#define TZ_Antarctica_Vostok PSTR("<+06>-6")
|
||||
#define TZ_Arctic_Longyearbyen PSTR("CET-1CEST,M3.5.0,M10.5.0/3")
|
||||
#define TZ_Asia_Aden PSTR("<+03>-3")
|
||||
#define TZ_Asia_Almaty PSTR("<+06>-6")
|
||||
#define TZ_Asia_Amman PSTR("EET-2EEST,M3.5.4/24,M10.5.5/1")
|
||||
#define TZ_Asia_Anadyr PSTR("<+12>-12")
|
||||
#define TZ_Asia_Aqtau PSTR("<+05>-5")
|
||||
#define TZ_Asia_Aqtobe PSTR("<+05>-5")
|
||||
#define TZ_Asia_Ashgabat PSTR("<+05>-5")
|
||||
#define TZ_Asia_Atyrau PSTR("<+05>-5")
|
||||
#define TZ_Asia_Baghdad PSTR("<+03>-3")
|
||||
#define TZ_Asia_Bahrain PSTR("<+03>-3")
|
||||
#define TZ_Asia_Baku PSTR("<+04>-4")
|
||||
#define TZ_Asia_Bangkok PSTR("<+07>-7")
|
||||
#define TZ_Asia_Barnaul PSTR("<+07>-7")
|
||||
#define TZ_Asia_Beirut PSTR("EET-2EEST,M3.5.0/0,M10.5.0/0")
|
||||
#define TZ_Asia_Bishkek PSTR("<+06>-6")
|
||||
#define TZ_Asia_Brunei PSTR("<+08>-8")
|
||||
#define TZ_Asia_Chita PSTR("<+09>-9")
|
||||
#define TZ_Asia_Choibalsan PSTR("<+08>-8")
|
||||
#define TZ_Asia_Colombo PSTR("<+0530>-5:30")
|
||||
#define TZ_Asia_Damascus PSTR("EET-2EEST,M3.5.5/0,M10.5.5/0")
|
||||
#define TZ_Asia_Dhaka PSTR("<+06>-6")
|
||||
#define TZ_Asia_Dili PSTR("<+09>-9")
|
||||
#define TZ_Asia_Dubai PSTR("<+04>-4")
|
||||
#define TZ_Asia_Dushanbe PSTR("<+05>-5")
|
||||
#define TZ_Asia_Famagusta PSTR("EET-2EEST,M3.5.0/3,M10.5.0/4")
|
||||
#define TZ_Asia_Gaza PSTR("EET-2EEST,M3.5.5/0,M10.5.6/1")
|
||||
#define TZ_Asia_Hebron PSTR("EET-2EEST,M3.5.5/0,M10.5.6/1")
|
||||
#define TZ_Asia_Ho_Chi_Minh PSTR("<+07>-7")
|
||||
#define TZ_Asia_Hong_Kong PSTR("HKT-8")
|
||||
#define TZ_Asia_Hovd PSTR("<+07>-7")
|
||||
#define TZ_Asia_Irkutsk PSTR("<+08>-8")
|
||||
#define TZ_Asia_Jakarta PSTR("WIB-7")
|
||||
#define TZ_Asia_Jayapura PSTR("WIT-9")
|
||||
#define TZ_Asia_Jerusalem PSTR("IST-2IDT,M3.4.4/26,M10.5.0")
|
||||
#define TZ_Asia_Kabul PSTR("<+0430>-4:30")
|
||||
#define TZ_Asia_Kamchatka PSTR("<+12>-12")
|
||||
#define TZ_Asia_Karachi PSTR("PKT-5")
|
||||
#define TZ_Asia_Kathmandu PSTR("<+0545>-5:45")
|
||||
#define TZ_Asia_Khandyga PSTR("<+09>-9")
|
||||
#define TZ_Asia_Kolkata PSTR("IST-5:30")
|
||||
#define TZ_Asia_Krasnoyarsk PSTR("<+07>-7")
|
||||
#define TZ_Asia_Kuala_Lumpur PSTR("<+08>-8")
|
||||
#define TZ_Asia_Kuching PSTR("<+08>-8")
|
||||
#define TZ_Asia_Kuwait PSTR("<+03>-3")
|
||||
#define TZ_Asia_Macau PSTR("CST-8")
|
||||
#define TZ_Asia_Magadan PSTR("<+11>-11")
|
||||
#define TZ_Asia_Makassar PSTR("WITA-8")
|
||||
#define TZ_Asia_Manila PSTR("PST-8")
|
||||
#define TZ_Asia_Muscat PSTR("<+04>-4")
|
||||
#define TZ_Asia_Nicosia PSTR("EET-2EEST,M3.5.0/3,M10.5.0/4")
|
||||
#define TZ_Asia_Novokuznetsk PSTR("<+07>-7")
|
||||
#define TZ_Asia_Novosibirsk PSTR("<+07>-7")
|
||||
#define TZ_Asia_Omsk PSTR("<+06>-6")
|
||||
#define TZ_Asia_Oral PSTR("<+05>-5")
|
||||
#define TZ_Asia_Phnom_Penh PSTR("<+07>-7")
|
||||
#define TZ_Asia_Pontianak PSTR("WIB-7")
|
||||
#define TZ_Asia_Pyongyang PSTR("KST-9")
|
||||
#define TZ_Asia_Qatar PSTR("<+03>-3")
|
||||
#define TZ_Asia_Qyzylorda PSTR("<+05>-5")
|
||||
#define TZ_Asia_Riyadh PSTR("<+03>-3")
|
||||
#define TZ_Asia_Sakhalin PSTR("<+11>-11")
|
||||
#define TZ_Asia_Samarkand PSTR("<+05>-5")
|
||||
#define TZ_Asia_Seoul PSTR("KST-9")
|
||||
#define TZ_Asia_Shanghai PSTR("CST-8")
|
||||
#define TZ_Asia_Singapore PSTR("<+08>-8")
|
||||
#define TZ_Asia_Srednekolymsk PSTR("<+11>-11")
|
||||
#define TZ_Asia_Taipei PSTR("CST-8")
|
||||
#define TZ_Asia_Tashkent PSTR("<+05>-5")
|
||||
#define TZ_Asia_Tbilisi PSTR("<+04>-4")
|
||||
#define TZ_Asia_Tehran PSTR("<+0330>-3:30<+0430>,J79/24,J263/24")
|
||||
#define TZ_Asia_Thimphu PSTR("<+06>-6")
|
||||
#define TZ_Asia_Tokyo PSTR("JST-9")
|
||||
#define TZ_Asia_Tomsk PSTR("<+07>-7")
|
||||
#define TZ_Asia_Ulaanbaatar PSTR("<+08>-8")
|
||||
#define TZ_Asia_Urumqi PSTR("<+06>-6")
|
||||
#define TZ_Asia_UstmNera PSTR("<+10>-10")
|
||||
#define TZ_Asia_Vientiane PSTR("<+07>-7")
|
||||
#define TZ_Asia_Vladivostok PSTR("<+10>-10")
|
||||
#define TZ_Asia_Yakutsk PSTR("<+09>-9")
|
||||
#define TZ_Asia_Yangon PSTR("<+0630>-6:30")
|
||||
#define TZ_Asia_Yekaterinburg PSTR("<+05>-5")
|
||||
#define TZ_Asia_Yerevan PSTR("<+04>-4")
|
||||
#define TZ_Atlantic_Azores PSTR("<-01>1<+00>,M3.5.0/0,M10.5.0/1")
|
||||
#define TZ_Atlantic_Bermuda PSTR("AST4ADT,M3.2.0,M11.1.0")
|
||||
#define TZ_Atlantic_Canary PSTR("WET0WEST,M3.5.0/1,M10.5.0")
|
||||
#define TZ_Atlantic_Cape_Verde PSTR("<-01>1")
|
||||
#define TZ_Atlantic_Faroe PSTR("WET0WEST,M3.5.0/1,M10.5.0")
|
||||
#define TZ_Atlantic_Madeira PSTR("WET0WEST,M3.5.0/1,M10.5.0")
|
||||
#define TZ_Atlantic_Reykjavik PSTR("GMT0")
|
||||
#define TZ_Atlantic_South_Georgia PSTR("<-02>2")
|
||||
#define TZ_Atlantic_Stanley PSTR("<-03>3")
|
||||
#define TZ_Atlantic_St_Helena PSTR("GMT0")
|
||||
#define TZ_Australia_Adelaide PSTR("ACST-9:30ACDT,M10.1.0,M4.1.0/3")
|
||||
#define TZ_Australia_Brisbane PSTR("AEST-10")
|
||||
#define TZ_Australia_Broken_Hill PSTR("ACST-9:30ACDT,M10.1.0,M4.1.0/3")
|
||||
#define TZ_Australia_Currie PSTR("AEST-10AEDT,M10.1.0,M4.1.0/3")
|
||||
#define TZ_Australia_Darwin PSTR("ACST-9:30")
|
||||
#define TZ_Australia_Eucla PSTR("<+0845>-8:45")
|
||||
#define TZ_Australia_Hobart PSTR("AEST-10AEDT,M10.1.0,M4.1.0/3")
|
||||
#define TZ_Australia_Lindeman PSTR("AEST-10")
|
||||
#define TZ_Australia_Lord_Howe PSTR("<+1030>-10:30<+11>-11,M10.1.0,M4.1.0")
|
||||
#define TZ_Australia_Melbourne PSTR("AEST-10AEDT,M10.1.0,M4.1.0/3")
|
||||
#define TZ_Australia_Perth PSTR("AWST-8")
|
||||
#define TZ_Australia_Sydney PSTR("AEST-10AEDT,M10.1.0,M4.1.0/3")
|
||||
#define TZ_Europe_Amsterdam PSTR("CET-1CEST,M3.5.0,M10.5.0/3")
|
||||
#define TZ_Europe_Andorra PSTR("CET-1CEST,M3.5.0,M10.5.0/3")
|
||||
#define TZ_Europe_Astrakhan PSTR("<+04>-4")
|
||||
#define TZ_Europe_Athens PSTR("EET-2EEST,M3.5.0/3,M10.5.0/4")
|
||||
#define TZ_Europe_Belgrade PSTR("CET-1CEST,M3.5.0,M10.5.0/3")
|
||||
#define TZ_Europe_Berlin PSTR("CET-1CEST,M3.5.0,M10.5.0/3")
|
||||
#define TZ_Europe_Bratislava PSTR("CET-1CEST,M3.5.0,M10.5.0/3")
|
||||
#define TZ_Europe_Brussels PSTR("CET-1CEST,M3.5.0,M10.5.0/3")
|
||||
#define TZ_Europe_Bucharest PSTR("EET-2EEST,M3.5.0/3,M10.5.0/4")
|
||||
#define TZ_Europe_Budapest PSTR("CET-1CEST,M3.5.0,M10.5.0/3")
|
||||
#define TZ_Europe_Busingen PSTR("CET-1CEST,M3.5.0,M10.5.0/3")
|
||||
#define TZ_Europe_Chisinau PSTR("EET-2EEST,M3.5.0,M10.5.0/3")
|
||||
#define TZ_Europe_Copenhagen PSTR("CET-1CEST,M3.5.0,M10.5.0/3")
|
||||
#define TZ_Europe_Dublin PSTR("IST-1GMT0,M10.5.0,M3.5.0/1")
|
||||
#define TZ_Europe_Gibraltar PSTR("CET-1CEST,M3.5.0,M10.5.0/3")
|
||||
#define TZ_Europe_Guernsey PSTR("GMT0BST,M3.5.0/1,M10.5.0")
|
||||
#define TZ_Europe_Helsinki PSTR("EET-2EEST,M3.5.0/3,M10.5.0/4")
|
||||
#define TZ_Europe_Isle_of_Man PSTR("GMT0BST,M3.5.0/1,M10.5.0")
|
||||
#define TZ_Europe_Istanbul PSTR("<+03>-3")
|
||||
#define TZ_Europe_Jersey PSTR("GMT0BST,M3.5.0/1,M10.5.0")
|
||||
#define TZ_Europe_Kaliningrad PSTR("EET-2")
|
||||
#define TZ_Europe_Kiev PSTR("EET-2EEST,M3.5.0/3,M10.5.0/4")
|
||||
#define TZ_Europe_Kirov PSTR("<+03>-3")
|
||||
#define TZ_Europe_Lisbon PSTR("WET0WEST,M3.5.0/1,M10.5.0")
|
||||
#define TZ_Europe_Ljubljana PSTR("CET-1CEST,M3.5.0,M10.5.0/3")
|
||||
#define TZ_Europe_London PSTR("GMT0BST,M3.5.0/1,M10.5.0")
|
||||
#define TZ_Europe_Luxembourg PSTR("CET-1CEST,M3.5.0,M10.5.0/3")
|
||||
#define TZ_Europe_Madrid PSTR("CET-1CEST,M3.5.0,M10.5.0/3")
|
||||
#define TZ_Europe_Malta PSTR("CET-1CEST,M3.5.0,M10.5.0/3")
|
||||
#define TZ_Europe_Mariehamn PSTR("EET-2EEST,M3.5.0/3,M10.5.0/4")
|
||||
#define TZ_Europe_Minsk PSTR("<+03>-3")
|
||||
#define TZ_Europe_Monaco PSTR("CET-1CEST,M3.5.0,M10.5.0/3")
|
||||
#define TZ_Europe_Moscow PSTR("MSK-3")
|
||||
#define TZ_Europe_Oslo PSTR("CET-1CEST,M3.5.0,M10.5.0/3")
|
||||
#define TZ_Europe_Paris PSTR("CET-1CEST,M3.5.0,M10.5.0/3")
|
||||
#define TZ_Europe_Podgorica PSTR("CET-1CEST,M3.5.0,M10.5.0/3")
|
||||
#define TZ_Europe_Prague PSTR("CET-1CEST,M3.5.0,M10.5.0/3")
|
||||
#define TZ_Europe_Riga PSTR("EET-2EEST,M3.5.0/3,M10.5.0/4")
|
||||
#define TZ_Europe_Rome PSTR("CET-1CEST,M3.5.0,M10.5.0/3")
|
||||
#define TZ_Europe_Samara PSTR("<+04>-4")
|
||||
#define TZ_Europe_San_Marino PSTR("CET-1CEST,M3.5.0,M10.5.0/3")
|
||||
#define TZ_Europe_Sarajevo PSTR("CET-1CEST,M3.5.0,M10.5.0/3")
|
||||
#define TZ_Europe_Saratov PSTR("<+04>-4")
|
||||
#define TZ_Europe_Simferopol PSTR("MSK-3")
|
||||
#define TZ_Europe_Skopje PSTR("CET-1CEST,M3.5.0,M10.5.0/3")
|
||||
#define TZ_Europe_Sofia PSTR("EET-2EEST,M3.5.0/3,M10.5.0/4")
|
||||
#define TZ_Europe_Stockholm PSTR("CET-1CEST,M3.5.0,M10.5.0/3")
|
||||
#define TZ_Europe_Tallinn PSTR("EET-2EEST,M3.5.0/3,M10.5.0/4")
|
||||
#define TZ_Europe_Tirane PSTR("CET-1CEST,M3.5.0,M10.5.0/3")
|
||||
#define TZ_Europe_Ulyanovsk PSTR("<+04>-4")
|
||||
#define TZ_Europe_Uzhgorod PSTR("EET-2EEST,M3.5.0/3,M10.5.0/4")
|
||||
#define TZ_Europe_Vaduz PSTR("CET-1CEST,M3.5.0,M10.5.0/3")
|
||||
#define TZ_Europe_Vatican PSTR("CET-1CEST,M3.5.0,M10.5.0/3")
|
||||
#define TZ_Europe_Vienna PSTR("CET-1CEST,M3.5.0,M10.5.0/3")
|
||||
#define TZ_Europe_Vilnius PSTR("EET-2EEST,M3.5.0/3,M10.5.0/4")
|
||||
#define TZ_Europe_Volgograd PSTR("<+04>-4")
|
||||
#define TZ_Europe_Warsaw PSTR("CET-1CEST,M3.5.0,M10.5.0/3")
|
||||
#define TZ_Europe_Zagreb PSTR("CET-1CEST,M3.5.0,M10.5.0/3")
|
||||
#define TZ_Europe_Zaporozhye PSTR("EET-2EEST,M3.5.0/3,M10.5.0/4")
|
||||
#define TZ_Europe_Zurich PSTR("CET-1CEST,M3.5.0,M10.5.0/3")
|
||||
#define TZ_Indian_Antananarivo PSTR("EAT-3")
|
||||
#define TZ_Indian_Chagos PSTR("<+06>-6")
|
||||
#define TZ_Indian_Christmas PSTR("<+07>-7")
|
||||
#define TZ_Indian_Cocos PSTR("<+0630>-6:30")
|
||||
#define TZ_Indian_Comoro PSTR("EAT-3")
|
||||
#define TZ_Indian_Kerguelen PSTR("<+05>-5")
|
||||
#define TZ_Indian_Mahe PSTR("<+04>-4")
|
||||
#define TZ_Indian_Maldives PSTR("<+05>-5")
|
||||
#define TZ_Indian_Mauritius PSTR("<+04>-4")
|
||||
#define TZ_Indian_Mayotte PSTR("EAT-3")
|
||||
#define TZ_Indian_Reunion PSTR("<+04>-4")
|
||||
#define TZ_Pacific_Apia PSTR("<+13>-13<+14>,M9.5.0/3,M4.1.0/4")
|
||||
#define TZ_Pacific_Auckland PSTR("NZST-12NZDT,M9.5.0,M4.1.0/3")
|
||||
#define TZ_Pacific_Bougainville PSTR("<+11>-11")
|
||||
#define TZ_Pacific_Chatham PSTR("<+1245>-12:45<+1345>,M9.5.0/2:45,M4.1.0/3:45")
|
||||
#define TZ_Pacific_Chuuk PSTR("<+10>-10")
|
||||
#define TZ_Pacific_Easter PSTR("<-06>6<-05>,M9.1.6/22,M4.1.6/22")
|
||||
#define TZ_Pacific_Efate PSTR("<+11>-11")
|
||||
#define TZ_Pacific_Enderbury PSTR("<+13>-13")
|
||||
#define TZ_Pacific_Fakaofo PSTR("<+13>-13")
|
||||
#define TZ_Pacific_Fiji PSTR("<+12>-12<+13>,M11.1.0,M1.2.2/123")
|
||||
#define TZ_Pacific_Funafuti PSTR("<+12>-12")
|
||||
#define TZ_Pacific_Galapagos PSTR("<-06>6")
|
||||
#define TZ_Pacific_Gambier PSTR("<-09>9")
|
||||
#define TZ_Pacific_Guadalcanal PSTR("<+11>-11")
|
||||
#define TZ_Pacific_Guam PSTR("ChST-10")
|
||||
#define TZ_Pacific_Honolulu PSTR("HST10")
|
||||
#define TZ_Pacific_Kiritimati PSTR("<+14>-14")
|
||||
#define TZ_Pacific_Kosrae PSTR("<+11>-11")
|
||||
#define TZ_Pacific_Kwajalein PSTR("<+12>-12")
|
||||
#define TZ_Pacific_Majuro PSTR("<+12>-12")
|
||||
#define TZ_Pacific_Marquesas PSTR("<-0930>9:30")
|
||||
#define TZ_Pacific_Midway PSTR("SST11")
|
||||
#define TZ_Pacific_Nauru PSTR("<+12>-12")
|
||||
#define TZ_Pacific_Niue PSTR("<-11>11")
|
||||
#define TZ_Pacific_Norfolk PSTR("<+11>-11")
|
||||
#define TZ_Pacific_Noumea PSTR("<+11>-11")
|
||||
#define TZ_Pacific_Pago_Pago PSTR("SST11")
|
||||
#define TZ_Pacific_Palau PSTR("<+09>-9")
|
||||
#define TZ_Pacific_Pitcairn PSTR("<-08>8")
|
||||
#define TZ_Pacific_Pohnpei PSTR("<+11>-11")
|
||||
#define TZ_Pacific_Port_Moresby PSTR("<+10>-10")
|
||||
#define TZ_Pacific_Rarotonga PSTR("<-10>10")
|
||||
#define TZ_Pacific_Saipan PSTR("ChST-10")
|
||||
#define TZ_Pacific_Tahiti PSTR("<-10>10")
|
||||
#define TZ_Pacific_Tarawa PSTR("<+12>-12")
|
||||
#define TZ_Pacific_Tongatapu PSTR("<+13>-13")
|
||||
#define TZ_Pacific_Wake PSTR("<+12>-12")
|
||||
#define TZ_Pacific_Wallis PSTR("<+12>-12")
|
||||
#define TZ_Etc_GMT PSTR("GMT0")
|
||||
#define TZ_Etc_GMTm0 PSTR("GMT0")
|
||||
#define TZ_Etc_GMTm1 PSTR("<+01>-1")
|
||||
#define TZ_Etc_GMTm2 PSTR("<+02>-2")
|
||||
#define TZ_Etc_GMTm3 PSTR("<+03>-3")
|
||||
#define TZ_Etc_GMTm4 PSTR("<+04>-4")
|
||||
#define TZ_Etc_GMTm5 PSTR("<+05>-5")
|
||||
#define TZ_Etc_GMTm6 PSTR("<+06>-6")
|
||||
#define TZ_Etc_GMTm7 PSTR("<+07>-7")
|
||||
#define TZ_Etc_GMTm8 PSTR("<+08>-8")
|
||||
#define TZ_Etc_GMTm9 PSTR("<+09>-9")
|
||||
#define TZ_Etc_GMTm10 PSTR("<+10>-10")
|
||||
#define TZ_Etc_GMTm11 PSTR("<+11>-11")
|
||||
#define TZ_Etc_GMTm12 PSTR("<+12>-12")
|
||||
#define TZ_Etc_GMTm13 PSTR("<+13>-13")
|
||||
#define TZ_Etc_GMTm14 PSTR("<+14>-14")
|
||||
#define TZ_Etc_GMT0 PSTR("GMT0")
|
||||
#define TZ_Etc_GMTp0 PSTR("GMT0")
|
||||
#define TZ_Etc_GMTp1 PSTR("<-01>1")
|
||||
#define TZ_Etc_GMTp2 PSTR("<-02>2")
|
||||
#define TZ_Etc_GMTp3 PSTR("<-03>3")
|
||||
#define TZ_Etc_GMTp4 PSTR("<-04>4")
|
||||
#define TZ_Etc_GMTp5 PSTR("<-05>5")
|
||||
#define TZ_Etc_GMTp6 PSTR("<-06>6")
|
||||
#define TZ_Etc_GMTp7 PSTR("<-07>7")
|
||||
#define TZ_Etc_GMTp8 PSTR("<-08>8")
|
||||
#define TZ_Etc_GMTp9 PSTR("<-09>9")
|
||||
#define TZ_Etc_GMTp10 PSTR("<-10>10")
|
||||
#define TZ_Etc_GMTp11 PSTR("<-11>11")
|
||||
#define TZ_Etc_GMTp12 PSTR("<-12>12")
|
||||
#define TZ_Etc_UCT PSTR("UTC0")
|
||||
#define TZ_Etc_UTC PSTR("UTC0")
|
||||
#define TZ_Etc_Greenwich PSTR("GMT0")
|
||||
#define TZ_Etc_Universal PSTR("UTC0")
|
||||
#define TZ_Etc_Zulu PSTR("UTC0")
|
||||
|
||||
#endif // TZDB_H
|
@ -16,6 +16,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/reent.h>
|
||||
@ -55,25 +56,12 @@ static void setServer(int id, const char* name_or_ip)
|
||||
{
|
||||
if (name_or_ip)
|
||||
{
|
||||
//TODO: check whether server is given by name or IP
|
||||
// per current configuration,
|
||||
// lwIP can receive an IP address or a fqdn
|
||||
sntp_setservername(id, (char*) name_or_ip);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void configTime(int timezone_sec, int daylightOffset_sec, const char* server1, const char* server2, const char* server3)
|
||||
{
|
||||
sntp_stop();
|
||||
|
||||
setServer(0, server1);
|
||||
setServer(1, server2);
|
||||
setServer(2, server3);
|
||||
|
||||
sntp_set_timezone_in_seconds(timezone_sec);
|
||||
sntp_set_daylight(daylightOffset_sec);
|
||||
sntp_init();
|
||||
}
|
||||
|
||||
int clock_gettime(clockid_t unused, struct timespec *tp)
|
||||
{
|
||||
(void) unused;
|
||||
@ -108,4 +96,33 @@ int _gettimeofday_r(struct _reent* unused, struct timeval *tp, void *tzp)
|
||||
return 0;
|
||||
}
|
||||
|
||||
};
|
||||
}; // extern "C"
|
||||
|
||||
void configTime(int timezone_sec, int daylightOffset_sec, const char* server1, const char* server2, const char* server3)
|
||||
{
|
||||
sntp_stop();
|
||||
|
||||
setServer(0, server1);
|
||||
setServer(1, server2);
|
||||
setServer(2, server3);
|
||||
|
||||
sntp_set_timezone_in_seconds(timezone_sec);
|
||||
sntp_set_daylight(daylightOffset_sec);
|
||||
sntp_init();
|
||||
}
|
||||
|
||||
void configTime(const char* tz, const char* server1, const char* server2, const char* server3)
|
||||
{
|
||||
sntp_stop();
|
||||
|
||||
setServer(0, server1);
|
||||
setServer(1, server2);
|
||||
setServer(2, server3);
|
||||
|
||||
char tzram[strlen_P(tz) + 1];
|
||||
memcpy_P(tzram, tz, sizeof(tzram));
|
||||
setenv("TZ", tzram, 1/*overwrite*/);
|
||||
tzset();
|
||||
|
||||
sntp_init();
|
||||
}
|
||||
|
@ -1,80 +1,145 @@
|
||||
/*
|
||||
NTP-TZ-DST
|
||||
NTP-TZ-DST (v2)
|
||||
NetWork Time Protocol - Time Zone - Daylight Saving Time
|
||||
|
||||
This example shows how to read and set time,
|
||||
and how to use NTP (set NTP0_OR_LOCAL1 to 0 below)
|
||||
or an external RTC (set NTP0_OR_LOCAL1 to 1 below)
|
||||
|
||||
TZ and DST below have to be manually set
|
||||
according to your local settings.
|
||||
This example shows:
|
||||
- how to read and set time
|
||||
- how to set timezone per country/city
|
||||
- how is local time automatically handled per official timezone definitions
|
||||
- how to change internal sntp start and update delay
|
||||
- how to use callbacks when time is updated
|
||||
|
||||
This example code is in the public domain.
|
||||
*/
|
||||
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <time.h> // time() ctime()
|
||||
#include <sys/time.h> // struct timeval
|
||||
#include <coredecls.h> // settimeofday_cb()
|
||||
|
||||
////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef STASSID
|
||||
#define STASSID "your-ssid"
|
||||
#define STAPSK "your-password"
|
||||
#endif
|
||||
|
||||
#define SSID STASSID
|
||||
#define SSIDPWD STAPSK
|
||||
#define TZ 1 // (utc+) TZ in hours
|
||||
#define DST_MN 60 // use 60mn for summer time in some countries
|
||||
// initial time (possibly given by an external RTC)
|
||||
#define RTC_UTC_TEST 1510592825 // 1510592825 = Monday 13 November 2017 17:07:05 UTC
|
||||
|
||||
#define NTP0_OR_LOCAL1 1 // 0:use NTP 1:fake external RTC
|
||||
#define RTC_TEST 1510592825 // 1510592825 = Monday 13 November 2017 17:07:05 UTC
|
||||
|
||||
// This database is autogenerated from IANA timezone database
|
||||
// https://www.iana.org/time-zones
|
||||
// and can be updated on demand in this repository
|
||||
#include <TZ.h>
|
||||
|
||||
// "TZ_" macros follow DST change across seasons without source code change
|
||||
// check for your nearest city in TZ.h
|
||||
|
||||
// espressif headquarter TZ
|
||||
//#define MYTZ TZ_Asia_Shanghai
|
||||
|
||||
// example for "Not Only Whole Hours" timezones:
|
||||
// Kolkata/Calcutta is shifted by 30mn
|
||||
//#define MYTZ TZ_Asia_Kolkata
|
||||
|
||||
// example of a timezone with a variable Daylight-Saving-Time:
|
||||
// demo: watch automatic time adjustment on Summer/Winter change (DST)
|
||||
#define MYTZ TZ_Europe_London
|
||||
|
||||
////////////////////////////////////////////////////////
|
||||
|
||||
#define TZ_MN ((TZ)*60)
|
||||
#define TZ_SEC ((TZ)*3600)
|
||||
#define DST_SEC ((DST_MN)*60)
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <coredecls.h> // settimeofday_cb()
|
||||
#include <Schedule.h>
|
||||
#include <PolledTimeout.h>
|
||||
|
||||
timeval cbtime; // time set in callback
|
||||
bool cbtime_set = false;
|
||||
#include <time.h> // time() ctime()
|
||||
#include <sys/time.h> // struct timeval
|
||||
|
||||
void time_is_set(void) {
|
||||
gettimeofday(&cbtime, NULL);
|
||||
cbtime_set = true;
|
||||
Serial.println("------------------ settimeofday() was called ------------------");
|
||||
}
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
settimeofday_cb(time_is_set);
|
||||
|
||||
#if NTP0_OR_LOCAL1
|
||||
// local
|
||||
|
||||
ESP.eraseConfig();
|
||||
time_t rtc = RTC_TEST;
|
||||
timeval tv = { rtc, 0 };
|
||||
timezone tz = { TZ_MN + DST_MN, 0 };
|
||||
settimeofday(&tv, &tz);
|
||||
|
||||
#else // ntp
|
||||
|
||||
configTime(TZ_SEC, DST_SEC, "pool.ntp.org");
|
||||
WiFi.mode(WIFI_STA);
|
||||
WiFi.begin(SSID, SSIDPWD);
|
||||
// don't wait, observe time changing when ntp timestamp is received
|
||||
|
||||
#endif // ntp
|
||||
}
|
||||
#if LWIP_VERSION_MAJOR == 1
|
||||
#include <lwip/sntp.h> // sntp_servermode_dhcp()
|
||||
#else
|
||||
#include <lwip/apps/sntp.h> // sntp_servermode_dhcp()
|
||||
#endif
|
||||
|
||||
// for testing purpose:
|
||||
extern "C" int clock_gettime(clockid_t unused, struct timespec *tp);
|
||||
|
||||
////////////////////////////////////////////////////////
|
||||
|
||||
static timeval tv;
|
||||
static timespec tp;
|
||||
static time_t now;
|
||||
static uint32_t now_ms, now_us;
|
||||
|
||||
static esp8266::polledTimeout::periodicMs showTimeNow(60000);
|
||||
static int time_machine_days = 0; // 0 = now
|
||||
static bool time_machine_running = false;
|
||||
|
||||
// OPTIONAL: change SNTP startup delay
|
||||
// a weak function is already defined and returns 0 (RFC violation)
|
||||
// it can be redefined:
|
||||
//uint32_t sntp_startup_delay_MS_rfc_not_less_than_60000 ()
|
||||
//{
|
||||
// //info_sntp_startup_delay_MS_rfc_not_less_than_60000_has_been_called = true;
|
||||
// return 60000; // 60s (or lwIP's original default: (random() % 5000))
|
||||
//}
|
||||
|
||||
// OPTIONAL: change SNTP update delay
|
||||
// a weak function is already defined and returns 1 hour
|
||||
// it can be redefined:
|
||||
//uint32_t sntp_update_delay_MS_rfc_not_less_than_15000 ()
|
||||
//{
|
||||
// //info_sntp_update_delay_MS_rfc_not_less_than_15000_has_been_called = true;
|
||||
// return 15000; // 15s
|
||||
//}
|
||||
|
||||
|
||||
void showTime() {
|
||||
gettimeofday(&tv, nullptr);
|
||||
clock_gettime(0, &tp);
|
||||
now = time(nullptr);
|
||||
now_ms = millis();
|
||||
now_us = micros();
|
||||
|
||||
Serial.println();
|
||||
printTm("localtime:", localtime(&now));
|
||||
Serial.println();
|
||||
printTm("gmtime: ", gmtime(&now));
|
||||
Serial.println();
|
||||
|
||||
// time from boot
|
||||
Serial.print("clock: ");
|
||||
Serial.print((uint32_t)tp.tv_sec);
|
||||
Serial.print("s / ");
|
||||
Serial.print((uint32_t)tp.tv_nsec);
|
||||
Serial.println("ns");
|
||||
|
||||
// time from boot
|
||||
Serial.print("millis: ");
|
||||
Serial.println(now_ms);
|
||||
Serial.print("micros: ");
|
||||
Serial.println(now_us);
|
||||
|
||||
// EPOCH+tz+dst
|
||||
Serial.print("gtod: ");
|
||||
Serial.print((uint32_t)tv.tv_sec);
|
||||
Serial.print("s / ");
|
||||
Serial.print((uint32_t)tv.tv_usec);
|
||||
Serial.println("us");
|
||||
|
||||
// EPOCH+tz+dst
|
||||
Serial.print("time: ");
|
||||
Serial.println((uint32_t)now);
|
||||
|
||||
// timezone and demo in the future
|
||||
Serial.printf("timezone: %s\n", MYTZ);
|
||||
|
||||
// human readable
|
||||
Serial.print("ctime: ");
|
||||
Serial.print(ctime(&now));
|
||||
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
|
||||
#define PTM(w) \
|
||||
Serial.print(":" #w "="); \
|
||||
Serial.print(" " #w "="); \
|
||||
Serial.print(tm->tm_##w);
|
||||
|
||||
void printTm(const char* what, const tm* tm) {
|
||||
@ -84,61 +149,83 @@ void printTm(const char* what, const tm* tm) {
|
||||
PTM(hour); PTM(min); PTM(sec);
|
||||
}
|
||||
|
||||
timeval tv;
|
||||
timespec tp;
|
||||
time_t now;
|
||||
uint32_t now_ms, now_us;
|
||||
void time_is_set_scheduled() {
|
||||
// everything is allowed in this function
|
||||
|
||||
// time machine demo
|
||||
if (time_machine_running) {
|
||||
if (time_machine_days == 0)
|
||||
Serial.printf("---- settimeofday() has been called - possibly from SNTP\n"
|
||||
" (starting time machine demo to show libc's automatic DST handling)\n\n");
|
||||
now = time(nullptr);
|
||||
const tm* tm = localtime(&now);
|
||||
Serial.printf("future=%3ddays: DST=%s - ",
|
||||
time_machine_days,
|
||||
tm->tm_isdst ? "true " : "false");
|
||||
Serial.print(ctime(&now));
|
||||
gettimeofday(&tv, nullptr);
|
||||
constexpr int days = 30;
|
||||
time_machine_days += days;
|
||||
if (time_machine_days > 360) {
|
||||
tv.tv_sec -= (time_machine_days - days) * 60 * 60 * 24;
|
||||
time_machine_days = 0;
|
||||
} else {
|
||||
tv.tv_sec += days * 60 * 60 * 24;
|
||||
}
|
||||
settimeofday(&tv, nullptr);
|
||||
} else {
|
||||
showTime();
|
||||
}
|
||||
}
|
||||
|
||||
void time_is_set_callback() {
|
||||
// As in an ISR,
|
||||
// it is not allowed to call "heavy" core API
|
||||
// like yield()/delay()/print()/network/...
|
||||
// If this is needed, use a scheduled function.
|
||||
|
||||
// This scheduled function is used for the demo, it is normaly unneeded
|
||||
schedule_function(time_is_set_scheduled);
|
||||
if (time_machine_days == 0) {
|
||||
time_machine_running = !time_machine_running;
|
||||
}
|
||||
}
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
Serial.println("\nStarting...\n");
|
||||
|
||||
// setup RTC time
|
||||
// it will be used until NTP server will send us real current time
|
||||
time_t rtc = RTC_UTC_TEST;
|
||||
timeval tv = { rtc, 0 };
|
||||
timezone tz = { 0, 0 };
|
||||
settimeofday(&tv, &tz);
|
||||
|
||||
// install callback - called when settimeofday is called (by SNTP or us)
|
||||
// once enabled (by DHCP), SNTP is updated every hour
|
||||
settimeofday_cb(time_is_set_callback);
|
||||
|
||||
// NTP servers may be overriden by your DHCP server for a more local one
|
||||
// (see below)
|
||||
configTime(MYTZ, "pool.ntp.org");
|
||||
|
||||
// OPTIONAL: disable obtaining SNTP servers from DHCP
|
||||
//sntp_servermode_dhcp(0); // 0: disable obtaining SNTP servers from DHCP (enabled by default)
|
||||
|
||||
// start network
|
||||
WiFi.persistent(false);
|
||||
WiFi.mode(WIFI_STA);
|
||||
WiFi.begin(STASSID, STAPSK);
|
||||
|
||||
// don't wait for network, observe time changing
|
||||
// when NTP timestamp is received
|
||||
Serial.printf("Time is currently set by a constant:\n");
|
||||
showTime();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
gettimeofday(&tv, nullptr);
|
||||
clock_gettime(0, &tp);
|
||||
now = time(nullptr);
|
||||
now_ms = millis();
|
||||
now_us = micros();
|
||||
|
||||
// localtime / gmtime every second change
|
||||
static time_t lastv = 0;
|
||||
if (lastv != tv.tv_sec) {
|
||||
lastv = tv.tv_sec;
|
||||
Serial.println();
|
||||
printTm("localtime", localtime(&now));
|
||||
Serial.println();
|
||||
printTm("gmtime ", gmtime(&now));
|
||||
Serial.println();
|
||||
Serial.println();
|
||||
if (showTimeNow) {
|
||||
showTime();
|
||||
}
|
||||
|
||||
// time from boot
|
||||
Serial.print("clock:");
|
||||
Serial.print((uint32_t)tp.tv_sec);
|
||||
Serial.print("/");
|
||||
Serial.print((uint32_t)tp.tv_nsec);
|
||||
Serial.print("ns");
|
||||
|
||||
// time from boot
|
||||
Serial.print(" millis:");
|
||||
Serial.print(now_ms);
|
||||
Serial.print(" micros:");
|
||||
Serial.print(now_us);
|
||||
|
||||
// EPOCH+tz+dst
|
||||
Serial.print(" gtod:");
|
||||
Serial.print((uint32_t)tv.tv_sec);
|
||||
Serial.print("/");
|
||||
Serial.print((uint32_t)tv.tv_usec);
|
||||
Serial.print("us");
|
||||
|
||||
// EPOCH+tz+dst
|
||||
Serial.print(" time:");
|
||||
Serial.print((uint32_t)now);
|
||||
|
||||
// human readable
|
||||
Serial.print(" ctime:(UTC+");
|
||||
Serial.print((uint32_t)(TZ * 60 + DST_MN));
|
||||
Serial.print("mn)");
|
||||
Serial.print(ctime(&now));
|
||||
|
||||
// simple drifting loop
|
||||
delay(100);
|
||||
}
|
||||
|
@ -107,18 +107,23 @@ Here is an overview of the release process. See the section below for detailed i
|
||||
|
||||
The following points assume work in a direct clone of the repository, and not in a personal fork.
|
||||
|
||||
2. Update `version` to the release in platform.txt and commit. E.g. `2.5.0`. Make a PR, wait for Travis CI, and merge.
|
||||
2. Make a PR with the following, wait for Travis CI, and merge.
|
||||
|
||||
3. Tag the latest commit on the master branch. In this project, tags have form `X.Y.Z`, e.g. `2.4.0`, or `X.Y.Z-betaN` for release candiate versions. Notice that there's no `v`at the beginning of the tag. Tags must be annotated, not lightweight tags. To create a tag, use git command (assuming that the master branch is checked out):
|
||||
* platform.txt: update `version` to the release E.g. `3.0.0`,
|
||||
|
||||
* `cores/esp8266/TZ.h`: import the latest database with the following shell command:\
|
||||
`$ cd tools; sh TZupdate.sh`.
|
||||
|
||||
3. Tag the latest commit on the master branch. In this project, tags have form `X.Y.Z`, e.g. `3.0.0`, or `X.Y.Z-betaN` for release candiate versions. Notice that there's no `v`at the beginning of the tag. Tags must be annotated, not lightweight tags. To create a tag, use git command (assuming that the master branch is checked out):
|
||||
|
||||
```
|
||||
git tag -a -m "Release 2.5.0" 2.5.0
|
||||
git tag -a -m "Release 3.0.0" 3.0.0
|
||||
```
|
||||
|
||||
then push the tag created in step 3 to esp8266/Arduino Github repository:
|
||||
|
||||
```
|
||||
git push origin 2.5.0
|
||||
git push origin 3.0.0
|
||||
```
|
||||
|
||||
4. In case something goes wrong, release can be canceled at any time:
|
||||
@ -141,7 +146,7 @@ The following points assume work in a direct clone of the repository, and not in
|
||||
|
||||
11. Create a commit to the master branch, updating:
|
||||
|
||||
* The version in platform.txt file. This should correspond to the version of the *next* milestone, plus `-dev` suffix. E.g. `2.5.0-dev`.
|
||||
* The version in platform.txt file. This should correspond to the version of the *next* milestone, plus `-dev` suffix. E.g. `3.1.0-dev`.
|
||||
|
||||
* In main README.md:
|
||||
|
||||
|
71
tools/TZupdate.sh
Executable file
71
tools/TZupdate.sh
Executable file
@ -0,0 +1,71 @@
|
||||
#!/bin/sh
|
||||
|
||||
# this shell script refreshes world timezone definitions in
|
||||
# cores/esp8266/TZ.h
|
||||
#
|
||||
# to run it, use:
|
||||
# /path/to/TZupdate.sh
|
||||
# tools/TZupdate.sh
|
||||
# ./TZupdate.sh
|
||||
|
||||
dir=$(cd ${0%/*} 2>/dev/null; pwd)
|
||||
base=${0##*/}
|
||||
|
||||
csv=https://raw.githubusercontent.com/nayarsystems/posix_tz_db/master/zones.csv
|
||||
|
||||
set -e
|
||||
|
||||
tz_tmpdir=$(mktemp -d)
|
||||
trap 'rm -r $tz_tmpdir' EXIT
|
||||
|
||||
input=$tz_tmpdir/zones.csv
|
||||
names=$tz_tmpdir/names.txt
|
||||
values=$tz_tmpdir/values.txt
|
||||
|
||||
wget -O $input $csv || curl $csv > $input
|
||||
|
||||
sed -e 's/^[^,]*,//g' -e 's,^,PSTR(,g' -e 's,$,),g' < $input > $values
|
||||
sed -e 's/^\([^,]*\),.*/#define TZ_\1/g' -e 's,["],,g' < $input | tr '/\-+' '_mp' > $names
|
||||
|
||||
(
|
||||
|
||||
cat << EOF
|
||||
|
||||
// autogenerated from $csv
|
||||
// by script <esp8266 arduino core>/tools/${base}
|
||||
// $(date -u)
|
||||
//
|
||||
// This database is autogenerated from IANA timezone database
|
||||
// https://www.iana.org/time-zones
|
||||
// and can be updated on demand in this repository
|
||||
// or by yourself using the above script
|
||||
|
||||
#ifndef TZDB_H
|
||||
#define TZDB_H
|
||||
|
||||
EOF
|
||||
|
||||
paste $names $values
|
||||
|
||||
cat << EOF
|
||||
|
||||
#endif // TZDB_H
|
||||
EOF
|
||||
|
||||
) > $tz_tmpdir/TZ.h
|
||||
|
||||
backup=$(date +%s)
|
||||
mv ${dir}/../cores/esp8266/TZ.h ${dir}/../cores/esp8266/TZ.h.$backup
|
||||
mv $tz_tmpdir/TZ.h ${dir}/../cores/esp8266/TZ.h
|
||||
|
||||
cat << EOF
|
||||
|
||||
Done:
|
||||
'${dir}/../cores/esp8266/TZ.h' is updated
|
||||
|
||||
Diff:
|
||||
----8<-------8<------8<---
|
||||
$(diff -u ${dir}/../cores/esp8266/TZ.h.$backup ${dir}/../cores/esp8266/TZ.h)
|
||||
--->8----->8------>8------
|
||||
|
||||
EOF
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1 +1 @@
|
||||
Subproject commit ffa962483cc1c5d874b11bec13080359619c4cb2
|
||||
Subproject commit 354887a25f83064dc0c795e11704190845812713
|
@ -8,3 +8,4 @@ typedef unsigned long u32_t;
|
||||
typedef signed long s32_t;
|
||||
typedef unsigned long mem_ptr_t;
|
||||
#define LWIP_ERR_T s32_t
|
||||
typedef uint32_t sys_prot_t;
|
||||
|
@ -1,5 +1,5 @@
|
||||
// generated by makefiles/make-lwip2-hash
|
||||
#ifndef LWIP_HASH_H
|
||||
#define LWIP_HASH_H
|
||||
#define LWIP_HASH_STR "STABLE-2_1_2_RELEASE/glue:1.2-8-g7958710"
|
||||
#define LWIP_HASH_STR "STABLE-2_1_2_RELEASE/glue:1.2-16-ge23a07e"
|
||||
#endif // LWIP_HASH_H
|
||||
|
@ -1,3 +1,40 @@
|
||||
/**
|
||||
* @file
|
||||
* Network Address and Port Translation
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2016-2019 NeoCat <neocat@neocat.jp>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
|
||||
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
||||
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
|
||||
* OF SUCH DAMAGE.
|
||||
*
|
||||
* This file is part of the lwIP TCP/IP stack.
|
||||
*
|
||||
* Author: NeoCat <neocat@neocat.jp>
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef __LWIP_NAPT_H__
|
||||
#define __LWIP_NAPT_H__
|
||||
|
||||
|
@ -3545,6 +3545,9 @@
|
||||
#error LWIP_FEATURES must be defined
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* TCP_RANDOM_PORT: randomize port instead of simply increasing
|
||||
@ -3567,21 +3570,28 @@
|
||||
|
||||
#define SNTP_SET_SYSTEM_TIME_US(t,us) do { struct timeval tv = { t, us }; settimeofday(&tv, NULL); } while (0)
|
||||
|
||||
#define SNTP_SUPPRESS_DELAY_CHECK 1
|
||||
#define SNTP_UPDATE_DELAY_DEFAULT 3600000 // update delay defined by a default weak function
|
||||
#define SNTP_UPDATE_DELAY sntp_update_delay_MS_rfc_not_less_than_15000()
|
||||
extern uint32_t SNTP_UPDATE_DELAY;
|
||||
|
||||
#if LWIP_FEATURES
|
||||
// lwip-1.4 had 3 possible SNTP servers (constant was harcoded)
|
||||
// esp8266/arduino/lwip-1.4 had 3 possible SNTP servers (constant was harcoded)
|
||||
#define SNTP_MAX_SERVERS 3
|
||||
#endif
|
||||
|
||||
// turn off random delay before sntp request
|
||||
// when SNTP_STARTUP_DELAY is not defined,
|
||||
// LWIP_RAND is used to set a delay
|
||||
// no delay by default before sntp request
|
||||
// https://github.com/esp8266/Arduino/pull/5564
|
||||
// from sntp_opts.h:
|
||||
/** According to the RFC, this shall be a random delay
|
||||
* between 1 and 5 minutes (in milliseconds) to prevent load peaks.
|
||||
* This can be defined to a random generation function,
|
||||
* which must return the delay in milliseconds as u32_t.
|
||||
*/
|
||||
#define SNTP_STARTUP_DELAY 0
|
||||
#define SNTP_STARTUP_DELAY 1 // enable startup delay
|
||||
#define SNTP_STARTUP_DELAY_FUNC_DEFAULT 0 // to 0 by default via a default weak function
|
||||
#define SNTP_STARTUP_DELAY_FUNC sntp_startup_delay_MS_rfc_not_less_than_60000()
|
||||
extern uint32_t SNTP_STARTUP_DELAY_FUNC;
|
||||
|
||||
/*
|
||||
--------------------------------------------------
|
||||
@ -3633,4 +3643,8 @@ void tcp_kill_timewait (void);
|
||||
#define MEMP_NUM_TCP_PCB_TIME_WAIT 5
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
#endif
|
||||
|
||||
#endif // MYLWIPOPTS_H
|
||||
|
Loading…
x
Reference in New Issue
Block a user