Skip to content

Commit 3f57982

Browse files
Andrew MelvinAndrew Melvin
Andrew Melvin
authored and
Andrew Melvin
committed
ready
1 parent 6357e6e commit 3f57982

File tree

4 files changed

+23
-2
lines changed

4 files changed

+23
-2
lines changed

HTTPPrinter.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,9 @@ void HTTPPrinter::SendPage() {
241241
Serial.printf(" %u variables inserted (%ums)\n", count, millis()-_time);
242242

243243
}
244+
245+
EndPage();
246+
244247
}
245248

246249
void HTTPPrinter::EndPage() {

HTTPPrinter.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ class HTTPPrinter: public Print
6161
void BeginPage(WiFiClient & c, fs::FS& fs, const char* path, uint8_t items);
6262
void SendPage();
6363
bool AddVariable(uint8_t n, const char * field, const char * text);
64-
void EndPage();
6564

6665
void End();
6766
void Setsize(size_t s);
@@ -77,6 +76,7 @@ class HTTPPrinter: public Print
7776
private:
7877
virtual size_t write(uint8_t);
7978
void Send_Header (int code, const char * content );
79+
void EndPage();
8080

8181
struct HTTP_Vars_t {
8282
//char * field[32];

examples/DynamicPage/DynamicPage.ino

+1-1
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ void OTA_handle(){
195195

196196

197197
//format bytes
198+
// Thanks to me-no-dev
198199
String formatBytes(size_t bytes){
199200
if (bytes < 1024){
200201
return String(bytes)+"B";
@@ -281,7 +282,6 @@ printer.BeginPage(c, SPIFFS, "/aboutdevice.htm", 30); // create the page, and s
281282

282283

283284
printer.SendPage();
284-
printer.EndPage();
285285

286286
Serial.printf("Sent page %ums, heap = %u B\n", millis() - _time, ESP.getFreeHeap());
287287

examples/DynamicPage/README.md

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
This is a library that allows you to inject dynamic content into SPIFFS files, for ESP8266 environment.
2+
3+
4+
The SPIFFS upload tool must be used to upload the contents of the data directory to the ESP.
5+
6+
7+
Create object :
8+
```
9+
HTTPPrinter printer;
10+
```
11+
12+
Then in webpage callback,
13+
```
14+
WiFiClient c = HTTP.client();
15+
printer.BeginPage(c, SPIFFS, "/file", 30); BeginPage(WiFiClient & c, fs::FS& fs, const char* path, uint8_t items);
16+
printer.AddVariable(0, "version", version); AddVariable(uint8_t n, const char * field, const char * text);
17+
printer.SendPage(); // sends the page, reclaims the memory..
18+
```

0 commit comments

Comments
 (0)