|
25 | 25 | #include "helpers.h" |
26 | 26 |
|
27 | 27 | #include "UpdateWrapper.h" |
| 28 | +#include "time.h" |
28 | 29 |
|
29 | 30 | #include "WebContent.h" |
30 | 31 |
|
31 | 32 | #include "config.h" |
32 | 33 | #if defined(TARGET_VRX_BACKPACK) |
33 | 34 | extern VrxBackpackConfig config; |
| 35 | +extern bool sendRTCChangesToVrx; |
34 | 36 | #else |
35 | 37 | extern TxBackpackConfig config; |
36 | 38 | #endif |
@@ -422,6 +424,33 @@ static void WebUploadForceUpdateHandler(AsyncWebServerRequest *request) { |
422 | 424 | } |
423 | 425 | } |
424 | 426 |
|
| 427 | +static void WebUploadRTCUpdateHandler(AsyncWebServerRequest *request) { |
| 428 | + static String ntpServer = request->arg("server"); |
| 429 | + long offset = request->arg("offset").toInt(); |
| 430 | + long dst = request->arg("dst") == "on" ? 3600 : 0; |
| 431 | + long utcOffset = offset < 0 ? (12 + abs(offset)) * 3600 : offset * 3600; |
| 432 | + |
| 433 | + DBGLN("Getting NTP data from %s", ntpServer.c_str()); |
| 434 | + configTime(dst, utcOffset, ntpServer.c_str()); |
| 435 | + |
| 436 | + tm timeData; |
| 437 | + AsyncWebServerResponse *response; |
| 438 | + if(!getLocalTime(&timeData)) { |
| 439 | + response = request->beginResponse(500); |
| 440 | + } |
| 441 | + else { |
| 442 | + response = request->beginResponse(200, "text/plain", "RTC clock synced with NTP server."); |
| 443 | + } |
| 444 | + |
| 445 | + response->addHeader("Connection", "close"); |
| 446 | + request->send(response); |
| 447 | + request->client()->close(); |
| 448 | + |
| 449 | + #if defined(TARGET_VRX_BACKPACK) |
| 450 | + sendRTCChangesToVrx = true; |
| 451 | + #endif |
| 452 | +} |
| 453 | + |
425 | 454 | static void wifiOff() |
426 | 455 | { |
427 | 456 | wifiStarted = false; |
@@ -554,6 +583,7 @@ static void startServices() |
554 | 583 |
|
555 | 584 | server.on("/update", HTTP_POST, WebUploadResponseHandler, WebUploadDataHandler); |
556 | 585 | server.on("/forceupdate", WebUploadForceUpdateHandler); |
| 586 | + server.on("/setrtc", WebUploadRTCUpdateHandler); |
557 | 587 |
|
558 | 588 | server.on("/log.js", WebUpdateSendContent); |
559 | 589 | server.on("/log.html", WebUpdateSendContent); |
|
0 commit comments