mirror of
https://github.com/lumapu/ahoy.git
synced 2025-07-19 01:07:15 +02:00
added part of mac address to MQTT client ID to seperate multiple ESPs in same network added dictionary for MQTT to reduce heap-fragmentation removed `last Alarm` from Live view, because it showed always the same alarm - will change in future
This commit is contained in:
parent
fe54599502
commit
a0879cfcbe
17 changed files with 393 additions and 148 deletions
|
@ -1,3 +1,8 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// 2023 Ahoy, https://ahoydtu.de
|
||||
// Creative Commons - http://creativecommons.org/licenses/by-nc-sa/3.0/de/
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef __WEB_API_H__
|
||||
#define __WEB_API_H__
|
||||
|
||||
|
@ -24,7 +29,9 @@ class RestApi {
|
|||
public:
|
||||
RestApi() {
|
||||
mTimezoneOffset = 0;
|
||||
mFreeHeap = 0;
|
||||
mHeapFree = 0;
|
||||
mHeapFreeBlk = 0;
|
||||
mHeapFrag = 0;
|
||||
nr = 0;
|
||||
}
|
||||
|
||||
|
@ -49,7 +56,7 @@ class RestApi {
|
|||
serializeJson(obj, out, 128);
|
||||
DPRINTLN(DBG_INFO, "RestApi: " + String(out));*/
|
||||
DynamicJsonDocument json(128);
|
||||
JsonObject dummy = json.to<JsonObject>();
|
||||
JsonObject dummy = json.as<JsonObject>();
|
||||
if(obj[F("path")] == "ctrl")
|
||||
setCtrl(obj, dummy);
|
||||
else if(obj[F("path")] == "setup")
|
||||
|
@ -58,7 +65,11 @@ class RestApi {
|
|||
|
||||
private:
|
||||
void onApi(AsyncWebServerRequest *request) {
|
||||
mFreeHeap = ESP.getFreeHeap();
|
||||
mHeapFree = ESP.getFreeHeap();
|
||||
#ifndef ESP32
|
||||
mHeapFreeBlk = ESP.getMaxFreeBlockSize();
|
||||
mHeapFrag = ESP.getHeapFragmentation();
|
||||
#endif
|
||||
|
||||
AsyncJsonResponse* response = new AsyncJsonResponse(false, 8192);
|
||||
JsonObject root = response->getRoot();
|
||||
|
@ -84,6 +95,7 @@ class RestApi {
|
|||
else
|
||||
getNotFound(root, F("http://") + request->host() + F("/api/"));
|
||||
|
||||
//DPRINTLN(DBG_INFO, "API mem usage: " + String(root.memoryUsage()));
|
||||
response->addHeader("Access-Control-Allow-Origin", "*");
|
||||
response->addHeader("Access-Control-Allow-Headers", "content-type");
|
||||
response->setLength();
|
||||
|
@ -194,7 +206,7 @@ class RestApi {
|
|||
|
||||
obj[F("sdk")] = ESP.getSdkVersion();
|
||||
obj[F("cpu_freq")] = ESP.getCpuFreqMHz();
|
||||
obj[F("heap_free")] = mFreeHeap;
|
||||
obj[F("heap_free")] = mHeapFree;
|
||||
obj[F("sketch_total")] = ESP.getFreeSketchSpace();
|
||||
obj[F("sketch_used")] = ESP.getSketchSize() / 1024; // in kb
|
||||
getGeneric(obj);
|
||||
|
@ -219,8 +231,8 @@ class RestApi {
|
|||
//obj[F("chip_cores")] = F("n/a");
|
||||
obj[F("core_version")] = ESP.getCoreVersion();
|
||||
obj[F("flash_size")] = ESP.getFlashChipRealSize() / 1024; // in kb
|
||||
obj[F("heap_frag")] = ESP.getHeapFragmentation();
|
||||
obj[F("max_free_blk")] = ESP.getMaxFreeBlockSize();
|
||||
obj[F("heap_frag")] = mHeapFrag;
|
||||
obj[F("max_free_blk")] = mHeapFreeBlk;
|
||||
obj[F("reboot_reason")] = ESP.getResetReason();
|
||||
#endif
|
||||
//obj[F("littlefs_total")] = LittleFS.totalBytes();
|
||||
|
@ -498,7 +510,7 @@ class RestApi {
|
|||
obj2[F("name")] = String(iv->config->name);
|
||||
obj2[F("channels")] = iv->channels;
|
||||
obj2[F("power_limit_read")] = ah::round3(iv->actPowerLimit);
|
||||
obj2[F("last_alarm")] = String(iv->lastAlarmMsg);
|
||||
//obj2[F("last_alarm")] = String(iv->lastAlarmMsg);
|
||||
obj2[F("ts_last_success")] = rec->ts;
|
||||
|
||||
JsonArray ch = obj2.createNestedArray("ch");
|
||||
|
@ -625,7 +637,8 @@ class RestApi {
|
|||
settings_t *mConfig;
|
||||
|
||||
uint32_t mTimezoneOffset;
|
||||
uint32_t mFreeHeap;
|
||||
uint32_t mHeapFree, mHeapFreeBlk;
|
||||
uint8_t mHeapFrag;
|
||||
uint16_t nr;
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue