mirror of
https://github.com/lumapu/ahoy.git
synced 2025-05-03 12:15:54 +02:00
fix webserial is now in local timezone
This commit is contained in:
parent
72219cdf17
commit
a77bea55d0
6 changed files with 27 additions and 11 deletions
|
@ -98,12 +98,12 @@ class app {
|
||||||
return String(str);
|
return String(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
String getTimeStr(void) {
|
String getTimeStr(uint32_t offset = 0) {
|
||||||
char str[20];
|
char str[10];
|
||||||
if(0 == mUtcTimestamp)
|
if(0 == mUtcTimestamp)
|
||||||
sprintf(str, "n/a");
|
sprintf(str, "n/a");
|
||||||
else
|
else
|
||||||
sprintf(str, "%02d:%02d:%02d UTC", hour(mUtcTimestamp), minute(mUtcTimestamp), second(mUtcTimestamp));
|
sprintf(str, "%02d:%02d:%02d ", hour(mUtcTimestamp + offset), minute(mUtcTimestamp + offset), second(mUtcTimestamp + offset));
|
||||||
return String(str);
|
return String(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -115,7 +115,7 @@ class app {
|
||||||
return mUtcTimestamp;
|
return mUtcTimestamp;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void setTimestamp(uint32_t newTime) {
|
void setTimestamp(uint32_t newTime) {
|
||||||
DPRINTLN(DBG_DEBUG, F("setTimestamp: ") + String(newTime));
|
DPRINTLN(DBG_DEBUG, F("setTimestamp: ") + String(newTime));
|
||||||
if(0 == newTime)
|
if(0 == newTime)
|
||||||
mUpdateNtp = true;
|
mUpdateNtp = true;
|
||||||
|
|
|
@ -19,8 +19,10 @@ function getAjax(url, ptr, method="GET", json=null) {
|
||||||
}
|
}
|
||||||
function p() {
|
function p() {
|
||||||
if(xhr.readyState == 4) {
|
if(xhr.readyState == 4) {
|
||||||
if(null != xhr.responseText)
|
if(null != xhr.responseText) {
|
||||||
ptr(JSON.parse(xhr.responseText));
|
if(null != ptr)
|
||||||
|
ptr(JSON.parse(xhr.responseText));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -85,14 +85,19 @@
|
||||||
|
|
||||||
if(null == root) return;
|
if(null == root) return;
|
||||||
root = root.inverter;
|
root = root.inverter;
|
||||||
for(var i = 0; i < root.inverter.length; i++)
|
for(var i = 0; i < root.inverter.length; i++) {
|
||||||
{
|
|
||||||
inv = root.inverter[i];
|
inv = root.inverter[i];
|
||||||
var opt = document.createElement('option');
|
var opt = document.createElement('option');
|
||||||
opt.value = inv.id;
|
opt.value = inv.id;
|
||||||
opt.innerHTML = inv.name;
|
opt.innerHTML = inv.name;
|
||||||
select.appendChild(opt);
|
select.appendChild(opt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// set time offset for serial console
|
||||||
|
var obj = new Object();
|
||||||
|
obj.cmd = "serial_utc_offset";
|
||||||
|
obj.ts = new Date().getTimezoneOffset() * -60;
|
||||||
|
getAjax("/api/setup", null, "POST", JSON.stringify(obj));
|
||||||
}
|
}
|
||||||
|
|
||||||
document.getElementById("clear").addEventListener("click", function() {
|
document.getElementById("clear").addEventListener("click", function() {
|
||||||
|
@ -133,8 +138,7 @@
|
||||||
e.innerHTML = "Error: " + obj["error"];
|
e.innerHTML = "Error: " + obj["error"];
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_selected_iv()
|
function get_selected_iv() {
|
||||||
{
|
|
||||||
var e = document.getElementById("InvID");
|
var e = document.getElementById("InvID");
|
||||||
return parseInt(e.value);
|
return parseInt(e.value);
|
||||||
}
|
}
|
||||||
|
|
|
@ -474,7 +474,7 @@ void web::serialCb(String msg) {
|
||||||
msg.replace("\r\n", "<rn>");
|
msg.replace("\r\n", "<rn>");
|
||||||
if(mSerialAddTime) {
|
if(mSerialAddTime) {
|
||||||
if((9 + mSerialBufFill) <= WEB_SERIAL_BUF_SIZE) {
|
if((9 + mSerialBufFill) <= WEB_SERIAL_BUF_SIZE) {
|
||||||
strncpy(&mSerialBuf[mSerialBufFill], mMain->getTimeStr().c_str(), 9);
|
strncpy(&mSerialBuf[mSerialBufFill], mMain->getTimeStr(mApi->getTimezoneOffset()).c_str(), 9);
|
||||||
mSerialBufFill += 9;
|
mSerialBufFill += 9;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
|
@ -18,6 +18,8 @@ webApi::webApi(AsyncWebServer *srv, app *app, sysConfig_t *sysCfg, config_t *con
|
||||||
mConfig = config;
|
mConfig = config;
|
||||||
mStat = stat;
|
mStat = stat;
|
||||||
mVersion = version;
|
mVersion = version;
|
||||||
|
|
||||||
|
mTimezoneOffset = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -430,6 +432,8 @@ bool webApi::setSetup(DynamicJsonDocument jsonIn, JsonObject jsonOut) {
|
||||||
mApp->setTimestamp(jsonIn[F("ts")]);
|
mApp->setTimestamp(jsonIn[F("ts")]);
|
||||||
else if(F("sync_ntp") == jsonIn[F("cmd")])
|
else if(F("sync_ntp") == jsonIn[F("cmd")])
|
||||||
mApp->setTimestamp(0); // 0: update ntp flag
|
mApp->setTimestamp(0); // 0: update ntp flag
|
||||||
|
else if(F("serial_utc_offset") == jsonIn[F("cmd")])
|
||||||
|
mTimezoneOffset = jsonIn[F("ts")];
|
||||||
else if(F("discovery_cfg") == jsonIn[F("cmd")])
|
else if(F("discovery_cfg") == jsonIn[F("cmd")])
|
||||||
mApp->mFlagSendDiscoveryConfig = true; // for homeassistant
|
mApp->mFlagSendDiscoveryConfig = true; // for homeassistant
|
||||||
else {
|
else {
|
||||||
|
|
|
@ -21,6 +21,10 @@ class webApi {
|
||||||
void setup(void);
|
void setup(void);
|
||||||
void loop(void);
|
void loop(void);
|
||||||
|
|
||||||
|
uint32_t getTimezoneOffset() {
|
||||||
|
return mTimezoneOffset;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void onApi(AsyncWebServerRequest *request);
|
void onApi(AsyncWebServerRequest *request);
|
||||||
void onApiPost(AsyncWebServerRequest *request);
|
void onApiPost(AsyncWebServerRequest *request);
|
||||||
|
@ -59,6 +63,8 @@ class webApi {
|
||||||
sysConfig_t *mSysCfg;
|
sysConfig_t *mSysCfg;
|
||||||
statistics_t *mStat;
|
statistics_t *mStat;
|
||||||
char *mVersion;
|
char *mVersion;
|
||||||
|
|
||||||
|
uint32_t mTimezoneOffset;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /*__WEB_API_H__*/
|
#endif /*__WEB_API_H__*/
|
||||||
|
|
Loading…
Add table
Reference in a new issue