Browse Source

www: show system time and date on status screen

H. Peter Anvin 2 years ago
parent
commit
c0d62baaf2
6 changed files with 18 additions and 3 deletions
  1. 12 2
      esp32/max80/httpd.c
  2. BIN
      esp32/output/max80.ino.bin
  3. 1 0
      esp32/www/lang/sv
  4. 5 1
      esp32/www/status.html
  5. BIN
      fpga/output/v1.fw
  6. BIN
      fpga/output/v2.fw

+ 12 - 2
esp32/max80/httpd.c

@@ -370,7 +370,17 @@ static esp_err_t httpd_get_config_status(httpd_req_t *req, bool status)
     fclose(f);
     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)
 {
     if (query) {
@@ -429,7 +439,7 @@ static esp_err_t httpd_sys_handler(httpd_req_t *req)
 	return httpd_lang_redirect(req);
 
     if (STRING_MATCHES(file, filelen, "getstatus"))
-	return httpd_get_config_status(req, true);
+	return httpd_get_status(req);
     
     if (STRING_MATCHES(file, filelen, "getconfig"))
 	return httpd_get_config_status(req, false);

BIN
esp32/output/max80.ino.bin


+ 1 - 0
esp32/www/lang/sv

@@ -37,3 +37,4 @@ button .hide=Göm
 .net-ip4-mask span=Nätmask:
 .net-ip4-gw span=Router:
 .sntp-sync span=Klockan i synk med NTP:
+.localtime span=Systemklocka:

+ 5 - 1
esp32/www/status.html

@@ -79,7 +79,11 @@
 	</label>
       </fieldset>
       <fieldset class="datetime">
-	<legend>Time and Date</legend>
+	<legend>Date and Time</legend>
+	<label class="localtime">
+	  <span>Current date and time:</span>
+	  <input type="text" name="localtime" />
+	</label>
 	<label class="sntp-server">
 	  <span>NTP server:</span>
 	  <input type="text" name="net.sntp.server" />

BIN
fpga/output/v1.fw


BIN
fpga/output/v2.fw