Skip to content

Commit 2f8962e

Browse files
authored
Merge pull request letscontrolit#1989 from TD-er/cleanup/reduce_flashStrings
[Cleanup] Reduce binary size to allow 1M OTA with minimal plugin set
2 parents cf949ab + a8c565e commit 2f8962e

File tree

100 files changed

+2459
-1466
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

100 files changed

+2459
-1466
lines changed

before_deploy

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ for ENV in \
2424
dev_ESP8266PUYA_1024_VCC\
2525
hard_SONOFF_POW\
2626
hard_SONOFF_POW_R2_4M\
27-
hard_Shelly_1\
27+
minimal_ESP8266_1024_OTA\
28+
minimal_ESP8285_1024_OTA\
2829
esp32dev\
2930
esp32test_1M8_partition;\
3031
do
270 KB
Binary file not shown.

embed_files.sh

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
#!/bin/bash
2+
3+
#
4+
# This script walks through the assets folder and minifys all JS, HTML, CSS and SVG files. It also generates
5+
# the corresponding constants that are added to the data.h file on esp8266_deauther folder.
6+
#
7+
# @Author Erick B. Tedeschi < erickbt86 [at] gmail [dot] com >
8+
# @Author Wandmalfarbe https://github.com/Wandmalfarbe
9+
#
10+
# See: https://github.com/letscontrolit/ESPEasy/issues/1671#issuecomment-415144898
11+
12+
outputfile="$(pwd)/data_h_temp"
13+
14+
rm $outputfile
15+
16+
function minify_html_css {
17+
file=$1
18+
curl -X POST -s --data-urlencode "input@$file" http://html-minifier.com/raw > /tmp/converter.temp
19+
}
20+
21+
function minify_js {
22+
file=$1
23+
curl -X POST -s --data-urlencode "input@$file" https://javascript-minifier.com/raw > /tmp/converter.temp
24+
}
25+
26+
function minify_svg {
27+
file=$1
28+
svgo -i /Users/User/Desktop/icons/tools.svg -o - > /tmp/converter.temp
29+
}
30+
31+
function ascii2hexCstyle {
32+
file_name=$(constFileName $1)
33+
result=$(cat /tmp/converter.temp | hexdump -ve '1/1 "0x%.2x,"')
34+
result=$(echo $result | sed 's/,$//')
35+
echo "const char DATA_${file_name}[] PROGMEM = {$result};"
36+
}
37+
38+
function constFileName {
39+
extension=$(echo $1 | egrep -io "(json|svg|css|js|html)$" | tr "[:lower:]" "[:upper:]")
40+
file=$(echo $1 | sed 's/\.json//' | sed 's/\.svg//' | sed 's/\.css//' | sed 's/\.html//' | sed 's/\.js//' | sed 's/\.\///' | tr '/' '_' | tr '.' '_' | tr '-' '_' | tr "[:lower:]" "[:upper:]")
41+
underscore="_"
42+
echo $file$underscore$extension
43+
}
44+
45+
46+
cd static
47+
file_list=$(find . -type f)
48+
49+
for file in $file_list; do
50+
echo "Processing: $file"
51+
file_name=$(constFileName $file)
52+
echo " Array Name: $file_name"
53+
54+
if [[ "$file" == *.min.js ]]; then
55+
echo " JS already minified"
56+
cat $file > /tmp/converter.temp
57+
ascii2hexCstyle $file >> $outputfile
58+
elif [[ "$file" == *.js ]]; then
59+
echo " JS minify"
60+
minify_js $file
61+
ascii2hexCstyle $file >> $outputfile
62+
elif [[ "$file" == *.min.css ]]; then
63+
echo " CSS already minified"
64+
cat $file > /tmp/converter.temp
65+
ascii2hexCstyle $file >> $outputfile
66+
elif [[ "$file" == *.html ]] || [[ "$file" == *.css ]]; then
67+
echo " HTML and CSS minify"
68+
minify_html_css $file
69+
ascii2hexCstyle $file >> $outputfile
70+
elif [[ "$file" == *.svg ]]; then
71+
echo " SVG minify"
72+
minify_svg $file
73+
ascii2hexCstyle $file >> $outputfile
74+
else
75+
echo " without minifier"
76+
cat $file > /tmp/converter.temp
77+
ascii2hexCstyle $file >> $outputfile
78+
fi
79+
echo ""
80+
sleep 1
81+
done
82+

