Skip to content

Commit

Permalink
WTF - ESP.getFreeHeap crashing the system for an specific light bulb...
Browse files Browse the repository at this point in the history
  • Loading branch information
xoseperez committed Dec 3, 2017
1 parent bd86de0 commit 489d629
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 6 deletions.
2 changes: 1 addition & 1 deletion code/espurna/espurna.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion code/espurna/settings.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
});

Expand Down
10 changes: 9 additions & 1 deletion code/espurna/utils.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions code/espurna/web.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down
2 changes: 1 addition & 1 deletion code/espurna/ws.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down

0 comments on commit 489d629

Please sign in to comment.