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

Commit e6a2d5c

Browse files
authored
v1.5.0 to reduce String usage
### Major Releases v1.5.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. Update `Packages' Patches` 4. Add more ESP32/ESP8266 supporting code
1 parent 2a1309b commit e6a2d5c

38 files changed

+1077
-246
lines changed

CONTRIBUTING.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ If you don't find anything, please [open a new issue](https://github.com/khoih-p
1414

1515
Please ensure to specify the following:
1616

17-
* Arduino IDE version (e.g. 1.8.16) or Platform.io version
18-
* `SAMD` Core Version (e.g. Arduino SAMD core v1.8.11, Adafruit SAMD core v1.7.5, Seeed Studio SAMD v1.8.2)
17+
* Arduino IDE version (e.g. 1.8.18) or Platform.io version
18+
* Board Core Version (e.g. Arduino SAMDUE core v1.6.12, ESP8266 core v3.0.2, ArduinoCore-mbed v2.6.1, etc.)
1919
* Contextual information (e.g. what you were trying to achieve)
2020
* Simplest possible steps to reproduce
2121
* Anything that might be relevant in your opinion, such as:
@@ -26,10 +26,11 @@ Please ensure to specify the following:
2626
### Example
2727

2828
```
29-
Arduino IDE version: 1.8.16
30-
Arduino SAMD Core Version 1.8.11
29+
Arduino IDE version: 1.8.18
30+
RASPBERRY_PI_PICO board
31+
ArduinoCore-mbed v2.6.1
3132
OS: Ubuntu 20.04 LTS
32-
Linux xy-Inspiron-3593 5.4.0-88-generic #99-Ubuntu SMP Thu Sep 23 17:29:00 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
33+
Linux xy-Inspiron-3593 5.4.0-91-generic #102-Ubuntu SMP Fri Nov 5 16:31:28 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
3334
3435
Context:
3536
I encountered an endless loop while trying to connect to Local WiFi.

README.md

Lines changed: 114 additions & 102 deletions
Large diffs are not rendered by default.

changelog.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
## Table of Contents
1313

1414
* [Changelog](#changelog)
15+
* [Major Releases v1.5.0](#major-releases-v150)
1516
* [Releases v1.4.2](#releases-v142)
1617
* [Releases v1.4.1](#releases-v141)
1718
* [Major Releases v1.4.0](#major-releases-v140)
@@ -34,6 +35,13 @@
3435

3536
## Changelog
3637

38+
### Major Releases v1.5.0
39+
40+
1. Reduce usage of Arduino String with std::string
41+
2. Optimize library code and examples by using **reference-passing instead of value-passing**.
42+
3. Update `Packages' Patches`
43+
4. Add more ESP32/ESP8266 supporting code
44+
3745
### Releases v1.4.2
3846

3947
1. Update `platform.ini` and `library.json` to use original `khoih-prog` instead of `khoih.prog` after PIO fix

examples/AdvancedWebServer/AdvancedWebServer.ino

Lines changed: 67 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,37 @@ void handleNotFound()
104104
digitalWrite(led, 0);
105105
}
106106

107+
#if (defined(WIFI_WEBSERVER_VERSION_INT) && (WIFI_WEBSERVER_VERSION_INT >= 1005000))
108+
109+
WWString initHeader = "<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\" width=\"310\" height=\"150\">\n" \
110+
"<rect width=\"310\" height=\"150\" fill=\"rgb(250, 230, 210)\" stroke-width=\"3\" stroke=\"rgb(0, 0, 0)\" />\n" \
111+
"<g stroke=\"blue\">\n";
112+
113+
void drawGraph()
114+
{
115+
WWString out;
116+
117+
out.reserve(3000);
118+
char temp[70];
119+
120+
out += initHeader;
121+
122+
int y = rand() % 130;
123+
124+
for (int x = 10; x < 300; x += 10)
125+
{
126+
int y2 = rand() % 130;
127+
sprintf(temp, "<line x1=\"%d\" y1=\"%d\" x2=\"%d\" y2=\"%d\" stroke-width=\"2\" />\n", x, 140 - y, x + 10, 140 - y2);
128+
out += temp;
129+
y = y2;
130+
}
131+
out += "</g>\n</svg>\n";
132+
133+
server.send(200, "image/svg+xml", fromWWString(out));
134+
}
135+
136+
#else
137+
107138
void drawGraph()
108139
{
109140
String out;
@@ -127,7 +158,9 @@ void drawGraph()
127158
server.send(200, F("image/svg+xml"), out);
128159
}
129160

