|
@@ -357,6 +357,41 @@ static esp_err_t httpd_set_config(httpd_req_t *req, const char *query)
|
|
return httpd_update_done(req, "Configuration", rv1 ? rv1 : rv2);
|
|
return httpd_update_done(req, "Configuration", rv1 ? rv1 : rv2);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+#define MIN_STATUS_REF 2 /* Minimum refresh time in ms */
|
|
|
|
+
|
|
|
|
+static void httpd_get_status_extra(FILE *f, httpd_req_t *req)
|
|
|
|
+{
|
|
|
|
+ static const char refresh_time_config[] = "http.status.refresh";
|
|
|
|
+ const unsigned long min_status_ref = 5;
|
|
|
|
+ char timebuf[64];
|
|
|
|
+ size_t len;
|
|
|
|
+ struct timeval tv;
|
|
|
|
+
|
|
|
|
+ unsigned long statref;
|
|
|
|
+ statref = Max(getenv_ul(refresh_time_config, 0), min_status_ref);
|
|
|
|
+
|
|
|
|
+ if (httpd_req_get_url_query_str(req, timebuf, sizeof timebuf) == ESP_OK &&
|
|
|
|
+ *timebuf) {
|
|
|
|
+ char *ep;
|
|
|
|
+ unsigned long newstatref = strtoul(timebuf, &ep, 10);
|
|
|
|
+ if (!*ep && newstatref >= min_status_ref && newstatref != statref) {
|
|
|
|
+ statref = newstatref;
|
|
|
|
+ setenv_config(refresh_time_config, timebuf);
|
|
|
|
+ read_config(NULL, true); /* Save changed config */
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ fprintf(f, "%s=%lu\n", refresh_time_config, statref);
|
|
|
|
+
|
|
|
|
+ gettimeofday(&tv,NULL);
|
|
|
|
+ const struct tm *tm = localtime(&tv.tv_sec);
|
|
|
|
+ len = strftime(timebuf, sizeof timebuf, "localtime=%Y-%m-%d %H:%M:%S.", tm);
|
|
|
|
+ snprintf(timebuf+len, sizeof timebuf - len, "%06u",
|
|
|
|
+ (unsigned long)tv.tv_usec);
|
|
|
|
+ len += 3;
|
|
|
|
+ len += strftime(timebuf+len, sizeof timebuf - len, " %z (%Z)\n", tm);
|
|
|
|
+ fwrite(timebuf, 1, len, f);
|
|
|
|
+}
|
|
|
|
+
|
|
static esp_err_t httpd_get_config_status(httpd_req_t *req, bool status)
|
|
static esp_err_t httpd_get_config_status(httpd_req_t *req, bool status)
|
|
{
|
|
{
|
|
FILE *f = httpd_fopen_write(req);
|
|
FILE *f = httpd_fopen_write(req);
|
|
@@ -366,21 +401,14 @@ static esp_err_t httpd_get_config_status(httpd_req_t *req, bool status)
|
|
httpd_resp_set_type(req, text_plain);
|
|
httpd_resp_set_type(req, text_plain);
|
|
httpd_resp_set_hdr(req, "Cache-Control", "no-cache");
|
|
httpd_resp_set_hdr(req, "Cache-Control", "no-cache");
|
|
|
|
|
|
|
|
+ if (status)
|
|
|
|
+ httpd_get_status_extra(f, req);
|
|
|
|
+
|
|
int rv = write_env(f, status);
|
|
int rv = write_env(f, status);
|
|
fclose(f);
|
|
fclose(f);
|
|
return rv ? ESP_FAIL : ESP_OK;
|
|
return rv ? ESP_FAIL : ESP_OK;
|
|
}
|
|
}
|
|
|
|
|
|
-static esp_err_t httpd_get_status(httpd_req_t *req)
|
|
|
|
-{
|
|
|
|
- char timebuf[64];
|
|
|
|
- time_t now = time(NULL);
|
|
|
|
- const struct tm *tm = localtime(&now);
|
|
|
|
- strftime(timebuf, sizeof timebuf, "%Y-%m-%d %H:%M:%S %z (%Z)", tm);
|
|
|
|
- setenv("status.localtime", timebuf, 1);
|
|
|
|
- return httpd_get_config_status(req, true);
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
static esp_err_t httpd_set_lang(httpd_req_t *req, const char *query)
|
|
static esp_err_t httpd_set_lang(httpd_req_t *req, const char *query)
|
|
{
|
|
{
|
|
if (query) {
|
|
if (query) {
|
|
@@ -439,7 +467,7 @@ static esp_err_t httpd_sys_handler(httpd_req_t *req)
|
|
return httpd_lang_redirect(req);
|
|
return httpd_lang_redirect(req);
|
|
|
|
|
|
if (STRING_MATCHES(file, filelen, "getstatus"))
|
|
if (STRING_MATCHES(file, filelen, "getstatus"))
|
|
- return httpd_get_status(req);
|
|
|
|
|
|
+ return httpd_get_config_status(req, true);
|
|
|
|
|
|
if (STRING_MATCHES(file, filelen, "getconfig"))
|
|
if (STRING_MATCHES(file, filelen, "getconfig"))
|
|
return httpd_get_config_status(req, false);
|
|
return httpd_get_config_status(req, false);
|