diff --git a/HTML/application.html b/HTML/application.html index 19e89c8..9438df1 100644 --- a/HTML/application.html +++ b/HTML/application.html @@ -29,6 +29,7 @@ timarr = [ ~crontmr(15)~ ]; function showcronerr(err) {if(err != "") alert(err);} +function dbgtmr(){PostData("tmrdbg=1", "application.html", false, false, false);}
@@ -45,6 +46,7 @@ function showcronerr(err) {if(err != "") alert(err);} + diff --git a/components/webguiapp b/components/webguiapp index 37d4106..4c2dd92 160000 --- a/components/webguiapp +++ b/components/webguiapp @@ -1 +1 @@ -Subproject commit 37d410623cc54b37fc94f5d33dd5e9d660ed5f95 +Subproject commit 4c2dd92bd130859ce3deabd0b9e361b1d603ed73 diff --git a/main/include/CronTimers.h b/main/include/CronTimers.h index ced2364..6f80e62 100644 --- a/main/include/CronTimers.h +++ b/main/include/CronTimers.h @@ -29,5 +29,6 @@ esp_err_t InitCronSheduler(); esp_err_t ReloadCronSheduler(); char* GetCronError(); +void DebugTimer(); #endif /* MAIN_INCLUDE_CRONTIMERS_H_ */ diff --git a/main/main.c b/main/main.c index 340a6fe..163c5f7 100644 --- a/main/main.c +++ b/main/main.c @@ -10,6 +10,8 @@ int HTTPPrintCustom(httpd_req_t *req, char *buf, char *var, int arg); HTTP_IO_RESULT AfterPostHandlerCustom(httpd_req_t *req, const char *filename, char *PostData); void UserMQTTEventHndlr(int idx, void *handler_args, esp_event_base_t base, int32_t event_id, void *event_data); +void TimeObtainHandler(struct timeval* tm); + const char my_context_data[] = "MyContextDataPassedIntoMQTTHandler"; @@ -18,6 +20,8 @@ void app_main(void) regHTTPPrintCustom(&HTTPPrintCustom); regAfterPostHandlerCustom(&AfterPostHandlerCustom); regUserEventHandler(&UserMQTTEventHndlr, (void*)my_context_data); + regTimeSyncCallback(&TimeObtainHandler); + WebGuiAppInit(); if (GetUserAppNeedReset()) { @@ -26,8 +30,6 @@ void app_main(void) } ESP_ERROR_CHECK(InitAppConfig()); - InitCronSheduler(); - ReloadCronSheduler(); while (true) { diff --git a/main/src/CronTimers.c b/main/src/CronTimers.c index dd429f8..5c34aea 100644 --- a/main/src/CronTimers.c +++ b/main/src/CronTimers.c @@ -39,7 +39,9 @@ void custom_cron_job_callback(cron_job *job) int obj = ((cron_timer_t*) job->data)->obj; char *name = ((cron_timer_t*) job->data)->name; //here call all timers jobs depends on object and action - ESP_LOGI(TAG, "Executed timer '%s' action %d under object %d", name, act, obj); + time_t now; + time(&now); + ESP_LOGI(TAG, "Executed timer '%s' action %d under object %d at time %d", name, act, obj, (unsigned int)now); return; } @@ -49,28 +51,51 @@ esp_err_t InitCronSheduler() return res; } - -const char* check_expr(const char* expr) { - const char* err = NULL; +const char* check_expr(const char *expr) +{ + const char *err = NULL; cron_expr test; memset(&test, 0, sizeof(test)); cron_parse_expr(expr, &test, &err); return err; } +void TimeObtainHandler(struct timeval *tm) +{ + ESP_LOGW(TAG, "Current time received with value %d", (unsigned int )tm->tv_sec); + ReloadCronSheduler(); +} + + +void DebugTimer() +{ + time_t now; + time(&now); + ESP_LOGW(TAG, "Timestamp %d", (unsigned int)now); + for (int i = 0; i < CRON_TIMERS_NUMBER; i++) + { + if(GetAppConf()->Timers[i].del) continue; + ESP_LOGW(TAG, "Cron expression:%s", GetAppConf()->Timers[i].cron); + cron_expr cron_exp = {0}; + cron_parse_expr(GetAppConf()->Timers[i].cron, &cron_exp, NULL); + ESP_LOGW(TAG, "Timer %d prev: %u", i, (uint32_t)cron_prev(&cron_exp, now)); + ESP_LOGW(TAG, "Timer %d next: %u", i, (uint32_t)cron_next(&cron_exp, now)); + } +} + esp_err_t ReloadCronSheduler() { //remove all jobs - ESP_LOGI(TAG,"Cron stop call result %d",cron_stop()); + ESP_LOGI(TAG, "Cron stop call result %d", cron_stop()); cron_job_clear_all(); //check if we have jobs to run bool isExpressError = false; for (int i = 0; i < CRON_TIMERS_NUMBER; i++) { - const char* err = check_expr(GetAppConf()->Timers[i].cron); - if(err) + const char *err = check_expr(GetAppConf()->Timers[i].cron); + if (err) { - snprintf (cron_express_error, CRON_EXPRESS_MAX_LENGTH-1, "In timer %d expression error:%s", i+1, err); + snprintf(cron_express_error, CRON_EXPRESS_MAX_LENGTH - 1, "In timer %d expression error:%s", i + 1, err); ESP_LOGE(TAG, "%s", cron_express_error); isExpressError = true; continue; @@ -81,12 +106,13 @@ esp_err_t ReloadCronSheduler() (void*) &GetAppConf()->Timers[i]); } } - if(!isExpressError) cron_express_error[0] = 0x00; //clear last cron expression parse + if (!isExpressError) + cron_express_error[0] = 0x00; //clear last cron expression parse int jobs_num = cron_job_node_count(); ESP_LOGI(TAG, "In config presents %d jobs", jobs_num); if (jobs_num > 0) - ESP_LOGI(TAG,"Cron start call result %d",cron_start()); + ESP_LOGI(TAG, "Cron start call result %d", cron_start()); return ESP_OK; } diff --git a/main/src/HTTPPostCustom.c b/main/src/HTTPPostCustom.c index 170c721..a6f00ee 100644 --- a/main/src/HTTPPostCustom.c +++ b/main/src/HTTPPostCustom.c @@ -101,7 +101,10 @@ static HTTP_IO_RESULT HTTPPostApplication(httpd_req_t *req, char *PostData) } } } - + if (httpd_query_key_value(PostData, "tmrdbg", tmp, sizeof(tmp)) == ESP_OK) + { + DebugTimer(); + } return HTTP_IO_DONE; }