130-
void setup(void)
161+
#endif
162+
163+
void setup()
131164
{
132165
pinMode(led, OUTPUT);
133166
digitalWrite(led, 0);
@@ -220,7 +253,39 @@ void setup(void)
220253
Serial.println(WiFi.localIP());
221254
}
222255

223-
void loop(void)
256+
void heartBeatPrint()
257+
{
258+
static int num = 1;
259+
260+
Serial.print(F("H"));
261+
262+
if (num == 80)
263+
{
264+
Serial.println();
265+
num = 1;
266+
}
267+
else if (num++ % 10 == 0)
268+
{
269+
Serial.print(F(" "));
270+
}
271+
}
272+
273+
void check_status()
274+
{
275+
static unsigned long checkstatus_timeout = 0;
276+
277+
#define STATUS_CHECK_INTERVAL 60000L
278+
279+
// Send status report every STATUS_REPORT_INTERVAL (60) seconds: we don't need to send updates frequently if there is no status change.
280+
if ((millis() > checkstatus_timeout) || (checkstatus_timeout == 0))
281+
{
282+
heartBeatPrint();
283+
checkstatus_timeout = millis() + STATUS_CHECK_INTERVAL;
284+
}
285+
}
286+
287+
void loop()
224288
{
225289
server.handleClient();
290+
check_status();
226291
}

examples/HelloServer/HelloServer.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ void handleNotFound()
7474
digitalWrite(led, 0);
7575
}
7676

77-
void setup(void)
77+
void setup()
7878
{
7979
// Open serial communications and wait for port to open:
8080
Serial.begin(115200);
@@ -153,7 +153,7 @@ void setup(void)
153153
Serial.println(WiFi.localIP());
154154
}
155155

156-
void loop(void)
156+
void loop()
157157
{
158158
server.handleClient();
159159
}

examples/HelloServer2/HelloServer2.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ void handleNotFound()
7474
digitalWrite(led, 0);
7575
}
7676

77-
void setup(void)
77+
void setup()
7878
{
7979
pinMode(led, OUTPUT);
8080
digitalWrite(led, 0);
@@ -177,7 +177,7 @@ void setup(void)
177177
Serial.println(WiFi.localIP());
178178
}
179179

180-
void loop(void)
180+
void loop()
181181
{
182182
server.handleClient();
183183
}

examples/PostServer/PostServer.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ void handleNotFound()
111111
digitalWrite(led, 0);
112112
}
113113

114-
void setup(void)
114+
void setup()
115115
{
116116
pinMode(led, OUTPUT);
117117
digitalWrite(led, 0);
@@ -189,7 +189,7 @@ void setup(void)
189189
Serial.println(WiFi.localIP());
190190
}
191191

192-
void loop(void)
192+
void loop()
193193
{
194194
server.handleClient();
195195
}

examples/SimpleAuthentication/SimpleAuthentication.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ void handleNotFound()
141141
server.send(404, F("text/plain"), message);
142142
}
143143

144-
void setup(void)
144+
void setup()
145145
{
146146
Serial.begin(115200);
147147
while (!Serial);
@@ -224,7 +224,7 @@ void setup(void)
224224
Serial.println(WiFi.localIP());
225225
}
226226

227-
void loop(void)
227+
void loop()
228228
{
229229
server.handleClient();
230230
}

