mirror of
https://github.com/lumapu/ahoy.git
synced 2025-05-12 00:16:42 +02:00
implemented #336 set time manually or resync NTP
This commit is contained in:
parent
f53933b473
commit
e3532f4464
7 changed files with 71 additions and 13 deletions
|
@ -61,10 +61,14 @@ void app::loop(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if(checkTicker(&mNtpRefreshTicker, mNtpRefreshInterval)) {
|
if(checkTicker(&mNtpRefreshTicker, mNtpRefreshInterval)) {
|
||||||
if(!apActive) {
|
if(!apActive)
|
||||||
mTimestamp = mWifi->getNtpTime();
|
mUpdateNtp = true;
|
||||||
DPRINTLN(DBG_INFO, "[NTP]: " + getDateTimeStr(mTimestamp));
|
}
|
||||||
}
|
|
||||||
|
if(mUpdateNtp) {
|
||||||
|
mUpdateNtp = false;
|
||||||
|
mTimestamp = mWifi->getNtpTime();
|
||||||
|
DPRINTLN(DBG_INFO, "[NTP]: " + getDateTimeStr(mTimestamp));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(mShouldReboot) {
|
if(mShouldReboot) {
|
||||||
|
@ -685,8 +689,9 @@ const char* app::getFieldStateClass(uint8_t fieldId) {
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
void app::resetSystem(void) {
|
void app::resetSystem(void) {
|
||||||
mUptimeSecs = 0;
|
mUptimeSecs = 0;
|
||||||
mPrevMillis = 0;
|
mPrevMillis = 0;
|
||||||
|
mUpdateNtp = false;
|
||||||
|
|
||||||
mNtpRefreshTicker = 0;
|
mNtpRefreshTicker = 0;
|
||||||
mNtpRefreshInterval = NTP_REFRESH_INTERVAL; // [ms]
|
mNtpRefreshInterval = NTP_REFRESH_INTERVAL; // [ms]
|
||||||
|
|
|
@ -112,6 +112,14 @@ class app {
|
||||||
return mTimestamp;
|
return mTimestamp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline void setTimestamp(uint32_t newTime) {
|
||||||
|
DPRINTLN(DBG_DEBUG, F("setTimestamp: ") + String(newTime));
|
||||||
|
if(0 == newTime)
|
||||||
|
mUpdateNtp = true;
|
||||||
|
else
|
||||||
|
mTimestamp = newTime;
|
||||||
|
}
|
||||||
|
|
||||||
void eraseSettings(bool all = false) {
|
void eraseSettings(bool all = false) {
|
||||||
//DPRINTLN(DBG_VERBOSE, F("main.h:eraseSettings"));
|
//DPRINTLN(DBG_VERBOSE, F("main.h:eraseSettings"));
|
||||||
uint8_t buf[64];
|
uint8_t buf[64];
|
||||||
|
@ -239,6 +247,7 @@ class app {
|
||||||
|
|
||||||
eep *mEep;
|
eep *mEep;
|
||||||
uint32_t mTimestamp;
|
uint32_t mTimestamp;
|
||||||
|
bool mUpdateNtp;
|
||||||
|
|
||||||
bool mShowRebootRequest;
|
bool mShowRebootRequest;
|
||||||
|
|
||||||
|
@ -257,7 +266,6 @@ class app {
|
||||||
|
|
||||||
// timer
|
// timer
|
||||||
uint32_t mTicker;
|
uint32_t mTicker;
|
||||||
|
|
||||||
uint32_t mRxTicker;
|
uint32_t mRxTicker;
|
||||||
|
|
||||||
// mqtt
|
// mqtt
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
//-------------------------------------
|
//-------------------------------------
|
||||||
#define VERSION_MAJOR 0
|
#define VERSION_MAJOR 0
|
||||||
#define VERSION_MINOR 5
|
#define VERSION_MINOR 5
|
||||||
#define VERSION_PATCH 18
|
#define VERSION_PATCH 19
|
||||||
|
|
||||||
|
|
||||||
//-------------------------------------
|
//-------------------------------------
|
||||||
|
|
|
@ -64,6 +64,10 @@
|
||||||
<input type="text" class="text" name="ntpAddr"/>
|
<input type="text" class="text" name="ntpAddr"/>
|
||||||
<label for="ntpPort">NTP Port</label>
|
<label for="ntpPort">NTP Port</label>
|
||||||
<input type="text" class="text" name="ntpPort"/>
|
<input type="text" class="text" name="ntpPort"/>
|
||||||
|
<label for="ntpBtn">set system time</label>
|
||||||
|
<input type="button" name="ntpBtn" id="ntpBtn" class="btn" value="from browser" onclick="setTime()"/>
|
||||||
|
<input type="button" name="ntpSync" id="ntpSync" class="btn" value="sync NTP" onclick="syncTime()"/>
|
||||||
|
<span id="apiResult">n/a</span>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -106,7 +110,7 @@
|
||||||
|
|
||||||
<label for="reboot">Reboot device after successful save</label>
|
<label for="reboot">Reboot device after successful save</label>
|
||||||
<input type="checkbox" class="cb" name="reboot"/>
|
<input type="checkbox" class="cb" name="reboot"/>
|
||||||
<input type="submit" value="save" class="btn"/>
|
<input type="submit" value="save" class="btn right"/>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -128,6 +132,28 @@
|
||||||
ivHtml(JSON.parse('{"name":"","serial":"","channels":4,"ch_max_power":[0,0,0,0],"ch_name":["","","",""],"power_limit":1500,"power_limit_option":65535}'), highestId + 1);
|
ivHtml(JSON.parse('{"name":"","serial":"","channels":4,"ch_max_power":[0,0,0,0],"ch_name":["","","",""],"power_limit":1500,"power_limit_option":65535}'), highestId + 1);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function apiCb(obj) {
|
||||||
|
var e = document.getElementById("apiResult");
|
||||||
|
if(obj["success"])
|
||||||
|
e.innerHTML = "ok";
|
||||||
|
else
|
||||||
|
e.innerHTML = "Error: " + obj["error"];
|
||||||
|
}
|
||||||
|
|
||||||
|
function setTime() {
|
||||||
|
var date = new Date();
|
||||||
|
var obj = new Object();
|
||||||
|
obj.cmd = "set_time";
|
||||||
|
obj.ts = parseInt(date.getTime() / 1000);
|
||||||
|
getAjax("/api/setup", apiCb, "POST", JSON.stringify(obj));
|
||||||
|
}
|
||||||
|
|
||||||
|
function syncTime() {
|
||||||
|
var obj = new Object();
|
||||||
|
obj.cmd = "sync_ntp";
|
||||||
|
getAjax("/api/setup", apiCb, "POST", JSON.stringify(obj));
|
||||||
|
}
|
||||||
|
|
||||||
function ivHtml(obj, id) {
|
function ivHtml(obj, id) {
|
||||||
highestId = id;
|
highestId = id;
|
||||||
if(highestId == (maxInv - 1))
|
if(highestId == (maxInv - 1))
|
||||||
|
|
|
@ -133,9 +133,8 @@ input.btn {
|
||||||
background-color: #006ec0;
|
background-color: #006ec0;
|
||||||
color: #fff;
|
color: #fff;
|
||||||
border: 0px;
|
border: 0px;
|
||||||
float: right;
|
|
||||||
margin: 10px 0px 30px 10px;
|
|
||||||
padding: 7px 20px 7px 20px;
|
padding: 7px 20px 7px 20px;
|
||||||
|
margin-bottom: 10px;
|
||||||
text-transform: uppercase;
|
text-transform: uppercase;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
|
|
|
@ -80,6 +80,8 @@ void webApi::onApiPostBody(AsyncWebServerRequest *request, uint8_t *data, size_t
|
||||||
String path = request->url().substring(5);
|
String path = request->url().substring(5);
|
||||||
if(path == "ctrl")
|
if(path == "ctrl")
|
||||||
root[F("success")] = setCtrl(json, root);
|
root[F("success")] = setCtrl(json, root);
|
||||||
|
else if(path == "setup")
|
||||||
|
root[F("success")] = setSetup(json, root);
|
||||||
else {
|
else {
|
||||||
root[F("success")] = false;
|
root[F("success")] = false;
|
||||||
root[F("error")] = "Path not found: " + path;
|
root[F("error")] = "Path not found: " + path;
|
||||||
|
@ -381,7 +383,24 @@ bool webApi::setCtrl(DynamicJsonDocument jsonIn, JsonObject jsonOut) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
jsonOut["error"] = "unknown 'tx_request'";
|
jsonOut[F("error")] = F("unknown 'tx_request'");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
bool webApi::setSetup(DynamicJsonDocument jsonIn, JsonObject jsonOut) {
|
||||||
|
if(F("set_time") == jsonIn[F("cmd")]) {
|
||||||
|
mApp->setTimestamp(jsonIn[F("ts")]);
|
||||||
|
}
|
||||||
|
else if(F("sync_ntp") == jsonIn[F("cmd")]) {
|
||||||
|
mApp->setTimestamp(0); // 0: update ntp flag
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
jsonOut[F("error")] = F("unknown cmd");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -394,6 +413,6 @@ Inverter<> *webApi::getInverter(DynamicJsonDocument jsonIn, JsonObject jsonOut)
|
||||||
uint8_t id = jsonIn[F("inverter")];
|
uint8_t id = jsonIn[F("inverter")];
|
||||||
Inverter<> *iv = mApp->mSys->getInverterByPos(id);
|
Inverter<> *iv = mApp->mSys->getInverterByPos(id);
|
||||||
if(NULL == iv)
|
if(NULL == iv)
|
||||||
jsonOut["error"] = F("inverter index to high: ") + String(id);
|
jsonOut[F("error")] = F("inverter index to high: ") + String(id);
|
||||||
return iv;
|
return iv;
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,6 +42,7 @@ class webApi {
|
||||||
void getRecord(JsonObject obj, record_t<> *rec);
|
void getRecord(JsonObject obj, record_t<> *rec);
|
||||||
|
|
||||||
bool setCtrl(DynamicJsonDocument jsonIn, JsonObject jsonOut);
|
bool setCtrl(DynamicJsonDocument jsonIn, JsonObject jsonOut);
|
||||||
|
bool setSetup(DynamicJsonDocument jsonIn, JsonObject jsonOut);
|
||||||
|
|
||||||
Inverter<> *getInverter(DynamicJsonDocument jsonIn, JsonObject jsonOut);
|
Inverter<> *getInverter(DynamicJsonDocument jsonIn, JsonObject jsonOut);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue