diff --git a/html/scan.js b/html/scan.js
index 7868c0a..51e589e 100644
--- a/html/scan.js
+++ b/html/scan.js
@@ -13,6 +13,7 @@ function get_mode() {
var data = JSON.parse(this.responseText);
if (data.mode==="STA") {
_('stamode').style.display = 'block';
+ _('rtctab').style.display = 'block';
_('ssid').textContent = data.ssid;
} else {
_('apmode').style.display = 'block';
@@ -347,6 +348,9 @@ _('forget').addEventListener('click', callback("Forget Home Network", "An error
if (_('modelmatch') != undefined) {
_('modelmatch').addEventListener('submit', callback("Set Model Match", "An error occurred updating the model match number", "/model", null));
}
+_('setrtc').addEventListener('submit', callback("Set RTC Time", "An error occured setting the RTC time", "/setrtc", function() {
+ return new FormData(_('setrtc'));
+}));
//=========================================================
diff --git a/html/vrx_index.html b/html/vrx_index.html
index 74b1b52..2e35d51 100644
--- a/html/vrx_index.html
+++ b/html/vrx_index.html
@@ -27,6 +27,7 @@
Welcome to your ExpressLRS update page
+
+
+
+
RTC Update via NTP
+ Here you can update your goggle RTC clock time using any available NTP server.
+ Make sure that the home network you're connected to has access to the Internet in order to connect to the NTP server.
+
+
+
diff --git a/lib/MSP/msptypes.h b/lib/MSP/msptypes.h
index a7cae37..c80986c 100644
--- a/lib/MSP/msptypes.h
+++ b/lib/MSP/msptypes.h
@@ -43,6 +43,7 @@
#define MSP_ELRS_BACKPACK_SET_BUZZER 0x030B
#define MSP_ELRS_BACKPACK_SET_OSD_ELEMENT 0x030C
#define MSP_ELRS_BACKPACK_SET_HEAD_TRACKING 0x030D // enable/disable head-tracking forwarding packets to the TX
+#define MSP_ELRS_BACKPACK_SET_RTC 0x030E
// incoming, packets originating from the VRx
#define MSP_ELRS_BACKPACK_SET_MODE 0x0380 // enable wifi/binding mode
diff --git a/lib/WIFI/devWIFI.cpp b/lib/WIFI/devWIFI.cpp
index 8d0ee63..7f9d4a2 100644
--- a/lib/WIFI/devWIFI.cpp
+++ b/lib/WIFI/devWIFI.cpp
@@ -25,12 +25,14 @@
#include "helpers.h"
#include "UpdateWrapper.h"
+#include "time.h"
#include "WebContent.h"
#include "config.h"
#if defined(TARGET_VRX_BACKPACK)
extern VrxBackpackConfig config;
+extern bool sendRTCChangesToVrx;
#else
extern TxBackpackConfig config;
#endif
@@ -422,6 +424,33 @@ static void WebUploadForceUpdateHandler(AsyncWebServerRequest *request) {
}
}
+static void WebUploadRTCUpdateHandler(AsyncWebServerRequest *request) {
+ static String ntpServer = request->arg("server");
+ long offset = request->arg("offset").toInt();
+ long dst = request->arg("dst") == "on" ? 3600 : 0;
+ long utcOffset = offset < 0 ? (12 + abs(offset)) * 3600 : offset * 3600;
+
+ DBGLN("Getting NTP data from %s", ntpServer.c_str());
+ configTime(dst, utcOffset, ntpServer.c_str());
+
+ tm timeData;
+ AsyncWebServerResponse *response;
+ if(!getLocalTime(&timeData)) {
+ response = request->beginResponse(500);
+ }
+ else {
+ response = request->beginResponse(200, "text/plain", "RTC clock synced with NTP server.");
+ }
+
+ response->addHeader("Connection", "close");
+ request->send(response);
+ request->client()->close();
+
+ #if defined(TARGET_VRX_BACKPACK)
+ sendRTCChangesToVrx = true;
+ #endif
+}
+
static void wifiOff()
{
wifiStarted = false;
@@ -554,6 +583,7 @@ static void startServices()
server.on("/update", HTTP_POST, WebUploadResponseHandler, WebUploadDataHandler);
server.on("/forceupdate", WebUploadForceUpdateHandler);
+ server.on("/setrtc", WebUploadRTCUpdateHandler);
server.on("/log.js", WebUpdateSendContent);
server.on("/log.html", WebUpdateSendContent);
diff --git a/src/Vrx_main.cpp b/src/Vrx_main.cpp
index 2f28368..d9bc1e9 100644
--- a/src/Vrx_main.cpp
+++ b/src/Vrx_main.cpp
@@ -69,6 +69,7 @@ unsigned long rebootTime = 0;
uint8_t cachedIndex = 0;
bool sendChannelChangesToVrx = false;
bool sendHeadTrackingChangesToVrx = false;
+bool sendRTCChangesToVrx = false;
bool gotInitialPacket = false;
bool headTrackingEnabled = false;
uint32_t lastSentRequest = 0;
@@ -445,6 +446,11 @@ void loop()
if (connectionState == wifiUpdate)
{
+ if (sendRTCChangesToVrx)
+ {
+ sendRTCChangesToVrx = false;
+ vrxModule.SetRTC();
+ }
return;
}
diff --git a/src/hdzero.cpp b/src/hdzero.cpp
index c9eed4b..393ae45 100644
--- a/src/hdzero.cpp
+++ b/src/hdzero.cpp
@@ -2,6 +2,7 @@
#include "hdzero.h"
#include "msptypes.h"
#include "logging.h"
+#include "time.h"
void
HDZero::Init()
@@ -115,3 +116,26 @@ HDZero::SetOSD(mspPacket_t *packet)
MSP msp;
msp.sendPacket(packet, m_port);
}
+
+void
+HDZero::SetRTC()
+{
+ MSP msp;
+ mspPacket_t packet;
+ tm timeData;
+ if(!getLocalTime(&timeData)) {
+ DBGLN("Could not obtain time data.");
+ return;
+ }
+ packet.reset();
+ packet.makeCommand();
+ packet.function = MSP_ELRS_BACKPACK_SET_RTC;
+ packet.addByte(timeData.tm_year);
+ packet.addByte(timeData.tm_mon);
+ packet.addByte(timeData.tm_mday);
+ packet.addByte(timeData.tm_hour);
+ packet.addByte(timeData.tm_min);
+ packet.addByte(timeData.tm_sec);
+
+ msp.sendPacket(&packet, m_port);
+}
diff --git a/src/hdzero.h b/src/hdzero.h
index 0bf6860..cf9fee2 100644
--- a/src/hdzero.h
+++ b/src/hdzero.h
@@ -25,4 +25,5 @@ class HDZero : public MSPModuleBase
void SetRecordingState(uint8_t recordingState, uint16_t delay);
void SendHeadTrackingEnableCmd(bool enable);
void SetOSD(mspPacket_t *packet);
+ void SetRTC();
};
diff --git a/src/module_base.cpp b/src/module_base.cpp
index 20f80b0..912d272 100644
--- a/src/module_base.cpp
+++ b/src/module_base.cpp
@@ -37,6 +37,11 @@ ModuleBase::SendHeadTrackingEnableCmd(bool enable)
{
}
+void
+ModuleBase::SetRTC()
+{
+}
+
void
ModuleBase::Loop(uint32_t now)
{
diff --git a/src/module_base.h b/src/module_base.h
index 1694602..c1d6033 100644
--- a/src/module_base.h
+++ b/src/module_base.h
@@ -11,6 +11,7 @@ class ModuleBase
void SetRecordingState(uint8_t recordingState, uint16_t delay);
void SetOSD(mspPacket_t *packet);
void SendHeadTrackingEnableCmd(bool enable);
+ void SetRTC();
void Loop(uint32_t now);
};
diff --git a/targets/common.ini b/targets/common.ini
index ae38fe1..cc8e974 100644
--- a/targets/common.ini
+++ b/targets/common.ini
@@ -1,6 +1,6 @@
# ------------------------- COMMON ENV DEFINITIONS -----------------
[env]
-platform = espressif8266@3.2.0
+platform = espressif8266@4.2.0
framework = arduino
extra_scripts =
pre:python/build_flags.py
diff --git a/targets/hdzero.ini b/targets/hdzero.ini
index bb03c3c..fbd9c49 100644
--- a/targets/hdzero.ini
+++ b/targets/hdzero.ini
@@ -2,7 +2,7 @@
# VRX backpack targets
# ********************************
-[env:HDZero_RX5.1_ESP8285_Backpack_via_UART]
+[env:HDZero_RX51_ESP8285_Backpack_via_UART]
extends = env_common_esp8285, hdzero_vrx_backpack_common
monitor_speed = 115200
build_flags =
@@ -10,10 +10,10 @@ build_flags =
${hdzero_vrx_backpack_common.build_flags}
-D PIN_LED=16
-[env:HDZero_RX5.1_ESP8285_Backpack_via_WIFI]
-extends = env:HDZero_RX5.1_ESP8285_Backpack_via_UART
+[env:HDZero_RX51_ESP8285_Backpack_via_WIFI]
+extends = env:HDZero_RX51_ESP8285_Backpack_via_UART
-[env:HDZero_RX5.1_ESP32_Backpack_via_UART]
+[env:HDZero_RX51_ESP32_Backpack_via_UART]
extends = env_common_esp32, hdzero_vrx_backpack_common
monitor_speed = 115200
build_flags =
@@ -22,10 +22,10 @@ build_flags =
-D PIN_LED=4
lib_ignore = STM32UPDATE
-[env:HDZero_RX5.1_ESP32_Backpack_via_WIFI]
-extends = env:HDZero_RX5.1_ESP32_Backpack_via_UART
+[env:HDZero_RX51_ESP32_Backpack_via_WIFI]
+extends = env:HDZero_RX51_ESP32_Backpack_via_UART
-[env:HDZero_Goggle_RX5.1_ESP32_Backpack_via_UART]
+[env:HDZero_Goggle_ESP32_Backpack_via_UART]
extends = env_common_esp32, hdzero_vrx_backpack_common
monitor_speed = 115200
build_flags =
@@ -35,5 +35,5 @@ build_flags =
-D NO_AUTOBIND=1
lib_ignore = STM32UPDATE
-[env:HDZero_Goggle_RX5.1_ESP32_Backpack_via_WIFI]
-extends = env:HDZero_Goggle_RX5.1_ESP32_Backpack_via_UART
+[env:HDZero_Goggle_ESP32_Backpack_via_WIFI]
+extends = env:HDZero_Goggle_ESP32_Backpack_via_UART