Skip to content

Commit 5ecfd3c

Browse files
author
Thorsten Ludewig
committed
use global buffer
1 parent bd17aea commit 5ecfd3c

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

lib/WebHandler/WebHandler.cpp

+10-6
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ WebHandler webHandler;
1414
static ESP8266WebServer server(80);
1515
size_t fsTotalBytes;
1616
size_t fsUsedBytes;
17-
char buffer[3000];
1817

1918
const char *getJsonStatus(WiFiClient *client)
2019
{
@@ -34,10 +33,16 @@ const char *getJsonStatus(WiFiClient *client)
3433
strncpy( remoteAddress, server.client().remoteIP().toString().c_str(), 31 );
3534
}
3635

37-
sprintf(buffer,
36+
if ( appBuffer == NULL )
37+
{
38+
appBuffer = (char *)malloc(APP_BUFFER_SIZE);
39+
memset(appBuffer, 0, APP_BUFFER_SIZE);
40+
}
41+
42+
sprintf(appBuffer,
3843
"{"
3944
"\"millis\":%lu,"
40-
"\"utc\":%lu,"
45+
"\"utc\":%llu,"
4146
"\"ctime\":\"%s\","
4247
"\"timezone\":\"%s\","
4348
"\"uptime\":\"%s\","
@@ -117,7 +122,7 @@ const char *getJsonStatus(WiFiClient *client)
117122
remotePort
118123
);
119124

120-
return buffer;
125+
return appBuffer;
121126
}
122127

123128
WebHandler::WebHandler()
@@ -143,8 +148,7 @@ void WebHandler::setup()
143148

144149
server.on("/", []() {
145150
server.sendHeader("Access-Control-Allow-Origin", "*");
146-
String message(getJsonStatus(NULL));
147-
server.send(200, "application/json", message );
151+
server.send(200, "application/json", getJsonStatus(NULL));
148152
} );
149153

150154
MDNS.addService("http", "tcp", 80);

0 commit comments

Comments
 (0)