Skip to content

Commit

Permalink
0.8.134
Browse files Browse the repository at this point in the history
* redesigned `/system`
  • Loading branch information
lumapu committed Aug 11, 2024
1 parent a770243 commit 5b6ffcc
Show file tree
Hide file tree
Showing 12 changed files with 275 additions and 145 deletions.
1 change: 1 addition & 0 deletions src/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## 0.8.134 - 2024-08-10
* combined Ethernet and WiFi variants - Ethernet is now always included, but needs to be enabled if needed
* improved statistic data in `/system`
* redesigned `/system`

## 0.8.133 - 2024-08-10
* Ethernet variants now support WiFi as fall back / configuration
Expand Down
4 changes: 4 additions & 0 deletions src/app.h
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,10 @@ class app : public IApp, public ah::Scheduler {
return mNetwork->getIp();
}

String getMac(void) override {
return mNetwork->getMac();
}

bool isApActive(void) override {
return mNetwork->isApActive();
}
Expand Down
1 change: 1 addition & 0 deletions src/appInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class IApp {
virtual void setupStation(void) = 0;
virtual bool getWasInCh12to14(void) const = 0;
virtual String getIp(void) = 0;
virtual String getMac(void) = 0;
virtual bool isApActive(void) = 0;

virtual uint32_t getUptime() = 0;
Expand Down
7 changes: 7 additions & 0 deletions src/network/AhoyEthernet.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ class AhoyEthernet : public AhoyWifi {
return ETH.localIP().toString();
}

String getMac(void) {
if(Mode::WIRELESS == mMode)
return AhoyWifi::getMac();
else
return ETH.macAddress();
}

bool isWiredConnection() {
return (Mode::WIRED == mMode);
}
Expand Down
1 change: 1 addition & 0 deletions src/network/AhoyNetwork.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ class AhoyNetwork {
virtual void begin() = 0;
virtual void tickNetworkLoop() = 0;
virtual String getIp(void) = 0;
virtual String getMac(void) = 0;

virtual bool getWasInCh12to14() {
return false;
Expand Down
24 changes: 14 additions & 10 deletions src/network/AhoyWifiEsp32.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,20 @@ class AhoyWifi : public AhoyNetwork {
#endif
}

void tickNetworkLoop() override {
if(mAp.isEnabled())
mAp.tickLoop();
}

String getIp(void) override {
return WiFi.localIP().toString();
}

String getMac(void) override {
return WiFi.macAddress();
}

private:
virtual void OnEvent(WiFiEvent_t event) override {
switch(event) {
case SYSTEM_EVENT_STA_CONNECTED:
Expand Down Expand Up @@ -78,16 +92,6 @@ class AhoyWifi : public AhoyNetwork {
}
}

void tickNetworkLoop() override {
if(mAp.isEnabled())
mAp.tickLoop();
}

String getIp(void) override {
return WiFi.localIP().toString();
}

private:
virtual void setStaticIp() override {
setupIp([this](IPAddress ip, IPAddress gateway, IPAddress mask, IPAddress dns1, IPAddress dns2) -> bool {
return WiFi.config(ip, gateway, mask, dns1, dns2);
Expand Down
4 changes: 4 additions & 0 deletions src/network/AhoyWifiEsp8266.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ class AhoyWifi : public AhoyNetwork {
return WiFi.localIP().toString();
}

String getMac(void) override {
return WiFi.macAddress();
}

bool getWasInCh12to14() override {
return mWasInCh12to14;
}
Expand Down
198 changes: 103 additions & 95 deletions src/web/RestApi.h
Original file line number Diff line number Diff line change
Expand Up @@ -413,109 +413,22 @@ class RestApi {
}

void getSysInfo(AsyncWebServerRequest *request, JsonObject obj) {
obj[F("ap_pwd")] = mConfig->sys.apPwd;
obj[F("ssid")] = mConfig->sys.stationSsid;
obj[F("hidd")] = mConfig->sys.isHidden;
obj[F("mac")] = WiFi.macAddress();
obj[F("wifi_channel")] = WiFi.channel();
obj[F("device_name")] = mConfig->sys.deviceName;
obj[F("dark_mode")] = (bool)mConfig->sys.darkMode;
obj[F("sched_reboot")] = (bool)mConfig->sys.schedReboot;

obj[F("pwd_set")] = (strlen(mConfig->sys.adminPwd) > 0);
obj[F("prot_mask")] = mConfig->sys.protectionMask;

obj[F("sdk")] = ESP.getSdkVersion();
obj[F("cpu_freq")] = ESP.getCpuFreqMHz();
obj[F("heap_free")] = mHeapFree;
getGeneric(request, obj);

getGeneric(request, obj.createNestedObject(F("generic")));
getChipInfo(obj.createNestedObject(F("chip")));
getRadioNrf(obj.createNestedObject(F("radioNrf")));
getMqttInfo(obj.createNestedObject(F("mqtt")));
getNetworkInfo(obj.createNestedObject(F("network")));
getMemoryInfo(obj.createNestedObject(F("memory")));
#if defined(ESP32)
getRadioCmtInfo(obj.createNestedObject(F("radioCmt")));
#endif
getMqttInfo(obj.createNestedObject(F("mqtt")));

#if defined(ETHERNET)
getEthernetInfo(obj.createNestedObject(F("eth")));
#endif

obj[F("heap_frag")] = mHeapFrag;
obj[F("max_free_blk")] = mHeapFreeBlk;

#if defined(ESP32)
obj[F("chip_revision")] = ESP.getChipRevision();
obj[F("chip_model")] = ESP.getChipModel();
obj[F("chip_cores")] = ESP.getChipCores();
obj[F("heap_total")] = ESP.getHeapSize();
//obj[F("core_version")] = F("n/a");

esp_reset_reason_t reason = esp_reset_reason();

// Reboot-Grund ausgeben
switch (reason) {
default:
[[fallthrough]];
case ESP_RST_UNKNOWN:
obj[F("reboot_reason")] = F("Unknown");
break;
case ESP_RST_POWERON:
obj[F("reboot_reason")] = F("Power on");
break;
case ESP_RST_EXT:
obj[F("reboot_reason")] = F("External");
break;
case ESP_RST_SW:
obj[F("reboot_reason")] = F("Software");
break;
case ESP_RST_PANIC:
obj[F("reboot_reason")] = F("Panic");
break;
case ESP_RST_INT_WDT:
obj[F("reboot_reason")] = F("Interrupt Watchdog");
break;
case ESP_RST_TASK_WDT:
obj[F("reboot_reason")] = F("Task Watchdog");
break;
case ESP_RST_WDT:
obj[F("reboot_reason")] = F("Watchdog");
break;
case ESP_RST_DEEPSLEEP:
obj[F("reboot_reason")] = F("Deepsleep");
break;
case ESP_RST_BROWNOUT:
obj[F("reboot_reason")] = F("Brownout");
break;
case ESP_RST_SDIO:
obj[F("reboot_reason")] = F("SDIO");
break;
}

const esp_partition_t *partition = esp_partition_find_first(ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_COREDUMP, "coredump");
if (partition != NULL)
obj[F("flash_size")] = partition->address + partition->size;
#else
//obj[F("heap_total")] = F("n/a");
//obj[F("chip_revision")] = F("n/a");
//obj[F("chip_model")] = F("n/a");
//obj[F("chip_cores")] = F("n/a");
obj[F("core_version")] = ESP.getCoreVersion();
obj[F("flash_size")] = ESP.getFlashChipRealSize() / 1024; // in kb
obj[F("reboot_reason")] = ESP.getResetReason();
#endif

#if !defined(ESP32)
FSInfo info;
LittleFS.info(info);
obj[F("par_used_spiffs")] = info.usedBytes;
obj[F("par_size_spiffs")] = info.totalBytes;
#else
obj[F("par_size_spiffs")] = LittleFS.totalBytes();
obj[F("par_used_spiffs")] = LittleFS.usedBytes();
#endif

obj[F("par_size_app0")] = ESP.getFreeSketchSpace();
obj[F("par_used_app0")] = ESP.getSketchSize();

/*uint8_t max;
mApp->getSchedulerInfo(&max);
Expand Down Expand Up @@ -885,11 +798,106 @@ class RestApi {
obj[F("irq")] = mConfig->sys.eth.pinIrq;
obj[F("reset")] = mConfig->sys.eth.pinRst;
}
#endif

void getNetworkInfo(JsonObject obj) {
#if defined(ESP32)
bool isWired = mApp->isWiredConnection();
if(!isWired)
obj[F("wifi_channel")] = WiFi.channel();
#else
obj[F("wifi_channel")] = WiFi.channel();
#endif

void getEthernetInfo(JsonObject obj) {
obj[F("wired")] = (bool)mApp->isWiredConnection();
obj[F("ap_pwd")] = mConfig->sys.apPwd;
obj[F("ssid")] = mConfig->sys.stationSsid;
obj[F("hidd")] = mConfig->sys.isHidden;
obj[F("mac")] = mApp->getMac();
obj[F("ip")] = mApp->getIp();

#if defined(ESP32)
obj[F("wired")] = isWired;
#endif
}

void getChipInfo(JsonObject obj) {
obj[F("cpu_freq")] = ESP.getCpuFreqMHz();
obj[F("sdk")] = ESP.getSdkVersion();
#if defined(ESP32)
obj[F("revision")] = ESP.getChipRevision();
obj[F("model")] = ESP.getChipModel();
obj[F("cores")] = ESP.getChipCores();

switch (esp_reset_reason()) {
default:
[[fallthrough]];
case ESP_RST_UNKNOWN:
obj[F("reboot_reason")] = F("Unknown");
break;
case ESP_RST_POWERON:
obj[F("reboot_reason")] = F("Power on");
break;
case ESP_RST_EXT:
obj[F("reboot_reason")] = F("External");
break;
case ESP_RST_SW:
obj[F("reboot_reason")] = F("Software");
break;
case ESP_RST_PANIC:
obj[F("reboot_reason")] = F("Panic");
break;
case ESP_RST_INT_WDT:
obj[F("reboot_reason")] = F("Interrupt Watchdog");
break;
case ESP_RST_TASK_WDT:
obj[F("reboot_reason")] = F("Task Watchdog");
break;
case ESP_RST_WDT:
obj[F("reboot_reason")] = F("Watchdog");
break;
case ESP_RST_DEEPSLEEP:
obj[F("reboot_reason")] = F("Deepsleep");
break;
case ESP_RST_BROWNOUT:
obj[F("reboot_reason")] = F("Brownout");
break;
case ESP_RST_SDIO:
obj[F("reboot_reason")] = F("SDIO");
break;
}
#else
obj[F("core_version")] = ESP.getCoreVersion();
obj[F("reboot_reason")] = ESP.getResetReason();
#endif
}

void getMemoryInfo(JsonObject obj) {
obj[F("heap_frag")] = mHeapFrag;
obj[F("heap_max_free_blk")] = mHeapFreeBlk;
obj[F("heap_free")] = mHeapFree;

obj[F("par_size_app0")] = ESP.getFreeSketchSpace();
obj[F("par_used_app0")] = ESP.getSketchSize();

#if defined(ESP32)
obj[F("heap_total")] = ESP.getHeapSize();

const esp_partition_t *partition = esp_partition_find_first(ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_COREDUMP, "coredump");
if (partition != NULL)
obj[F("flash_size")] = partition->address + partition->size;

obj[F("par_size_spiffs")] = LittleFS.totalBytes();
obj[F("par_used_spiffs")] = LittleFS.usedBytes();
#else
obj[F("flash_size")] = ESP.getFlashChipRealSize();

FSInfo info;
LittleFS.info(info);
obj[F("par_used_spiffs")] = info.usedBytes;
obj[F("par_size_spiffs")] = info.totalBytes;
obj[F("heap_total")] = 24*1014; // FIXME: don't know correct value
#endif
}
#endif

void getRadioNrf(JsonObject obj) {
obj[F("en")] = (bool) mConfig->nrf.enabled;
Expand Down
4 changes: 4 additions & 0 deletions src/web/html/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,10 @@ function badge(success, text, second="error") {
return ml("span", {class: "badge badge-" + ((success) ? "success" : second)}, text);
}

function progress(val) {
return ml("div", {class: "progress"}, ml("div", {class: "progress-bar", style: "width: " + val + "%"}, null))
}

function tabChange(id) {
var els = document.getElementsByClassName("nav-link");
[].forEach.call(els, function(e) {
Expand Down
13 changes: 13 additions & 0 deletions src/web/html/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -859,3 +859,16 @@ ul {
height: 100%;
overflow: auto;
}

.progress {
display: flex;
height: 1rem;
overflow: hidden;
background-color: #e9ecef;
border-radius: .25rem;
}

.progress-bar {
display: flex;
background-color: var(--primary);
}
Loading

0 comments on commit 5b6ffcc

Please sign in to comment.