Skip to content

Commit

Permalink
Merge pull request #34 from pzbitskiy/pavel/ntp-server
Browse files Browse the repository at this point in the history
Add option to configure NTP server
  • Loading branch information
dzungpv authored Aug 28, 2024
2 parents 65468a9 + 30a847a commit c3d3457
Show file tree
Hide file tree
Showing 14 changed files with 60 additions and 37 deletions.
2 changes: 1 addition & 1 deletion main/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ String ap_pwd;
String ota_pwd;

// time and time zone
const char *ntpServer = "pool.ntp.org";
String ntpServer = "pool.ntp.org";
const long gmtOffset_sec = 3600;
const int daylightOffset_sec = 3600;

Expand Down
33 changes: 19 additions & 14 deletions main/htmls/html_pages.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,21 @@
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
const char html_page_reboot[] PROGMEM =

const char html_page_reboot[] PROGMEM =
"<p>_TXT_M_REBOOT_ <span id='count'>20s</span>...</p>"
"<script>"
"setTimeout(function() {"
"window.location.href = '/';"
"}, 20000);"
"</script>";

const char html_page_reset[] PROGMEM =
const char html_page_reset[] PROGMEM =
"<p>_TXT_M_RESET_ <span id='count'>20s</span>. _TXT_M_RESET_1_ _UNIT_NAME_</p>"
;


const char html_page_save_reboot[] PROGMEM =
const char html_page_save_reboot[] PROGMEM =
"<p>_TXT_M_SAVE_ <span id='count'>20s</span>...</p>"
"<script>"
"setTimeout(function() {"
Expand All @@ -36,7 +36,7 @@ const char html_page_save_reboot[] PROGMEM =
"</script>"
;

const char html_page_mqtt[] PROGMEM =
const char html_page_mqtt[] PROGMEM =
"<div id='l1' name='l1'>"
"<fieldset>"
"<legend><b>&nbsp; _TXT_MQTT_TITLE_ &nbsp;</b></legend>"
Expand Down Expand Up @@ -90,7 +90,7 @@ const char html_page_mqtt[] PROGMEM =
"</div>"
;

const char html_page_others[] PROGMEM =
const char html_page_others[] PROGMEM =
"<div id='l1' name='l1'>"
"<fieldset>"
"<legend><b>&nbsp; _TXT_OTHERS_TITLE_ &nbsp;</b></legend>"
Expand Down Expand Up @@ -131,6 +131,11 @@ const char html_page_others[] PROGMEM =
"<input id='tz' name='tz' placeholder=' ' value='_TIME_ZONE_' "
"autocomplete='off' autocorrect='off' autocapitalize='off' spellcheck='false'>"
"</p>"
"<p><b>_TXT_OTHER_NTP_SERVER_</b>"
"<br/>"
"<input id='ntp' name='ntp' placeholder='pool.ntp.org' value='_NTP_SERVER_' "
"autocomplete='off' autocorrect='off' autocapitalize='off' spellcheck='false'>"
"</p>"
"<br/>"
"<button name='save' type='submit' class='button bgrn'>_TXT_SAVE_</button>"
"</form>"
Expand All @@ -143,7 +148,7 @@ const char html_page_others[] PROGMEM =
"</div>"
;

const char html_page_status[] PROGMEM =
const char html_page_status[] PROGMEM =
"<div id='l1' name='l1'>"
"<fieldset>"
"<legend><b>&nbsp; _TXT_STATUS_TITLE_ &nbsp;</b></legend>"
Expand All @@ -168,7 +173,7 @@ const char html_page_status[] PROGMEM =
"</p>"
"</div>";

const char html_page_wifi[] PROGMEM =
const char html_page_wifi[] PROGMEM =
"<div id='l1' name='l1'>"
"<fieldset>"
"<legend><b>&nbsp; _TXT_WIFI_TITLE_ &nbsp;</b></legend>"
Expand Down Expand Up @@ -211,7 +216,7 @@ const char html_page_wifi[] PROGMEM =
"</div>"
;

const char html_page_control[] PROGMEM =
const char html_page_control[] PROGMEM =

