Browse Source

fixed timezone for time sync from browser #336 (thx @DanielR92)

pull/317/head
lumapu 2 years ago
parent
commit
dbdc2ad5ab
  1. 2
      tools/esp8266/app.cpp
  2. 4
      tools/esp8266/html/serial.html
  3. 5
      tools/esp8266/html/setup.html
  4. 6
      tools/esp8266/webApi.cpp

2
tools/esp8266/app.cpp

@ -125,7 +125,7 @@ void app::loop(void) {
mPayload[iv->id].txId = p->packet[0]; mPayload[iv->id].txId = p->packet[0];
DPRINTLN(DBG_DEBUG, F("Response from devcontrol request received")); DPRINTLN(DBG_DEBUG, F("Response from devcontrol request received"));
iv->devControlRequest = false; iv->devControlRequest = false;
if (p->packet[12] == ActivePowerContr && p->packet[13] == 0x00) { if ((p->packet[12] == ActivePowerContr) && (p->packet[13] == 0x00)) {
if (p->packet[10] == 0x00 && p->packet[11] == 0x00) if (p->packet[10] == 0x00 && p->packet[11] == 0x00)
DPRINTLN(DBG_INFO, F("Inverter ") + String(iv->id) + F(" has accepted power limit set point ") + String(iv->powerLimit[0]) + F(" with PowerLimitControl ") + String(iv->powerLimit[1])); DPRINTLN(DBG_INFO, F("Inverter ") + String(iv->id) + F(" has accepted power limit set point ") + String(iv->powerLimit[0]) + F(" with PowerLimitControl ") + String(iv->powerLimit[1]));
else else

4
tools/esp8266/html/serial.html

@ -42,9 +42,9 @@
<select name="pwrlimcntrl" id="pwrlimcntrl"> <select name="pwrlimcntrl" id="pwrlimcntrl">
<option value="" selected disabled hidden>select the unit and persistence</option> <option value="" selected disabled hidden>select the unit and persistence</option>
<option value="0">absolute in Watt non persistent</option> <option value="0">absolute in Watt non persistent</option>
<option value="1">relativ in percent non persistent</option> <option value="1">relative in percent non persistent</option>
<option value="256">absolute in Watt persistent</option> <option value="256">absolute in Watt persistent</option>
<option value="257">relativ in percent persistent</option> <option value="257">relative in percent persistent</option>
</select> </select>
<br/> <br/>
<input type="button" value="Send Power Limit" class="btn" id="sendpwrlim"/> <input type="button" value="Send Power Limit" class="btn" id="sendpwrlim"/>

5
tools/esp8266/html/setup.html

@ -135,16 +135,17 @@
function apiCb(obj) { function apiCb(obj) {
var e = document.getElementById("apiResult"); var e = document.getElementById("apiResult");
if(obj["success"]) if(obj["success"])
e.innerHTML = "ok"; e.innerHTML = "command excuted";
else else
e.innerHTML = "Error: " + obj["error"]; e.innerHTML = "Error: " + obj["error"];
} }
function setTime() { function setTime() {
var date = new Date(); var date = new Date();
var offset = date.getTimezoneOffset() * -60;
var obj = new Object(); var obj = new Object();
obj.cmd = "set_time"; obj.cmd = "set_time";
obj.ts = parseInt(date.getTime() / 1000); obj.ts = parseInt(offset + (date.getTime() / 1000));
getAjax("/api/setup", apiCb, "POST", JSON.stringify(obj)); getAjax("/api/setup", apiCb, "POST", JSON.stringify(obj));
} }

6
tools/esp8266/webApi.cpp

@ -392,12 +392,10 @@ bool webApi::setCtrl(DynamicJsonDocument jsonIn, JsonObject jsonOut) {
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
bool webApi::setSetup(DynamicJsonDocument jsonIn, JsonObject jsonOut) { bool webApi::setSetup(DynamicJsonDocument jsonIn, JsonObject jsonOut) {
if(F("set_time") == jsonIn[F("cmd")]) { if(F("set_time") == jsonIn[F("cmd")])
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 { else {
jsonOut[F("error")] = F("unknown cmd"); jsonOut[F("error")] = F("unknown cmd");
return false; return false;

Loading…
Cancel
Save