lib/Adafruit_TCS34725/examples/tcs34725autorange/tcs34725autorange.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ void loop(void) {
163163
Serial.print(rgb_sensor.atime_ms);
164164
Serial.print(F("ms (0x"));
165165
Serial.print(rgb_sensor.atime, HEX);
166-
Serial.println(F(")"));
166+
Serial.println(")");
167167

168168
Serial.print(F("Raw R:"));
169169
Serial.print(rgb_sensor.r);
@@ -182,7 +182,7 @@ void loop(void) {
182182
Serial.print(rgb_sensor.saturation);
183183
Serial.print(F(" Sat75:"));
184184
Serial.print(rgb_sensor.saturation75);
185-
Serial.print(F(" "));
185+
Serial.print(" ");
186186
Serial.println(rgb_sensor.isSaturated ? "*SATURATED*" : "");
187187

188188
Serial.print(F("CPL:"));

lib/Adafruit_TSL2591/examples/tsl2591/tsl2591.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ void displaySensorDetails(void)
3333
Serial.print (F("Min Value: ")); Serial.print(sensor.min_value); Serial.println(F(" lux"));
3434
Serial.print (F("Resolution: ")); Serial.print(sensor.resolution); Serial.println(F(" lux"));
3535
Serial.println(F("------------------------------------"));
36-
Serial.println(F(""));
36+
Serial.println("");
3737
delay(500);
3838
}
3939

@@ -81,7 +81,7 @@ void configureSensor(void)
8181
Serial.print((tsl.getTiming() + 1) * 100, DEC);
8282
Serial.println(F(" ms"));
8383
Serial.println(F("------------------------------------"));
84-
Serial.println(F(""));
84+
Serial.println("");
8585
}
8686

8787

lib/ArduinoJson/third-party/catch/catch.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4207,7 +4207,7 @@ namespace Tbc {
42074207
}
42084208
else {
42094209
spliceLine( indent, remainder, width-1 );
4210-
lines.back() += "-";
4210+
lines.back() += '-';
42114211
}
42124212
if( lines.size() == 1 )
42134213
indent = _attr.indent;