"<div style='text-align:center;'>"
"<h2>_TXT_CTRL_CTEMP_ <span id='room_temperature'>_ROOMTEMP_</span>&#176;</h2>"
Expand Down Expand Up @@ -307,7 +312,7 @@ const char html_page_control[] PROGMEM =
"</p>"
"</div>";

const char html_page_unit[] PROGMEM =
const char html_page_unit[] PROGMEM =
"<div id='l1' name='l1'>"
"<fieldset>"
"<legend><b>&nbsp; _TXT_UNIT_TITLE_ &nbsp;</b></legend>"
Expand Down Expand Up @@ -355,7 +360,7 @@ const char html_page_unit[] PROGMEM =
"<input id='lpwc' name='lpwc' type='password' placeholder=' ' value='_LOGIN_PASSWORD_' "
"autocomplete='off' autocorrect='off' autocapitalize='off' spellcheck='false'>"
"</p>"
"<span id='message_not_match' style='color:red'> </span> <br>"
"<span id='message_not_match' style='color:red'> </span> <br>"
"<p>_TXT_UNIT_LOGIN_USERNAME_ <b>admin</b></p>"
"<br/>"
"<button name='save' type='submit' class='button bgrn'>_TXT_SAVE_</button>"
Expand All @@ -370,7 +375,7 @@ const char html_page_unit[] PROGMEM =
"</div>"
;

const char html_page_login[] PROGMEM =
const char html_page_login[] PROGMEM =
"<script>"
"var loginSucess = _LOGIN_SUCCESS_;"
"document.onreadystatechange = function() {"
Expand Down Expand Up @@ -406,7 +411,7 @@ const char html_page_login[] PROGMEM =
"</div>"
;

const char html_page_upgrade[] PROGMEM =
const char html_page_upgrade[] PROGMEM =
"<script>"
"function eb(s) {"
"return document.getElementById(s);"
Expand Down Expand Up @@ -438,7 +443,7 @@ const char html_page_upgrade[] PROGMEM =
"<div id='f2' style='display:none;text-align:center;'><b>_TXT_UPGRADE_START_ ...</b></div>"
;