examples/WebClient/WebClient.ino

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
/****************************************************************************************************************************
22
WebClient.ino - Simple Arduino web server sample for SAMD21 running WiFiNINA shield
33
For any WiFi shields, such as WiFiNINA W101, W102, W13x, or custom, such as ESP8266/ESP32-AT, Ethernet, etc
4-
4+
55
WiFiWebServer is a library for the ESP32-based WiFi shields to run WebServer
66
Based on and modified from ESP8266 https://github.com/esp8266/Arduino/releases
77
Based on and modified from Arduino WiFiNINA library https://www.arduino.cc/en/Reference/WiFiNINA
88
Built by Khoi Hoang https://github.com/khoih-prog/WiFiWebServer
99
Licensed under MIT license
10-
10+
1111
A simple web server that shows the value of the analog input pins via a web page using an ESP8266 module.
1212
This sketch will start an access point and print the IP address of your ESP8266 module to the Serial monitor.
1313
From there, you can open that address in a web browser to display the web page.
1414
The web page will be automatically refreshed each 20 seconds.
15-
15+
1616
For more details see: http://yaab-arduino.blogspot.com/p/wifiesp.html
1717
***************************************************************************************************************************************/
1818
#include "defines.h"
@@ -47,7 +47,7 @@ void setup()
4747
while (!Serial);
4848

4949
Serial.print(F("\nStarting WebClient on ")); Serial.print(BOARD_NAME);
50-
Serial.print(F(" with ")); Serial.println(SHIELD_TYPE);
50+
Serial.print(F(" with ")); Serial.println(SHIELD_TYPE);
5151
Serial.println(WIFI_WEBSERVER_VERSION);
5252

5353
#if WIFI_USING_ESP_AT
@@ -58,46 +58,46 @@ void setup()
5858
WiFi.init(&EspSerial);
5959

6060
Serial.println(F("WiFi shield init done"));
61-
61+
6262
#endif
6363

6464
#if !(ESP32 || ESP8266)
65-
65+
6666
// check for the presence of the shield
67-
#if USE_WIFI_NINA
68-
if (WiFi.status() == WL_NO_MODULE)
69-
#else
70-
if (WiFi.status() == WL_NO_SHIELD)
71-
#endif
72-
{
73-
Serial.println(F("WiFi shield not present"));
74-
// don't continue
75-
while (true);
76-
}
77-
78-
#if USE_WIFI_NINA
79-
String fv = WiFi.firmwareVersion();
80-
81-
if (fv < WIFI_FIRMWARE_LATEST_VERSION)
82-
{
83-
Serial.println(F("Please upgrade the firmware"));
84-
}
85-
#endif
86-
67+
#if USE_WIFI_NINA
68+
if (WiFi.status() == WL_NO_MODULE)
69+
#else
70+
if (WiFi.status() == WL_NO_SHIELD)
71+
#endif
72+
{
73+
Serial.println(F("WiFi shield not present"));
74+
// don't continue
75+
while (true);
76+
}
77+
78+
#if USE_WIFI_NINA
79+
String fv = WiFi.firmwareVersion();
80+
81+
if (fv < WIFI_FIRMWARE_LATEST_VERSION)
82+
{
83+
Serial.println(F("Please upgrade the firmware"));
84+
}
85+
#endif
86+
8787
#endif
8888

8989
Serial.print(F("Connecting to SSID: "));
9090
Serial.println(ssid);
91-
91+
9292
status = WiFi.begin(ssid, pass);
9393

9494
delay(1000);
95-
95+
9696
// attempt to connect to WiFi network
9797
while ( status != WL_CONNECTED)
9898
{
9999
delay(500);
100-
100+
101101
// Connect to WPA/WPA2 network
102102
status = WiFi.status();
103103
}
@@ -120,7 +120,7 @@ void setup()
120120
}
121121
}
122122

123-
void printoutData(void)
123+
void printoutData()
124124
{
125125
// if there are incoming bytes available
126126
// from the server, read them and print them

keywords.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ FunctionRequestHandler KEYWORD1
1717
StaticRequestHandler KEYWORD1
1818
WiFi_RingBuffer KEYWORD1
1919

20+
WWString KEYWORD1
21+
2022
#######################
2123
# WiFiHttpClient
2224
#######################

0 commit comments

Comments
 (0)