Skip to content
This repository was archived by the owner on Feb 4, 2023. It is now read-only.

Commit 3e709a9

Browse files
authored
Improve AdvancedWebServer example
- Display more info about Heap: Free, Min, Max
1 parent 1f0e93f commit 3e709a9

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

examples/Async_AdvancedWebServer/Async_AdvancedWebServer.ino

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,17 @@ char temp[BUFFER_SIZE];
7474

7575
void handleRoot(AsyncWebServerRequest *request)
7676
{
77+
static uint32_t pageCount = 0;
78+
static uint32_t maxfreeHeap = 0;
79+
static uint32_t minFreeHeap = 0xFFFFFFFF;
80+
uint32_t curFreeHeap = rp2040.getFreeHeap();
81+
82+
if (maxfreeHeap < curFreeHeap)
83+
maxfreeHeap = curFreeHeap;
84+
85+
if (minFreeHeap > curFreeHeap)
86+
minFreeHeap = curFreeHeap;
87+
7788
digitalWrite(LED_BUILTIN, LED_ON);
7889

7990
int sec = millis() / 1000;
@@ -84,7 +95,7 @@ void handleRoot(AsyncWebServerRequest *request)
8495
snprintf(temp, BUFFER_SIZE - 1,
8596
"<html>\
8697
<head>\
87-
<meta http-equiv='refresh' content='60'/>\
98+
<meta http-equiv='refresh' content='5'/>\
8899
<title>AsyncWebServer-%s</title>\
89100
<style>\
90101
body { background-color: #cccccc; font-family: Arial, Helvetica, Sans-Serif; Color: #000088; }\
@@ -93,10 +104,11 @@ body { background-color: #cccccc; font-family: Arial, Helvetica, Sans-Serif; Col
93104
<body>\
94105
<h2>AsyncWebServer_RP2040W!</h2>\
95106
<h3>running WiFi on %s</h3>\
96-
<p>Uptime: %d d %02d:%02d:%02d</p>\
107+
<p>Uptime: %d d %02d:%02d:%02d, pageCount: %lu</p>\
108+
<p>Heap Free: %lu, Max: %lu, Min: %lu</p>\
97109
<img src=\"/test.svg\" />\
98110
</body>\
99-
</html>", BOARD_NAME, BOARD_NAME, day, hr % 24, min % 60, sec % 60);
111+
</html>", BOARD_NAME, BOARD_NAME, day, hr % 24, min % 60, sec % 60, ++pageCount, curFreeHeap, maxfreeHeap, minFreeHeap);
100112

101113
request->send(200, "text/html", temp);
102114

@@ -241,7 +253,7 @@ void setup()
241253

242254
server.begin();
243255

244-
Serial.print(F("HTTP EthernetWebServer is @ IP : "));
256+
Serial.print(F("AsyncWebServer is @ IP : "));
245257
Serial.println(WiFi.localIP());
246258
}
247259

0 commit comments

Comments
 (0)