const char html_page_upload[] PROGMEM =
const char html_page_upload[] PROGMEM =
"<div style='text-align:center;'>"
"<h2>_TXT_UPLOAD_FW_PAGE_</h2>"
"</div>"
Expand Down
1 change: 1 addition & 0 deletions main/language_translations.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ MAKE_WORD_TRANSLATION(txt_others_tx_pin, en::txt_others_tx_pin, vi::txt_others_t
MAKE_WORD_TRANSLATION(txt_others_rx_pin, en::txt_others_rx_pin, vi::txt_others_rx_pin, da::txt_others_rx_pin, de::txt_others_rx_pin, es::txt_others_rx_pin, fr::txt_others_rx_pin, it::txt_others_rx_pin, ja::txt_others_rx_pin, zh::txt_others_rx_pin, ca::txt_others_rx_pin) // TODO translate
MAKE_WORD_TRANSLATION(txt_others_tz, en::txt_others_tz, vi::txt_others_tz, da::txt_others_tz, de::txt_others_tz, es::txt_others_tz, fr::txt_others_tz, it::txt_others_tz, ja::txt_others_tz, zh::txt_others_tz, ca::txt_others_tz) // TODO translate
MAKE_WORD_TRANSLATION(txt_others_tz_list, en::txt_others_tz_list, vi::txt_others_tz_list, da::txt_others_tz_list, de::txt_others_tz_list, es::txt_others_tz_list, fr::txt_others_tz_list, it::txt_others_tz_list, ja::txt_others_tz_list, zh::txt_others_tz_list, ca::txt_others_tz_list) // TODO translate
MAKE_WORD_TRANSLATION(txt_others_ntp_server, en::txt_others_ntp_server, vi::txt_others_ntp_server, da::txt_others_ntp_server, de::txt_others_ntp_server, es::txt_others_ntp_server, fr::txt_others_ntp_server, it::txt_others_ntp_server, ja::txt_others_ntp_server, zh::txt_others_ntp_server, ca::txt_others_ntp_server) // TODO translate

// Page Status
MAKE_WORD_TRANSLATION(txt_status_title, en::txt_status_title, vi::txt_status_title, da::txt_status_title, de::txt_status_title, es::txt_status_title, fr::txt_status_title, it::txt_status_title, ja::txt_status_title, zh::txt_status_title, ca::txt_status_title) // TODO translate
Expand Down
3 changes: 2 additions & 1 deletion main/languages/ca-ES.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ namespace ca
const char txt_others_rx_pin[] PROGMEM = "RX pin (ESP32, 0 use UART1)";
const char txt_others_tz[] PROGMEM = "Fus horari";
const char txt_others_tz_list[] PROGMEM = "Vegeu-ne la llista";
const char txt_others_ntp_server[] PROGMEM = "Server NTP";

// Page Status
const char txt_status_title[] PROGMEM = "Estat";
Expand Down Expand Up @@ -177,7 +178,7 @@ namespace ca
const char txt_upload_success[] PROGMEM = "Correcta";
const char txt_upload_refresh[] PROGMEM = "Refrescant en";

// Page Init
// Page Init
const char txt_init_title[] PROGMEM = "Configuració inicial";
const char txt_init_reboot_mes[] PROGMEM = "S'està reiniciant i connectant a la xarxa WiFi! Hauries de veure'l llistat al teu punt d'accés.";
const char txt_init_reboot_mes_1[] PROGMEM = "Utilitzeu aquesta adreça per accedir al vostre dispositiu després de reiniciar-lo. S'està reiniciant";
Expand Down
3 changes: 2 additions & 1 deletion main/languages/da-DA.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ namespace da
const char txt_others_rx_pin[] PROGMEM = "RX pin (ESP32, 0 use UART1)";
const char txt_others_tz[] PROGMEM = "Timezone";
const char txt_others_tz_list[] PROGMEM = "See list";

const char txt_others_ntp_server[] PROGMEM = "NTP Server";

// Page Status
const char txt_status_title[] PROGMEM = "Status";
const char txt_status_hvac[] PROGMEM = "HVAC Status";
Expand Down
1 change: 1 addition & 0 deletions main/languages/de-DE.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ namespace de
const char txt_others_rx_pin[] PROGMEM = "RX pin (ESP32, 0 use UART1)";
const char txt_others_tz[] PROGMEM = "Timezone";
const char txt_others_tz_list[] PROGMEM = "See list";
const char txt_others_ntp_server[] PROGMEM = "NTP Server";

// Page Status
const char txt_status_title[] PROGMEM = "Status";
Expand Down
3 changes: 2 additions & 1 deletion main/languages/en-GB.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ namespace en
const char txt_others_rx_pin[] PROGMEM = "RX pin (ESP32, 0 use UART1)";
const char txt_others_tz[] PROGMEM = "Timezone";
const char txt_others_tz_list[] PROGMEM = "See list";

const char txt_others_ntp_server[] PROGMEM = "NTP Server";

// Page Status
const char txt_status_title[] PROGMEM = "Status";
const char txt_status_hvac[] PROGMEM = "HVAC Status";
Expand Down
3 changes: 2 additions & 1 deletion main/languages/es-ES.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ namespace es
const char txt_others_rx_pin[] PROGMEM = "RX pin (ESP32, 0 use UART1)";
const char txt_others_tz[] PROGMEM = "Timezone";
const char txt_others_tz_list[] PROGMEM = "See list";

const char txt_others_ntp_server[] PROGMEM = "Servidor NTP";

// Page Status
const char txt_status_title[] PROGMEM = "Estado";
const char txt_status_hvac[] PROGMEM = "Estado HVAC";
Expand Down
7 changes: 4 additions & 3 deletions main/languages/fr-FR.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,10 @@ namespace fr
const char txt_others_debug_log[] PROGMEM = "MQTT topic debug logs";
const char txt_others_tx_pin[] PROGMEM = "TX pin (ESP32, 0 use UART1)";
const char txt_others_rx_pin[] PROGMEM = "RX pin (ESP32, 0 use UART1)";
const char txt_others_tz[] PROGMEM = "Timezone";
const char txt_others_tz_list[] PROGMEM = "See list";

const char txt_others_tz[] PROGMEM = "Fuseau horaire";
const char txt_others_tz_list[] PROGMEM = "Voir la liste";
const char txt_others_ntp_server[] PROGMEM = "Serveur NTP";

// Page Status
const char txt_status_title[] PROGMEM = "Etats";
const char txt_status_hvac[] PROGMEM = "Etat HVAC";
Expand Down
7 changes: 4 additions & 3 deletions main/languages/it-IT.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,10 @@ namespace it
const char txt_others_debug_log[] PROGMEM = "MQTT topic debug logs";
const char txt_others_tx_pin[] PROGMEM = "TX pin (ESP32, 0 use UART1)";
const char txt_others_rx_pin[] PROGMEM = "RX pin (ESP32, 0 use UART1)";
const char txt_others_tz[] PROGMEM = "Timezone";
const char txt_others_tz_list[] PROGMEM = "See list";

const char txt_others_tz[] PROGMEM = "Fuso orario";
const char txt_others_tz_list[] PROGMEM = "Vedi l'elenco";
const char txt_others_ntp_server[] PROGMEM = "Servidor NTP";

// Page Status
const char txt_status_title[] PROGMEM = "Stato";
const char txt_status_hvac[] PROGMEM = "Stato HVAC";
Expand Down
7 changes: 4 additions & 3 deletions main/languages/ja-JP.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,10 @@ namespace ja
const char txt_others_debug_log[] PROGMEM = "MQTT topic debug logs";
const char txt_others_tx_pin[] PROGMEM = "TX pin (ESP32, 0 use UART1)";
const char txt_others_rx_pin[] PROGMEM = "RX pin (ESP32, 0 use UART1)";
const char txt_others_tz[] PROGMEM = "Timezone";
const char txt_others_tz_list[] PROGMEM = "See list";

const char txt_others_tz[] PROGMEM = "タイムゾーン";
const char txt_others_tz_list[] PROGMEM = "リストを見る";
const char txt_others_ntp_server[] PROGMEM = "NTP サーバー";

// Page Status
const char txt_status_title[] PROGMEM = "ステータス";
const char txt_status_hvac[] PROGMEM = "エアコン本体";
Expand Down
3 changes: 2 additions & 1 deletion main/languages/vi-VN.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ namespace vi
const char txt_others_rx_pin[] PROGMEM = "Chân RX (ESP32, 0 dùng UART1)";
const char txt_others_tz[] PROGMEM = "Múi giờ";
const char txt_others_tz_list[] PROGMEM = "Xem danh sách";

const char txt_others_ntp_server[] PROGMEM = "Máy chủ NTP";

// Page Status
const char txt_status_title[] PROGMEM = "Trạng thái";
const char txt_status_hvac[] PROGMEM = "Trạng thái ĐH";
Expand Down
7 changes: 4 additions & 3 deletions main/languages/zh-CN.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,10 @@ namespace zh
const char txt_others_debug_log[] PROGMEM = "MQTT topic debug logs";
const char txt_others_tx_pin[] PROGMEM = "TX pin (ESP32, 0 use UART1)";
const char txt_others_rx_pin[] PROGMEM = "RX pin (ESP32, 0 use UART1)";
const char txt_others_tz[] PROGMEM = "Timezone";
const char txt_others_tz_list[] PROGMEM = "See list";

const char txt_others_tz[] PROGMEM = "时区";
const char txt_others_tz_list[] PROGMEM = "查看列表";
const char txt_others_ntp_server[] PROGMEM = "NTP 服务器";

// Page Status
const char txt_status_title[] PROGMEM = "状态";
const char txt_status_hvac[] PROGMEM = "空调状态";
Expand Down
17 changes: 12 additions & 5 deletions main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ bool loadOthers()
return false;
}
// Allocate document capacity.
const size_t capacity = JSON_OBJECT_SIZE(7) + 350;
const size_t capacity = JSON_OBJECT_SIZE(9) + 366;
DynamicJsonDocument doc(capacity);
deserializeJson(doc, configFile);
// unit
Expand Down Expand Up @@ -581,6 +581,10 @@ bool loadOthers()
{
timezone = doc["tz"].as<String>();
}
if (doc.containsKey("ntp"))
{
ntpServer = doc["ntp"].as<String>();
}
return true;
}

