Browse Source

factory reset formats entire little fs

renamed sunrise / sunset on indext.html to start / stop communication
show system information only if called directly from menu
pull/518/head
lumapu 2 years ago
parent
commit
b2fc16e030
  1. 5
      src/CHANGES.md
  2. 18
      src/app.cpp
  3. 28
      src/config/settings.h
  4. 2
      src/defines.h
  5. 1
      src/web/RestApi.h
  6. 11
      src/web/html/index.html
  7. 11
      src/web/html/system.html
  8. 1
      src/wifi/ahoywifi.cpp

5
src/CHANGES.md

@ -1,5 +1,10 @@
# Changelog
## 0.5.56
* factory reset formats entire little fs
* renamed sunrise / sunset on indext.html to start / stop communication
* show system information only if called directly from menu
## 0.5.55
* fixed static IP save

18
src/app.cpp

@ -30,15 +30,6 @@ void app::setup() {
mSettings.getPtr(mConfig);
DPRINTLN(DBG_INFO, F("Settings valid: ") + String((mSettings.getValid()) ? F("true") : F("false")));
every(std::bind(&app::tickSend, this), mConfig->nrf.sendInterval);
#if !defined(AP_ONLY)
once(std::bind(&app::tickNtpUpdate, this), 2);
if((mConfig->sun.lat) && (mConfig->sun.lon)) {
mCalculatedTimezoneOffset = (int8_t)((mConfig->sun.lon >= 0 ? mConfig->sun.lon + 7.5 : mConfig->sun.lon - 7.5) / 15) * 3600;
once(std::bind(&app::tickCalcSunrise, this), 5);
}
#endif
mSys = new HmSystemType();
mSys->enableDebug();
mSys->setup(mConfig->nrf.amplifierPower, mConfig->nrf.pinIrq, mConfig->nrf.pinCe, mConfig->nrf.pinCs);
@ -51,6 +42,15 @@ void app::setup() {
mWifi.setup(mConfig, &mTimestamp);
every(std::bind(&app::tickSend, this), mConfig->nrf.sendInterval);
#if !defined(AP_ONLY)
once(std::bind(&app::tickNtpUpdate, this), 2);
if((mConfig->sun.lat) && (mConfig->sun.lon)) {
mCalculatedTimezoneOffset = (int8_t)((mConfig->sun.lon >= 0 ? mConfig->sun.lon + 7.5 : mConfig->sun.lon - 7.5) / 15) * 3600;
once(std::bind(&app::tickCalcSunrise, this), 5);
}
#endif
if(mSys->Radio.isChipConnected()) {
mSys->addInverters(&mConfig->inst);
mPayload.setup(mSys);

28
src/config/settings.h

@ -193,7 +193,7 @@ class settings {
}
bool saveSettings(void) {
DPRINTLN(DBG_INFO, F("save settings"));
DPRINTLN(DBG_DEBUG, F("save settings"));
File fp = LittleFS.open("/settings.json", "w");
if(!fp) {
DPRINTLN(DBG_ERROR, F("can't open settings file!"));
@ -221,24 +221,32 @@ class settings {
}
bool eraseSettings(bool eraseWifi = false) {
loadDefaults(eraseWifi);
if(true == eraseWifi)
return LittleFS.format();
loadDefaults(!eraseWifi);
return saveSettings();
}
private:
void loadDefaults(bool wifi = true) {
void loadDefaults(bool keepWifi = false) {
DPRINTLN(DBG_VERBOSE, F("loadDefaults"));
if(wifi) {
snprintf(mCfg.sys.stationSsid, SSID_LEN, FB_WIFI_SSID);
snprintf(mCfg.sys.stationPwd, PWD_LEN, FB_WIFI_PWD);
}
else {
cfgSys_t tmp;
cfgSys_t tmp;
if(keepWifi) {
// copy contents which should not be deleted
memset(&tmp.adminPwd, 0, PWD_LEN);
memcpy(&tmp, &mCfg.sys, sizeof(cfgSys_t));
memset(&mCfg, 0, sizeof(settings_t));
}
// erase all settings and reset to default
memset(&mCfg, 0, sizeof(settings_t));
// restore temp settings
if(keepWifi)
memcpy(&mCfg.sys, &tmp, sizeof(cfgSys_t));
else {
snprintf(mCfg.sys.stationSsid, SSID_LEN, FB_WIFI_SSID);
snprintf(mCfg.sys.stationPwd, PWD_LEN, FB_WIFI_PWD);
}
snprintf(mCfg.sys.deviceName, DEVNAME_LEN, DEF_DEVICE_NAME);
mCfg.nrf.sendInterval = SEND_INTERVAL;

2
src/defines.h

@ -13,7 +13,7 @@
//-------------------------------------
#define VERSION_MAJOR 0
#define VERSION_MINOR 5
#define VERSION_PATCH 55
#define VERSION_PATCH 56
//-------------------------------------
typedef struct {

1
src/web/RestApi.h

@ -203,6 +203,7 @@ class RestApi {
getMenu(obj.createNestedObject(F("menu")));
getSysInfo(obj.createNestedObject(F("system")));
obj[F("html")] = F("<a href=\"/factory\" class=\"btn\">Factory Reset</a><br/><br/><a href=\"/reboot\" class=\"btn\">Reboot</a>");
}
void getHtmlLogout(JsonObject obj) {

11
src/web/html/index.html

@ -31,11 +31,14 @@
}
</script>
<p><span class="des">Uptime: </span><span id="uptime"></span></p>
<p><span class="des">ESP-Time: </span><span id="date"></span></p>
<p>
<span class="des">Uptime: </span><span id="uptime"></span><br/>
<span class="des">ESP-Time: </span><span id="date"></span>
</p>
<div id="sun">
<span class="des">Sunrise: </span><span id="sunrise"></span><br>
<span class="des">Sunset: </span><span id="sunset"></span>
<span class="des">Communication</span><br/>
<span class="des">start: </span><span id="sunrise"></span><br>
<span class="des">stop: </span><span id="sunset"></span>
</div>
<p><span class="des">WiFi RSSI: </span><span id="wifi_rssi"></span> dBm</p>
<p>

11
src/web/html/system.html

@ -55,6 +55,7 @@
for (const [key, value] of Object.entries(obj)) {
if(!data.includes(key) || (typeof value == 'undefined')) continue;
var li = document.createElement("li");
li.appendChild()
li.appendChild(document.createTextNode(key + ": " + value));
ul.appendChild(li);
}
@ -86,10 +87,6 @@
if(null != obj) {
parseMenu(obj["menu"]);
parseSys(obj["system"]);
parseSysInfo(obj["system"]);
parseRadio(obj["system"]["radio"]);
var e = document.getElementById("system");
e.innerHTML = obj["html"];
if(null != obj["refresh"]) {
var meta = document.createElement('meta');
@ -97,6 +94,12 @@
meta.content = obj["refresh"] + "; URL=" + obj["refresh_url"];
document.getElementsByTagName('head')[0].appendChild(meta);
}
else {
parseSysInfo(obj["system"]);
parseRadio(obj["system"]["radio"]);
}
var e = document.getElementById("system");
e.innerHTML = obj["html"];
}
}

1
src/wifi/ahoywifi.cpp

@ -8,6 +8,7 @@
#define F(sl) (sl)
#endif
#include "ahoywifi.h"
#include <ESP8266HTTPClient.h>
// NTP CONFIG
#define NTP_PACKET_SIZE 48

Loading…
Cancel
Save