Added homeSpan.setTimeServerTimeout(uint32_t tSec);

Sets timeout when connecting to Time Server (default is 10 seconds if not specified)
This commit is contained in:
Gregg 2022-03-05 20:35:01 -06:00
parent 2787966c48
commit e3b9ed99cb
3 changed files with 7 additions and 3 deletions

View File

@ -1945,16 +1945,16 @@ void SpanWebLog::initTime(){
if(!timeServer) if(!timeServer)
return; return;
Serial.printf("Acquiring Time from %s (%s)... ",timeServer,timeZone); Serial.printf("Acquiring Time from %s (%s). Waiting %d second(s) for response... ",timeServer,timeZone,waitTime/1000);
configTzTime(timeZone,timeServer); configTzTime(timeZone,timeServer);
struct tm timeinfo; struct tm timeinfo;
if(getLocalTime(&timeinfo,10000)){ if(getLocalTime(&timeinfo,waitTime)){
strftime(bootTime,sizeof(bootTime),"%c",&timeinfo); strftime(bootTime,sizeof(bootTime),"%c",&timeinfo);
Serial.printf("%s\n\n",bootTime); Serial.printf("%s\n\n",bootTime);
homeSpan.reserveSocketConnections(1); homeSpan.reserveSocketConnections(1);
timeInit=true; timeInit=true;
} else { } else {
Serial.printf("Can't access Time Server (or Time Zone improperly specified) - time-keeping not initialized!\n\n"); Serial.printf("Can't access Time Server - time-keeping not initialized!\n\n");
} }
} }

View File

@ -104,6 +104,7 @@ struct SpanWebLog{ // optional web status/log data
boolean timeInit=false; // flag to indicate time has been initialized boolean timeInit=false; // flag to indicate time has been initialized
char bootTime[33]="Unknown"; // boot time char bootTime[33]="Unknown"; // boot time
String statusURL; // URL of status log String statusURL; // URL of status log
uint32_t waitTime=10000; // number of milliseconds to wait for initial connection to time server
struct log_t { // log entry type struct log_t { // log entry type
uint64_t upTime; // number of seconds since booting uint64_t upTime; // number of seconds since booting
@ -228,6 +229,8 @@ struct Span{
void enableWebLog(uint16_t maxEntries=0, const char *serv=NULL, const char *tz="UTC", const char *url=DEFAULT_WEBLOG_URL){ // enable Web Logging void enableWebLog(uint16_t maxEntries=0, const char *serv=NULL, const char *tz="UTC", const char *url=DEFAULT_WEBLOG_URL){ // enable Web Logging
webLog.init(maxEntries, serv, tz, url); webLog.init(maxEntries, serv, tz, url);
} }
void setTimeServerTimeout(uint32_t tSec){webLog.waitTime=tSec*1000;} // sets wait time (in seconds) for optional web log time server to connect
[[deprecated("Please use reserveSocketConnections(n) method instead.")]] [[deprecated("Please use reserveSocketConnections(n) method instead.")]]
void setMaxConnections(uint8_t n){requestedMaxCon=n;} // sets maximum number of simultaneous HAP connections void setMaxConnections(uint8_t n){requestedMaxCon=n;} // sets maximum number of simultaneous HAP connections

View File

@ -100,6 +100,7 @@
#define LOG1(x) if(homeSpan.logLevel>0)Serial.print(x) #define LOG1(x) if(homeSpan.logLevel>0)Serial.print(x)
#define LOG2(x) if(homeSpan.logLevel>1)Serial.print(x) #define LOG2(x) if(homeSpan.logLevel>1)Serial.print(x)
#define WEBLOG(format,...) homeSpan.webLog.addLog(format __VA_OPT__(,) __VA_ARGS__) #define WEBLOG(format,...) homeSpan.webLog.addLog(format __VA_OPT__(,) __VA_ARGS__)
////////////////////////////////////////////////////// //////////////////////////////////////////////////////