Expand Down Expand Up @@ -686,10 +690,10 @@ void saveWifi(String apSsid, const String& apPwd, String hostName, const String&
configFile.close();
}

void saveOthers(const String& haa, const String& haat, const String& debugPckts, const String& debugLogs, const String& txPin, const String& rxPin, const String& tz)
void saveOthers(const String& haa, const String& haat, const String& debugPckts, const String& debugLogs, const String& txPin, const String& rxPin, const String& tz, const String &ntp)
{
// Allocate document capacity.
const size_t capacity = JSON_OBJECT_SIZE(7) + 350;
const size_t capacity = JSON_OBJECT_SIZE(9) + 366;
DynamicJsonDocument doc(capacity);
doc["haa"] = haa;
doc["haat"] = haat;
Expand All @@ -698,6 +702,7 @@ void saveOthers(const String& haa, const String& haat, const String& debugPckts,
doc["txPin"] = txPin;
doc["rxPin"] = rxPin;
doc["tz"] = tz;
doc["ntp"] = ntp;
File configFile = SPIFFS.open(others_conf, "w");
if (!configFile)
{
Expand All @@ -712,7 +717,7 @@ void saveCurrentOthers()
String haa = others_haa ? "ON" : "OFF";
String debugPckts = _debugModePckts ? "ON" : "OFF";
String debugLogs = _debugModeLogs ? "ON" : "OFF";
saveOthers(haa, others_haa_topic, debugPckts, debugLogs, String(HP_TX), String(HP_RX), timezone);
saveOthers(haa, others_haa_topic, debugPckts, debugLogs, String(HP_TX), String(HP_RX), timezone, ntpServer);
}

// Initialize captive portal page
Expand Down Expand Up @@ -1138,7 +1143,7 @@ void handleOthers(AsyncWebServerRequest *request)
checkLogin(request);
if (request->hasArg("save"))
{
saveOthers(request->arg("HAA"), request->arg("haat"), request->arg("DebugPckts"), request->arg("DebugLogs"), request->arg("tx_pin"), request->arg("rx_pin"), request->arg("tz"));
saveOthers(request->arg("HAA"), request->arg("haat"), request->arg("DebugPckts"), request->arg("DebugLogs"), request->arg("tx_pin"), request->arg("rx_pin"), request->arg("tz"), request->arg("ntp"));
String saveRebootPage = FPSTR(html_page_save_reboot);
// localize
saveRebootPage.replace("_TXT_M_SAVE_", translatedWord(FL_(txt_m_save)));
Expand All @@ -1156,6 +1161,7 @@ void handleOthers(AsyncWebServerRequest *request)
othersPage.replace("_TXT_OTHERS_DEBUG_PCKTS_", translatedWord(FL_(txt_others_debug_packets)));
othersPage.replace("_TXT_OTHERS_DEBUG_LOGS_", translatedWord(FL_(txt_others_debug_log)));
othersPage.replace("_TXT_OTHERS_TIME_ZONE_", translatedWord(FL_(txt_others_tz)));
othersPage.replace("_TXT_OTHER_NTP_SERVER_", translatedWord(FL_(txt_others_ntp_server)));
othersPage.replace("_SEE_TZ_LIST", translatedWord(FL_(txt_others_tz_list)));
othersPage.replace("_TXT_TX_PIN_", translatedWord(FL_(txt_others_tx_pin)));
othersPage.replace("_TXT_RX_PIN_", translatedWord(FL_(txt_others_rx_pin)));
Expand All @@ -1168,6 +1174,7 @@ void handleOthers(AsyncWebServerRequest *request)
othersPage.replace("_TX_PIN_", String(HP_TX));
othersPage.replace("_RX_PIN_", String(HP_RX));
othersPage.replace("_TIME_ZONE_", timezone);
othersPage.replace("_NTP_SERVER_", String(ntpServer));
if (others_haa)
{
othersPage.replace("_HAA_ON_", "selected");
Expand Down

0 comments on commit c3d3457

Please sign in to comment.