lib/IRremoteESP8266/examples/IRMQTTServer/IRMQTTServer.ino

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -290,13 +290,13 @@ String timeSince(uint32_t const start) {
290290
result += String(days) + " day";
291291
if (days > 1) result += "s";
292292
if (hours)
293-
result += " " + String(hours) + " hour";
293+
result += ' ' + String(hours) + " hour";
294294
if (hours > 1) result += "s";
295295
if (minutes)
296-
result += " " + String(minutes) + " minute";
296+
result += ' ' + String(minutes) + " minute";
297297
if (minutes > 1) result += "s";
298298
if (seconds)
299-
result += " " + String(seconds) + " second";
299+
result += ' ' + String(seconds) + " second";
300300
if (seconds > 1) result += "s";
301301
result.trim();
302302
return result + " ago";
@@ -1003,7 +1003,7 @@ void handleNotFound() {
10031003
message += server.args();
10041004
message += "\n";
10051005
for (uint8_t i=0; i < server.args(); i++)
1006-
message += " " + server.argName(i) + ": " + server.arg(i) + "\n";
1006+
message += ' ' + server.argName(i) + ": " + server.arg(i) + "\n";
10071007
server.send(404, "text/plain", message);
10081008
}
10091009

lib/IRremoteESP8266/examples/IRServer/IRServer.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ void handleNotFound() {
8282
message += server.args();
8383
message += "\n";
8484
for (uint8_t i = 0; i < server.args(); i++)
85-
message += " " + server.argName(i) + ": " + server.arg(i) + "\n";
85+
message += ' ' + server.argName(i) + ": " + server.arg(i) + "\n";
8686
server.send(404, "text/plain", message);
8787
}
8888

lib/IRremoteESP8266/src/IRutils.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ std::string resultToSourceCode(const decode_results *results) {
344344
output += " // " + typeToString(results->decode_type, results->repeat);
345345
// Only display the value if the decode type doesn't have an A/C state.
346346
if (!hasACState(results->decode_type))
347-
output += " " + uint64ToString(results->value, 16);
347+
output += ' ' + uint64ToString(results->value, 16);
348348
output += "\n";
349349

350350
// Now dump "known" codes
@@ -395,7 +395,7 @@ std::string resultToTimingInfo(const decode_results *results) {
395395

396396
for (uint16_t i = 1; i < results->rawlen; i++) {
397397
if (i % 2 == 0)
398-
output += "-"; // even
398+
output += '-'; // even
399399
else
400400
output += " +"; // odd
401401
value = uint64ToString(results->rawbuf[i] * kRawTick);

lib/IRremoteESP8266/src/ir_Haier.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ std::string IRHaierAC::toString() {
359359
default:
360360
result += "Unknown";
361361
}
362-
result += ")";
362+
result += ')';
363363
result += ", Mode: " + uint64ToString(getMode());
364364
switch (getMode()) {
365365
case kHaierAcAuto:
@@ -407,7 +407,7 @@ std::string IRHaierAC::toString() {
407407
default:
408408
result += "Unknown";
409409
}
410-
result += ")";
410+
result += ')';
411411
result += ", Sleep: ";
412412
if (getSleep())
413413
result += "On";
@@ -674,7 +674,7 @@ std::string IRHaierACYRW02::toString() {
674674
default:
675675
result += "Unknown";
676676
}
677-
result += ")";
677+
result += ')';
678678
result += ", Mode: " + uint64ToString(getMode());
679679
switch (getMode()) {
680680
case kHaierAcYrw02Auto:
@@ -727,7 +727,7 @@ std::string IRHaierACYRW02::toString() {
727727
default:
728728
result += "Unknown";
729729
}
730-
result += ")";
730+
result += ')';
731731
result += ", Swing: " + uint64ToString(getSwing()) + " (";
732732
switch (getSwing()) {
733733
case kHaierAcYrw02SwingOff:
@@ -751,7 +751,7 @@ std::string IRHaierACYRW02::toString() {
751751
default:
752752
result += "Unknown";
753753
}
754-
result += ")";
754+
result += ')';
755755
result += ", Sleep: ";
756756
if (getSleep())
757757
result += "On";

platformio.ini

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,10 @@ monitor_speed = 115200
135135
platform = ${common.platform}
136136
build_flags =
137137

138+
[normal_ota]
139+
platform = ${common.platform}
140+
build_flags = -DPLUGIN_BUILD_MINIMAL_OTA
141+
138142
[testing]
139143
platform = ${core_2_4_2.platform}
140144
build_flags = -DPLUGIN_BUILD_TESTING
@@ -285,6 +289,39 @@ board_build.flash_mode = ${esp8266_1M.board_build.flash_mode}
285289
build_unflags = ${esp8266_1M.build_unflags}
286290
build_flags = ${esp8266_1M.build_flags} ${normal.build_flags}
287291

292+
[env:minimal_ESP8266_1024_OTA]
293+
platform = ${common.platform}
294+
lib_deps = ${common.lib_deps}
295+
lib_ignore = ${common.lib_ignore}
296+
lib_ldf_mode = ${common.lib_ldf_mode}
297+
lib_archive = ${common.lib_archive}
298+
framework = ${common.framework}
299+
upload_speed = ${common.upload_speed}
300+
monitor_speed = ${common.monitor_speed}
301+
board = ${common.board}
302+
board_upload.maximum_size = 616448
303+
board_build.f_cpu = ${esp8266_1M.board_build.f_cpu}
304+
board_build.flash_mode = ${esp8266_1M.board_build.flash_mode}
305+
build_unflags = ${esp8266_1M.build_unflags}
306+
build_flags = ${esp8266_1M.build_flags} ${normal_ota.build_flags}
307+
308+
[env:minimal_ESP8285_1024_OTA]
309+
platform = ${common.platform}
310+
lib_deps = ${common.lib_deps}
311+
lib_ignore = ${common.lib_ignore}
312+
lib_ldf_mode = ${common.lib_ldf_mode}
313+
lib_archive = ${common.lib_archive}
314+
framework = ${common.framework}
315+
upload_speed = ${common.upload_speed}
316+
monitor_speed = ${common.monitor_speed}
317+
board = ${esp8285_1M.board}
318+
board_upload.maximum_size = 616448
319+
board_build.f_cpu = ${esp8285_1M.board_build.f_cpu}
320+
board_build.flash_mode = ${esp8285_1M.board_build.flash_mode}
321+
build_unflags = ${esp8285_1M.build_unflags}
322+
build_flags = ${esp8285_1M.build_flags} ${normal_ota.build_flags}
323+
324+
288325
[env:normal_core_241_ESP8266_1024]
289326
platform = ${core_2_4_1.platform}
290327
lib_deps = ${common.lib_deps}

src/Commands/Common.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,11 @@ String Command_GetORSetIP(struct EventStruct *event,
2929
char TmpStr1[INPUT_COMMAND_SIZE];
3030
if (GetArgv(Line, TmpStr1, arg + 1)) {
3131
if (!str2ip(TmpStr1, IP)) {
32-
return return_result(event, F("Invalid parameter."));
32+
String result = F("Invalid parameter: ");
33+
result += TmpStr1;
34+
return return_result(event, result);
3335
}
34-
}else {
36+
} else {
3537
Serial.println();
3638
String result = targetDescription;
3739
if (useStaticIP()) {

src/Controller.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ bool MQTTConnect(int controller_idx)
155155
if(Settings.MQTTUseUnitNameAsClientId){
156156
clientid = Settings.Name;
157157
if (Settings.Unit != 0) { // only append non-zero unit number
158-
clientid += F("_");
158+
clientid += '_';
159159
clientid += Settings.Unit;
160160
}
161161
}
@@ -169,7 +169,7 @@ bool MQTTConnect(int controller_idx)
169169
// To overcome this issue, append the number of reconnects to the client ID to
170170
// make it different from the previous one.
171171
if (wifi_reconnects >= 1) {
172-
clientid += F("_");
172+
clientid += '_';
173173
clientid += wifi_reconnects;
174174
}
175175

0 commit comments

Comments
 (0)