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

Commit 7f242b2

Browse files
authored
v1.4.0 to reduce String usage
### Major Releases v1.4.0 1. Reduce usage of Arduino String with std::string 2. Optimize library code and examples by using **reference-passing instead of value-passing**. 3. Fix bug related to String in library and examples 4. Update `Packages' Patches`
1 parent 53ddf77 commit 7f242b2

File tree

1 file changed

+73
-15
lines changed

1 file changed

+73
-15
lines changed

README.md

Lines changed: 73 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1252,7 +1252,7 @@ void handleRoot()
12521252
{
12531253
digitalWrite(led, 1);
12541254

1255-
#define BUFFER_SIZE 400
1255+
#define BUFFER_SIZE 512
12561256

12571257
char temp[BUFFER_SIZE];
12581258
int sec = millis() / 1000;
@@ -1305,29 +1305,54 @@ void handleNotFound()
13051305
digitalWrite(led, 0);
13061306
}
13071307

1308+
#define ORIGINAL_STR_LEN 2048
1309+
13081310
void drawGraph()
13091311
{
1310-
String out;
1311-
out.reserve(3000);
1312+
static String out;
1313+
static uint16_t previousStrLen = ORIGINAL_STR_LEN;
1314+
1315+
if (out.length() == 0)
1316+
{
1317+
ET_LOGWARN1(F("String Len = 0, extend to"), ORIGINAL_STR_LEN);
1318+
out.reserve(ORIGINAL_STR_LEN);
1319+
}
1320+
1321+
out = F( "<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\" width=\"310\" height=\"150\">\n" \
1322+
"<rect width=\"310\" height=\"150\" fill=\"rgb(250, 230, 210)\" stroke-width=\"3\" stroke=\"rgb(0, 0, 0)\" />\n" \
1323+
"<g stroke=\"blue\">\n");
1324+
13121325
char temp[70];
1313-
out += "<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\" width=\"310\" height=\"150\">\n";
1314-
out += "<rect width=\"310\" height=\"150\" fill=\"rgb(250, 230, 210)\" stroke-width=\"1\" stroke=\"rgb(0, 0, 0)\" />\n";
1315-
out += "<g stroke=\"black\">\n";
1326+
13161327
int y = rand() % 130;
13171328

13181329
for (int x = 10; x < 300; x += 10)
13191330
{
13201331
int y2 = rand() % 130;
1321-
sprintf(temp, "<line x1=\"%d\" y1=\"%d\" x2=\"%d\" y2=\"%d\" stroke-width=\"1\" />\n", x, 140 - y, x + 10, 140 - y2);
1332+
sprintf(temp, "<line x1=\"%d\" y1=\"%d\" x2=\"%d\" y2=\"%d\" stroke-width=\"2\" />\n", x, 140 - y, x + 10, 140 - y2);
13221333
out += temp;
13231334
y = y2;
13241335
}
1325-
out += "</g>\n</svg>\n";
1336+
1337+
out += F("</g>\n</svg>\n");
1338+
1339+
ET_LOGDEBUG1(F("String Len = "), out.length());
1340+
1341+
if (out.length() > previousStrLen)
1342+
{
1343+
ET_LOGERROR3(F("String Len > "), previousStrLen, F(", extend to"), out.length() + 48);
13261344

1327-
server.send(200, "image/svg+xml", out);
1345+
previousStrLen = out.length() + 48;
1346+
1347+
out.reserve(previousStrLen);
1348+
}
1349+
else
1350+
{
1351+
server.send(200, "image/svg+xml", out);
1352+
}
13281353
}
13291354

1330-
void setup(void)
1355+
void setup()
13311356
{
13321357
pinMode(led, OUTPUT);
13331358
digitalWrite(led, 0);
@@ -1389,9 +1414,42 @@ void setup(void)
13891414
Serial.println(Ethernet.localIP());
13901415
}
13911416

1392-
void loop(void)
1417+
1418+
void heartBeatPrint()
1419+
{
1420+
static int num = 1;
1421+
1422+
Serial.print(F("."));
1423+
1424+
if (num == 80)
1425+
{
1426+
Serial.println();
1427+
num = 1;
1428+
}
1429+
else if (num++ % 10 == 0)
1430+
{
1431+
Serial.print(F(" "));
1432+
}
1433+
}
1434+
1435+
void check_status()
1436+
{
1437+
static unsigned long checkstatus_timeout = 0;
1438+
1439+
#define STATUS_CHECK_INTERVAL 10000L
1440+
1441+
// Send status report every STATUS_REPORT_INTERVAL (60) seconds: we don't need to send updates frequently if there is no status change.
1442+
if ((millis() > checkstatus_timeout) || (checkstatus_timeout == 0))
1443+
{
1444+
heartBeatPrint();
1445+
checkstatus_timeout = millis() + STATUS_CHECK_INTERVAL;
1446+
}
1447+
}
1448+
1449+
void loop()
13931450
{
13941451
server.handleClient();
1452+
check_status();
13951453
}
13961454
```
13971455
@@ -1415,8 +1473,8 @@ void loop(void)
14151473
// If USE_BUILTIN_ETHERNET == false and USE_UIP_ETHERNET == false =>
14161474
// either use W5x00 with EthernetXYZ library
14171475
// or ENC28J60 with EthernetENC library
1418-
//#define USE_BUILTIN_ETHERNET true
1419-
#define USE_BUILTIN_ETHERNET false
1476+
#define USE_BUILTIN_ETHERNET true
1477+
//#define USE_BUILTIN_ETHERNET false
14201478
14211479
//#define USE_UIP_ETHERNET true
14221480
#define USE_UIP_ETHERNET false
@@ -1432,9 +1490,9 @@ void loop(void)
14321490
#define USE_ETHERNET false //true
14331491
#define USE_ETHERNET2 false //true
14341492
#define USE_ETHERNET3 false //true
1435-
#define USE_ETHERNET_LARGE false
1493+
#define USE_ETHERNET_LARGE true
14361494
#define USE_ETHERNET_ESP8266 false //true
1437-
#define USE_ETHERNET_ENC true
1495+
#define USE_ETHERNET_ENC false
14381496
#define USE_CUSTOM_ETHERNET false
14391497
#endif
14401498

0 commit comments

Comments
 (0)