-
Notifications
You must be signed in to change notification settings - Fork 20
/
ntptask.ino
47 lines (34 loc) · 1.68 KB
/
ntptask.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
void ntpTask( void * pvParameters )
{
const char * NTPpool = "pool.ntp.org";
const char * defaultTimezone = "CET-1CEST,M3.5.0/2,M10.5.0/3";
static char NTPpoolAdress[20];
if ( COUNTRY_CODE_ISO_3166 )
snprintf( NTPpoolAdress, sizeof( NTPpoolAdress ), "%s.%s", COUNTRY_CODE_ISO_3166, NTPpool );
else
snprintf( NTPpoolAdress, sizeof( NTPpoolAdress ), "0.%s", NTPpool );
configTzTime( preferences.getString( "timezone", defaultTimezone ).c_str(), NTPpoolAdress );
struct tm timeinfo = {0};
while ( !getLocalTime( &timeinfo, 0 ) )
vTaskDelay( 10 / portTICK_PERIOD_MS );
gettimeofday( &systemStart, NULL );
/* save reset reason */
if ( preferences.getString("bootlog").equalsIgnoreCase("on") ) {
char content[60];
snprintf( content, sizeof( content ), " %s,%s", resetString( 0 ), resetString( 1 ) );
logger.appendToFile( "/reset_reasons.txt", HUMAN_TIME, content );
}
ESP_LOGI( TAG, "NTP sync from '%s'", NTPpoolAdress );
/* start time dependent tasks */
logger.startSensors( NUMBER_OF_SENSORS, ONEWIRE_PIN, HWTIMER0_SENSOR );
BaseType_t xReturned;
xReturned = xTaskCreatePinnedToCore(
dimmerTask, /* Function to implement the task */
"dimmerTask", /* Name of the task */
3000, /* Stack size in words */
NULL, /* Task input parameter */
dimmerTaskPriority, /* Priority of the task */
&xDimmerTaskHandle, /* Task handle. */
1); /* Core where the task should run */
vTaskDelete( NULL );
}