tested calculation of previous and next event's absolute time
This commit is contained in:
parent
efd9318c65
commit
50e224c4d9
|
|
@ -29,6 +29,7 @@ timarr = [
|
|||
~crontmr(15)~
|
||||
];
|
||||
function showcronerr(err) {if(err != "") alert(err);}
|
||||
function dbgtmr(){PostData("tmrdbg=1", "application.html", false, false, false);}
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
|
|
@ -45,6 +46,7 @@ function showcronerr(err) {if(err != "") alert(err);}
|
|||
<div id="timer"></div>
|
||||
</div>
|
||||
<button type="button" class ='btn' id='bt2' onclick="addtm()">Add timer</button>
|
||||
<button type="button" class ='btn' id='bt2' onclick="dbgtmr()">Debug</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
Subproject commit 37d410623cc54b37fc94f5d33dd5e9d660ed5f95
|
||||
Subproject commit 4c2dd92bd130859ce3deabd0b9e361b1d603ed73
|
||||
|
|
@ -29,5 +29,6 @@
|
|||
esp_err_t InitCronSheduler();
|
||||
esp_err_t ReloadCronSheduler();
|
||||
char* GetCronError();
|
||||
void DebugTimer();
|
||||
|
||||
#endif /* MAIN_INCLUDE_CRONTIMERS_H_ */
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user