diff --git a/code/espurna/espurna.ino b/code/espurna/espurna.ino index 65fdf131..93572858 100644 --- a/code/espurna/espurna.ino +++ b/code/espurna/espurna.ino @@ -212,7 +212,7 @@ void welcome() { DEBUG_MSG_P(PSTR("[INIT] Last reset reason: %s\n"), (char *) ESP.getResetReason().c_str()); } - DEBUG_MSG_P(PSTR("[INIT] Free heap: %u bytes\n"), ESP.getFreeHeap()); + DEBUG_MSG_P(PSTR("[INIT] Free heap: %u bytes\n"), getFreeHeap()); #if ADC_VCC_ENABLED DEBUG_MSG_P(PSTR("[INIT] Power: %d mV\n"), ESP.getVcc()); #endif diff --git a/code/espurna/settings.ino b/code/espurna/settings.ino index cd61a15c..d277e97e 100644 --- a/code/espurna/settings.ino +++ b/code/espurna/settings.ino @@ -175,7 +175,7 @@ void settingsSetup() { }); Embedis::command( F("HEAP"), [](Embedis* e) { - DEBUG_MSG_P(PSTR("Free HEAP: %d bytes\n"), ESP.getFreeHeap()); + DEBUG_MSG_P(PSTR("Free HEAP: %d bytes\n"), getFreeHeap()); DEBUG_MSG_P(PSTR("+OK\n")); }); diff --git a/code/espurna/utils.ino b/code/espurna/utils.ino index db64e781..0f557bc4 100644 --- a/code/espurna/utils.ino +++ b/code/espurna/utils.ino @@ -33,6 +33,14 @@ String getCoreRevision() { #endif } +// WTF +// Calling ESP.getFreeHeap() is making the system crash on a specific +// AiLight bulb, but anywhere else... +unsigned int getFreeHeap() { + if (getSetting("wtfHeap", 0).toInt() == 1) return 9999; + return ESP.getFreeHeap(); +} + String buildTime() { const char time_now[] = __TIME__; // hh:mm:ss @@ -79,7 +87,7 @@ unsigned long getUptime() { void heartbeat() { unsigned long uptime_seconds = getUptime(); - unsigned int free_heap = ESP.getFreeHeap(); + unsigned int free_heap = getFreeHeap(); // ------------------------------------------------------------------------- // MQTT diff --git a/code/espurna/web.ino b/code/espurna/web.ino index c9a27202..ab847b40 100644 --- a/code/espurna/web.ino +++ b/code/espurna/web.ino @@ -75,8 +75,8 @@ void _onHome(AsyncWebServerRequest *request) { // Chunked response, we calculate the chunks based on free heap (in multiples of 32) // This is necessary when a TLS connection is open since it sucks too much memory - DEBUG_MSG_P(PSTR("[MAIN] Free heap: %d bytes\n"), ESP.getFreeHeap()); - size_t max = (ESP.getFreeHeap() / 3) & 0xFFE0; + DEBUG_MSG_P(PSTR("[MAIN] Free heap: %d bytes\n"), getFreeHeap()); + size_t max = (getFreeHeap() / 3) & 0xFFE0; AsyncWebServerResponse *response = request->beginChunkedResponse("text/html", [max](uint8_t *buffer, size_t maxLen, size_t index) -> size_t { diff --git a/code/espurna/ws.ino b/code/espurna/ws.ino index a103bb24..7225f919 100644 --- a/code/espurna/ws.ino +++ b/code/espurna/ws.ino @@ -333,7 +333,7 @@ void _wsStart(uint32_t client_id) { root["network"] = getNetwork(); root["deviceip"] = getIP(); root["uptime"] = getUptime(); - root["heap"] = ESP.getFreeHeap(); + root["heap"] = getFreeHeap(); root["sketch_size"] = ESP.getSketchSize(); root["free_size"] = ESP.getFreeSketchSpace();