-
Notifications
You must be signed in to change notification settings - Fork 424
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #69 from omersiar/dev
Hot fix #68
- Loading branch information
Showing
48 changed files
with
1,069 additions
and
971 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
src/websrc/3rdparty/* linguist-vendored | ||
src/webh/* linguist-vendored |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
/* | ||
* ntp.cpp | ||
* | ||
* Created on: 8 Mar 2016 | ||
* Author: joe | ||
*/ | ||
|
||
#include "Ntp.h" | ||
#include <ESPAsyncUDP.h> | ||
|
||
char * NtpClient::TimeServerName; | ||
int8_t NtpClient::timezone; | ||
time_t NtpClient::syncInterval; | ||
IPAddress NtpClient::timeServer; | ||
|
||
AsyncUDP NtpClient::udpListener; | ||
|
||
byte NtpClient::NTPpacket[NTP_PACKET_SIZE]; | ||
|
||
void ICACHE_FLASH_ATTR NtpClient::Ntp(const char * server, int8_t tz, time_t syncSecs) { | ||
TimeServerName = strdup(server); | ||
timezone = tz; | ||
syncInterval = syncSecs; | ||
setSyncProvider(getNtpTime); | ||
setSyncInterval(syncInterval); | ||
} | ||
|
||
|
||
ICACHE_FLASH_ATTR NtpClient::~NtpClient() { | ||
udpListener.close(); | ||
} | ||
|
||
// send an NTP request to the time server at the given address | ||
time_t ICACHE_FLASH_ATTR NtpClient::getNtpTime() { | ||
memset(NTPpacket, 0, sizeof(NTPpacket)); | ||
NTPpacket[0]=0b11100011; | ||
NTPpacket[1]=0; | ||
NTPpacket[2]=6; | ||
NTPpacket[3]=0xEC; | ||
NTPpacket[12]=49; | ||
NTPpacket[13]=0x4E; | ||
NTPpacket[14]=49; | ||
NTPpacket[15]=52; | ||
WiFi.hostByName(TimeServerName,timeServer); | ||
if(udpListener.connect(timeServer, 123)) { | ||
udpListener.onPacket([](AsyncUDPPacket packet) { | ||
unsigned long highWord = word(packet.data()[40], packet.data()[41]); | ||
unsigned long lowWord = word(packet.data()[42], packet.data()[43]); | ||
time_t UnixUTCtime = (highWord << 16 | lowWord)-2208988800UL; | ||
setTime(UnixUTCtime); | ||
}); | ||
} | ||
else { | ||
|
||
} | ||
udpListener.write(NTPpacket, sizeof(NTPpacket)); | ||
// ugly | ||
return 0; | ||
} | ||
|
||
bool ICACHE_FLASH_ATTR NtpClient::processTime() { | ||
|
||
timeStatus_t ts = timeStatus(); | ||
|
||
switch (ts) { | ||
case timeNeedsSync: | ||
case timeSet: | ||
return true; | ||
default: | ||
//sync | ||
now(); | ||
return false; | ||
} | ||
} | ||
|
||
String ICACHE_FLASH_ATTR NtpClient::zeroPaddedIntVal(int val) { | ||
if (val < 10) | ||
return "0" + String(val); | ||
else | ||
return String(val); | ||
} | ||
|
||
//returns the current date/time as a string in iso8601 format | ||
String ICACHE_FLASH_ATTR NtpClient::iso8601DateTime() { | ||
|
||
String hyphen = "-"; | ||
String colon = ":"; | ||
|
||
return String(year()) + hyphen + | ||
zeroPaddedIntVal(month()) + hyphen + | ||
zeroPaddedIntVal(day()) + "T" + | ||
zeroPaddedIntVal(hour()) + colon + | ||
zeroPaddedIntVal(minute()) + colon + | ||
zeroPaddedIntVal(second()) + | ||
(timezone == 0 ? "Z" : String(timezone)); | ||
} | ||
|
||
time_t NtpClient::getUptimeSec() { | ||
_uptimesec = _uptimesec + (millis () - _uptimesec); | ||
return _uptimesec / 1000; | ||
} | ||
|
||
deviceUptime ICACHE_FLASH_ATTR NtpClient::getDeviceUptime() { | ||
|
||
unsigned long currentmillis = millis(); | ||
|
||
deviceUptime uptime; | ||
uptime.secs = (long)((currentmillis / 1000) % 60); | ||
uptime.mins = (long)((currentmillis / 60000) % 60); | ||
uptime.hours = (long)((currentmillis / 3600000) % 24); | ||
uptime.days = (long)((currentmillis / 86400000) % 10); | ||
|
||
return uptime; | ||
|
||
} | ||
|
||
String ICACHE_FLASH_ATTR NtpClient::getDeviceUptimeString() { | ||
|
||
deviceUptime uptime = getDeviceUptime(); | ||
|
||
return String(uptime.days) + " days, " + | ||
String(uptime.hours) + " hours, " + | ||
String(uptime.mins) + " mins, " + | ||
String(uptime.secs) + " secs"; | ||
|
||
} | ||
|
||
/* | ||
* returns the current time as UTC (timezone offset removed) | ||
*/ | ||
ICACHE_FLASH_ATTR time_t NtpClient::getUtcTimeNow() { | ||
|
||
return now() - timezone; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* ntp.h | ||
* | ||
* Created on: 8 Mar 2016 | ||
* Author: joe | ||
*/ | ||
|
||
#ifndef NTP_H_ | ||
#define NTP_H_ | ||
|
||
#include <ESP8266WiFi.h> | ||
#include <ESPAsyncUDP.h> | ||
#include <TimeLib.h> | ||
|
||
#define NTP_PACKET_SIZE 48 // NTP time is in the first 48 bytes of message | ||
|
||
struct deviceUptime { | ||
long days; | ||
long hours; | ||
long mins; | ||
long secs; | ||
}; | ||
|
||
class NtpClient { | ||
public: | ||
|
||
void ICACHE_FLASH_ATTR Ntp(const char * server, int8_t tz, time_t syncSecs); | ||
ICACHE_FLASH_ATTR virtual ~NtpClient(); | ||
|
||
static char * TimeServerName; | ||
static IPAddress timeServer; | ||
static int8_t timezone; | ||
static time_t syncInterval; | ||
|
||
static AsyncUDP udpListener; | ||
|
||
static byte NTPpacket[NTP_PACKET_SIZE]; | ||
|
||
static ICACHE_FLASH_ATTR String iso8601DateTime(); | ||
static ICACHE_FLASH_ATTR deviceUptime getDeviceUptime(); | ||
static ICACHE_FLASH_ATTR String getDeviceUptimeString(); | ||
static ICACHE_FLASH_ATTR time_t getUtcTimeNow(); | ||
bool ICACHE_FLASH_ATTR processTime(); | ||
time_t getUptimeSec(); | ||
|
||
private: | ||
static ICACHE_FLASH_ATTR String zeroPaddedIntVal(int val); | ||
static ICACHE_FLASH_ATTR time_t getNtpTime(); | ||
|
||
protected: | ||
time_t _uptimesec = 0; | ||
}; | ||
|
||
#endif /* NTP_H_ */ |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.