diff options
author | Anton L. Šijanec <sijanecantonluka@gmail.com> | 2020-04-16 21:37:16 +0200 |
---|---|---|
committer | Anton L. Šijanec <sijanecantonluka@gmail.com> | 2020-04-16 21:37:16 +0200 |
commit | d8e4a5b71da218293214acc9c9b6be2ccb095271 (patch) | |
tree | 348d29f793c8774c2438d58d28b360452f624023 /f010_raznefunkcije.ino | |
parent | updejtttttt (diff) | |
download | sijaneciot-master.tar sijaneciot-master.tar.gz sijaneciot-master.tar.bz2 sijaneciot-master.tar.lz sijaneciot-master.tar.xz sijaneciot-master.tar.zst sijaneciot-master.zip |
Diffstat (limited to 'f010_raznefunkcije.ino')
-rw-r--r-- | f010_raznefunkcije.ino | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/f010_raznefunkcije.ino b/f010_raznefunkcije.ino index 9613049..b940625 100644 --- a/f010_raznefunkcije.ino +++ b/f010_raznefunkcije.ino @@ -71,6 +71,7 @@ String getContentType(String filename) { // convert the file extension to the MI else if (filename.endsWith(".gz")) return "application/x-gzip"; else if (filename.endsWith(".xml")) return "text/xml"; else if (filename.endsWith(".svg")) return "text/svg+xml"; + else if (filename.endsWith(".csv")) return "text/csv"; return "application/octet-stream"; } @@ -109,6 +110,60 @@ String fihr(int code, String text) { // format inline html response const int NTP_PACKET_SIZE = 48; // NTP time is in the first 48 bytes of message byte packetBuffer[NTP_PACKET_SIZE]; //buffer to hold incoming & outgoing packets +time_t getHttpTime() { + const char * headerKeys[] = {"date"} ; + const size_t numberOfHeaders = 1; + HTTPClient http; + http.begin("http://razor.arnes.si/.well-known/time"); + http.collectHeaders(headerKeys, numberOfHeaders); + int httpCode = http.GET(); + String headerDate; + if (httpCode > 0) { + for(int i = 0; i< http.headers(); i++){ + Serial.println(http.header(i)); + } + headerDate = http.header("date"); + + } else { + if(razhroscevanje) Serial.println("unable to get http time"); + return 0; + } + http.end(); + // string, delimeter, array, length + String locenoSPresledki[5]; + String locenoZDvopicjem[3]; + explode(headerDate, " ", locenoSPresledki, 5); + int dan = locenoSPresledki[1].toInt(); + String mesc = locenoSPresledki[2]; + int leto = locenoSPresledki[3].toInt(); + explode(locenoSPresledki[4], ":", locenoZDvopicjem, 3); + int ura = locenoZDvopicjem[0].toInt(); + int minuta = locenoZDvopicjem[1].toInt(); + int sekund = locenoZDvopicjem[2].toInt(); + int mesec; + if(mesc == "Jan") mesec=1; + else if(mesc == "Feb") mesec=2; + else if(mesc == "Mar") mesec=3; + else if(mesc == "Apr") mesec=4; + else if(mesc == "May") mesec=5; + else if(mesc == "Jun") mesec=6; + else if(mesc == "Jul") mesec=7; + else if(mesc == "Aug") mesec=8; + else if(mesc == "Sep") mesec=9; + else if(mesc == "Oct") mesec=10; + else if(mesc == "Nov") mesec=11; + else if(mesc == "Dec") mesec=12; + tmElements_t tm; + tm.Hour = ura; + tm.Minute = minuta; + tm.Second = sekund; + tm.Day = dan; + tm.Month = mesec; + tm.Year = leto-1970; + if(razhroscevanje) Serial.println("httpUpdate ("+mesc+","+mesec+"): "+String(makeTime(tm))); + return makeTime(tm); +} + time_t getNtpTime() { IPAddress ntpServerIP; // NTP server's ip address @@ -162,3 +217,7 @@ void sendNTPpacket(IPAddress &address) Udp.write(packetBuffer, NTP_PACKET_SIZE); Udp.endPacket(); } + +time_t timeSyncProvider() { + return getHttpTime(); +} |