Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit e7bb7fe

Browse files
authoredJun 13, 2024··
Merge branch 'master' into webserver-filters
2 parents 1f498a1 + 1d895e5 commit e7bb7fe

19 files changed

+251
-113
lines changed
 

‎.github/scripts/on-push.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ if [ "$BUILD_PIO" -eq 0 ]; then
108108

109109
if [ "$BUILD_LOG" -eq 1 ]; then
110110
#remove last comma from the last JSON object
111-
sed -i '$ s/.$//' "$sizes_file"
111+
sed -i '$ s/,$//' "$sizes_file"
112112
#echo end of JSON array
113113
echo "]}" >> $sizes_file
114114
fi

‎.github/scripts/set_push_chunks.sh

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
#!/bin/bash
2+
3+
build_all=false
4+
chunks_count=0
5+
6+
if [[ $CORE_CHANGED == 'true' ]] || [[ $IS_PR != 'true' ]]; then
7+
echo "Core files changed or not a PR. Building all."
8+
build_all=true
9+
chunks_count=$MAX_CHUNKS
10+
elif [[ $LIB_CHANGED == 'true' ]]; then
11+
echo "Libraries changed. Building only affected sketches."
12+
if [[ $NETWORKING_CHANGED == 'true' ]]; then
13+
echo "Networking libraries changed. Building networking related sketches."
14+
networking_sketches="$(find libraries/WiFi -name *.ino) "
15+
networking_sketches+="$(find libraries/Ethernet -name *.ino) "
16+
networking_sketches+="$(find libraries/PPP -name *.ino) "
17+
networking_sketches+="$(find libraries/NetworkClientSecure -name *.ino) "
18+
networking_sketches+="$(find libraries/WebServer -name *.ino) "
19+
fi
20+
if [[ $FS_CHANGED == 'true' ]]; then
21+
echo "FS libraries changed. Building FS related sketches."
22+
fs_sketches="$(find libraries/SD -name *.ino) "
23+
fs_sketches+="$(find libraries/SD_MMC -name *.ino) "
24+
fs_sketches+="$(find libraries/SPIFFS -name *.ino) "
25+
fs_sketches+="$(find libraries/LittleFS -name *.ino) "
26+
fs_sketches+="$(find libraries/FFat -name *.ino) "
27+
fi
28+
sketches="$networking_sketches $fs_sketches"
29+
for file in $LIB_FILES; do
30+
if [[ $file == *.ino ]]; then
31+
# If file ends with .ino, add it to the list of sketches
32+
echo "Sketch found: $file"
33+
sketches+="$file "
34+
elif [[ $(basename $(dirname $file)) == "src" ]]; then
35+
# If file is in a src directory, find all sketches in the parent/examples directory
36+
echo "Library src file found: $file"
37+
lib=$(dirname $(dirname $file))
38+
if [[ -d $lib/examples ]]; then
39+
lib_sketches=$(find $lib/examples -name *.ino)
40+
sketches+="$lib_sketches "
41+
echo "Library sketches: $lib_sketches"
42+
fi
43+
else
44+
# If file is in a example folder but it is not a sketch, find all sketches in the current directory
45+
echo "File in example folder found: $file"
46+
sketch=$(find $(dirname $file) -name *.ino)
47+
sketches+="$sketch "
48+
echo "Sketch in example folder: $sketch"
49+
fi
50+
echo ""
51+
done
52+
fi
53+
54+
if [[ -n $sketches ]]; then
55+
# Remove duplicates
56+
sketches=$(echo $sketches | tr ' ' '\n' | sort | uniq)
57+
for sketch in $sketches; do
58+
echo $sketch >> sketches_found.txt
59+
chunks_count=$((chunks_count+1))
60+
done
61+
echo "Number of sketches found: $chunks_count"
62+
echo "Sketches:"
63+
echo "$sketches"
64+
65+
if [[ $chunks_count -gt $MAX_CHUNKS ]]; then
66+
echo "More sketches than the allowed number of chunks found. Limiting to $MAX_CHUNKS chunks."
67+
chunks_count=$MAX_CHUNKS
68+
fi
69+
fi
70+
71+
chunks='["0"'
72+
for i in $(seq 1 $(( $chunks_count - 1 )) ); do
73+
chunks+=",\"$i\""
74+
done
75+
chunks+="]"
76+
77+
echo "build_all=$build_all" >> $GITHUB_OUTPUT
78+
echo "build_libraries=$BUILD_LIBRARIES" >> $GITHUB_OUTPUT
79+
echo "build_static_sketches=$BUILD_STATIC_SKETCHES" >> $GITHUB_OUTPUT
80+
echo "build_idf=$BUILD_IDF" >> $GITHUB_OUTPUT
81+
echo "build_platformio=$BUILD_PLATFORMIO" >> $GITHUB_OUTPUT
82+
echo "chunk_count=$chunks_count" >> $GITHUB_OUTPUT
83+
echo "chunks=$chunks" >> $GITHUB_OUTPUT

‎.github/scripts/sketch_utils.sh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ function build_sketch(){ # build_sketch <ide_path> <user_path> <path-to-ino> [ex
192192

193193
exit_status=$?
194194
if [ $exit_status -ne 0 ]; then
195-
echo ""ERROR: Compilation failed with error code $exit_status""
195+
echo "ERROR: Compilation failed with error code $exit_status"
196196
exit $exit_status
197197
fi
198198

@@ -236,7 +236,7 @@ function build_sketch(){ # build_sketch <ide_path> <user_path> <path-to-ino> [ex
236236

237237
exit_status=$?
238238
if [ $exit_status -ne 0 ]; then
239-
echo ""ERROR: Compilation failed with error code $exit_status""
239+
echo "ERROR: Compilation failed with error code $exit_status"
240240
exit $exit_status
241241
fi
242242
# $ide_path/arduino-builder -compile -logger=human -core-api-version=10810 \
@@ -398,6 +398,7 @@ function build_sketches(){ # build_sketches <ide_path> <user_path> <target> <pat
398398
else
399399
start_index=$(( $chunk_index * $chunk_size ))
400400
if [ "$sketchcount" -le "$start_index" ]; then
401+
echo "No sketches to build for $target in this chunk"
401402
return 0
402403
fi
403404

@@ -437,7 +438,7 @@ function build_sketches(){ # build_sketches <ide_path> <user_path> <target> <pat
437438
continue
438439
fi
439440
echo ""
440-
echo "Building Sketch Index $(($sketchnum - 1)) - $sketchdirname"
441+
echo "Building Sketch Index $sketchnum - $sketchdirname"
441442
build_sketch $args -s $sketchdir $xtra_opts
442443
local result=$?
443444
if [ $result -ne 0 ]; then

‎.github/scripts/tests_run.sh

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,12 @@ function run_test() {
9595
printf "\033[95mpytest tests --build-dir $build_dir -k test_$sketchname --junit-xml=$report_file $extra_args\033[0m\n"
9696
bash -c "set +e; pytest tests --build-dir $build_dir -k test_$sketchname --junit-xml=$report_file $extra_args; exit \$?" || result=$?
9797
printf "\n"
98-
result=$?
9998
if [ $result -ne 0 ]; then
99+
printf "\033[91mFailed test: $sketchname -- Config: $i\033[0m\n\n"
100100
error=$result
101101
fi
102102
fi
103103
done
104-
printf "Test return code: $error\n"
105104
return $error
106105
}
107106

@@ -250,7 +249,6 @@ else
250249

251250
exit_code=0
252251
run_test $target $sketch $options $erase || exit_code=$?
253-
echo "Sketch $sketch exit code: $exit_code"
254252
if [ $exit_code -ne 0 ]; then
255253
error=$exit_code
256254
fi

‎.github/workflows/hw.yml

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,18 +77,16 @@ jobs:
7777
run: |
7878
pip install -U pip
7979
pip install -r tests/requirements.txt --extra-index-url https://dl.espressif.com/pypi
80+
apt update
81+
apt install -y jq
8082
8183
- name: Get binaries
82-
id: cache-build-binaries
83-
uses: actions/cache/restore@v4
8484
if: ${{ steps.check-tests.outputs.enabled == 'true' }}
85+
uses: actions/download-artifact@v4
8586
with:
86-
fail-on-cache-miss: true
87-
key: tests-${{ env.id }}-bin
87+
name: tests-bin-${{ inputs.chip }}-${{ inputs.type }}
8888
path: |
89-
~/.arduino/tests/**/build*.tmp/*.bin
90-
~/.arduino/tests/**/build*.tmp/*.elf
91-
~/.arduino/tests/**/build*.tmp/*.json
89+
~/.arduino/tests
9290
9391
- name: Run Tests
9492
if: ${{ steps.check-tests.outputs.enabled == 'true' }}

‎.github/workflows/lib.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@ jobs:
120120

121121
- name: Push to github repo
122122
run: |
123-
git config user.name github-actions
124-
git config user.email github-actions@github.com
123+
git config user.name "github-actions[bot]"
124+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
125125
git add ${{ env.RESULT_LIBRARY_TEST_FILE }}
126126
git commit -m "Generated External Libraries Test Results"
127127
git push origin HEAD:gh-pages

‎.github/workflows/publishsizes-2.x.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,22 +32,22 @@ jobs:
3232
run: |
3333
mv master_cli_compile/*.json artifacts/sizes-report/pr/
3434
mv v2.x_cli_compile/*.json artifacts/sizes-report/master/
35-
35+
3636
- name: Report results
3737
uses: P-R-O-C-H-Y/report-size-deltas@sizes_v2
3838
with:
3939
sketches-reports-source: ${{ env.SKETCHES_REPORTS_PATH }}
4040
github-token: ${{ env.GITHUB_TOKEN }}
4141
destination-file: ${{ env.RESULT_SIZES_TEST_FILE }}
42-
42+
4343
- name: Append file with action URL
4444
run:
4545
echo "/ [GitHub Action Link](https://github.com/${{github.repository}}/actions/runs/${{github.run_id}})" >> ${{ env.RESULT_SIZES_TEST_FILE }}
4646

4747
- name: Push to github repo
4848
run: |
49-
git config user.name github-actions
50-
git config user.email github-actions@github.com
49+
git config user.name "github-actions[bot]"
50+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
5151
git add ${{ env.RESULT_SIZES_TEST_FILE }}
5252
git commit -m "Generated Sizes Results (master-v2.x)"
5353
git push origin HEAD:gh-pages

‎.github/workflows/push.yml

Lines changed: 18 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ jobs:
7777
libraries:
7878
- 'libraries/**/examples/**'
7979
- 'libraries/**/src/**'
80+
networking:
81+
- 'libraries/Network/src/**'
82+
fs:
83+
- 'libraries/FS/src/**'
8084
static_sketeches:
8185
- 'libraries/NetworkClientSecure/examples/WiFiClientSecure/WiFiClientSecure.ino'
8286
- 'libraries/BLE/examples/Server/Server.ino'
@@ -97,78 +101,18 @@ jobs:
97101
id: set-chunks
98102
env:
99103
LIB_FILES: ${{ steps.changed-files.outputs.libraries_all_changed_files }}
104+
IS_PR: ${{ github.event_name == 'pull_request' }}
105+
MAX_CHUNKS: ${{ env.MAX_CHUNKS }}
106+
BUILD_PLATFORMIO: ${{ steps.changed-files.outputs.platformio_any_changed == 'true' }}
107+
BUILD_IDF: ${{ steps.changed-files.outputs.idf_any_changed == 'true' }}
108+
BUILD_LIBRARIES: ${{ steps.changed-files.outputs.libraries_any_changed == 'true' }}
109+
BUILD_STATIC_SKETCHES: ${{ steps.changed-files.outputs.static_sketeches_any_changed == 'true' }}
110+
FS_CHANGED: ${{ steps.changed-files.outputs.fs_any_changed == 'true' }}
111+
NETWORKING_CHANGED: ${{ steps.changed-files.outputs.networking_any_changed == 'true' }}
112+
CORE_CHANGED: ${{ steps.changed-files.outputs.core_any_changed == 'true' }}
113+
LIB_CHANGED: ${{ steps.changed-files.outputs.libraries_any_changed == 'true' }}
100114
run: |
101-
build_all=false
102-
chunks_count=0
103-
is_pr=${{ github.event_name == 'pull_request' }}
104-
105-
build_platformio=${{ steps.changed-files.outputs.platformio_any_changed == 'true' }}
106-
build_idf=${{ steps.changed-files.outputs.idf_any_changed == 'true' }}
107-
build_libraries=${{ steps.changed-files.outputs.libraries_any_changed == 'true' }}
108-
build_static_sketches=${{ steps.changed-files.outputs.static_sketeches_any_changed == 'true' }}
109-
110-
core_changed=${{ steps.changed-files.outputs.core_any_changed == 'true' }}
111-
lib_changed=${{ steps.changed-files.outputs.libraries_any_changed == 'true' }}
112-
113-
if [[ $core_changed == 'true' ]] || [[ $is_pr != 'true' ]]; then
114-
echo "Core files changed or not a PR. Building all."
115-
build_all=true
116-
chunks_count=${{ env.MAX_CHUNKS }}
117-
elif [[ $lib_changed == 'true' ]]; then
118-
echo "Libraries changed. Building only affected sketches."
119-
sketches=""
120-
for file in $LIB_FILES; do
121-
if [[ $file == *.ino ]]; then
122-
# If file ends with .ino, add it to the list of sketches
123-
echo "Sketch found: $file"
124-
sketches+="$file "
125-
elif [[ $(basename $(dirname $file)) == "src" ]]; then
126-
# If file is in a src directory, find all sketches in the parent/examples directory
127-
echo "Library src file found: $file"
128-
lib=$(dirname $(dirname $file))
129-
lib_sketches=$(find $lib/examples -name *.ino)
130-
sketches+="$lib_sketches "
131-
echo "Library sketches: $lib_sketches"
132-
else
133-
# If file is in a example folder but it is not a sketch, find all sketches in the current directory
134-
echo "File in example folder found: $file"
135-
sketch=$(find $(dirname $file) -name *.ino)
136-
sketches+="$sketch "
137-
echo "Sketch in example folder: $sketch"
138-
fi
139-
echo ""
140-
done
141-
fi
142-
143-
if [[ -n $sketches ]]; then
144-
# Remove duplicates
145-
sketches=$(echo $sketches | tr ' ' '\n' | sort | uniq)
146-
for sketch in $sketches; do
147-
echo $sketch >> sketches_found.txt
148-
chunks_count=$((chunks_count+1))
149-
done
150-
echo "Number of sketches found: $chunks_count"
151-
echo "Sketches: $sketches"
152-
153-
if [[ $chunks_count -gt ${{ env.MAX_CHUNKS }} ]]; then
154-
echo "More sketches than the allowed number of chunks found. Limiting to ${{ env.MAX_CHUNKS }} chunks."
155-
chunks_count=${{ env.MAX_CHUNKS }}
156-
fi
157-
fi
158-
159-
chunks='["0"'
160-
for i in $(seq 1 $(( $chunks_count - 1 )) ); do
161-
chunks+=",\"$i\""
162-
done
163-
chunks+="]"
164-
165-
echo "build_all=$build_all" >> $GITHUB_OUTPUT
166-
echo "build_libraries=$build_libraries" >> $GITHUB_OUTPUT
167-
echo "build_static_sketches=$build_static_sketches" >> $GITHUB_OUTPUT
168-
echo "build_idf=$build_idf" >> $GITHUB_OUTPUT
169-
echo "build_platformio=$build_platformio" >> $GITHUB_OUTPUT
170-
echo "chunk_count=$chunks_count" >> $GITHUB_OUTPUT
171-
echo "chunks=$chunks" >> $GITHUB_OUTPUT
115+
bash ./.github/scripts/set_push_chunks.sh
172116
173117
- name: Upload sketches found
174118
if: ${{ steps.set-chunks.outputs.build_all == 'false' && steps.set-chunks.outputs.build_libraries == 'true' }}
@@ -336,9 +280,10 @@ jobs:
336280

337281
- name: Commit json files to gh-pages if on master
338282
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
283+
continue-on-error: true
339284
run: |
340-
git config user.name github-actions
341-
git config user.email github-actions@github.com
285+
git config user.name "github-actions[bot]"
286+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
342287
git add --all
343288
git commit -m "Updated cli compile json files"
344289
git push origin HEAD:gh-pages

‎.github/workflows/qemu.yml

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -113,15 +113,11 @@ jobs:
113113
114114
- name: Get binaries
115115
if: ${{ steps.check-tests.outputs.enabled == 'true' }}
116-
id: cache-build-binaries
117-
uses: actions/cache/restore@v4
116+
uses: actions/download-artifact@v4
118117
with:
119-
fail-on-cache-miss: true
120-
key: tests-${{ env.id }}-bin
118+
name: tests-bin-${{ inputs.chip }}-${{ inputs.type }}
121119
path: |
122-
~/.arduino/tests/**/build*.tmp/*.bin
123-
~/.arduino/tests/**/build*.tmp/*.elf
124-
~/.arduino/tests/**/build*.tmp/*.json
120+
~/.arduino/tests
125121
126122
- name: Run Tests
127123
if: ${{ steps.check-tests.outputs.enabled == 'true' }}

‎.github/workflows/wokwi.yml

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -91,15 +91,11 @@ jobs:
9191

9292
- name: Get binaries
9393
if: ${{ steps.check-tests.outputs.enabled == 'true' }}
94-
id: cache-build-binaries
95-
uses: actions/cache/restore@v4
94+
uses: actions/download-artifact@v4
9695
with:
97-
fail-on-cache-miss: true
98-
key: tests-${{ env.id }}-bin
96+
name: tests-bin-${{ inputs.chip }}-${{ inputs.type }}
9997
path: |
100-
~/.arduino/tests/**/build*.tmp/*.bin
101-
~/.arduino/tests/**/build*.tmp/*.elf
102-
~/.arduino/tests/**/build*.tmp/*.json
98+
~/.arduino/tests
10399
104100
- name: Run Tests
105101
if: ${{ steps.check-tests.outputs.enabled == 'true' }}

‎cores/esp32/chip-debug-report.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ static void printChipInfo(void) {
9696
chip_report_printf(" Cores : %d\n", info.cores);
9797
rtc_cpu_freq_config_t conf;
9898
rtc_clk_cpu_freq_get_config(&conf);
99-
chip_report_printf(" Frequency : %lu MHz\n", conf.freq_mhz);
99+
chip_report_printf(" CPU Frequency : %lu MHz\n", conf.freq_mhz);
100+
chip_report_printf(" XTAL Frequency : %d MHz\n", rtc_clk_xtal_freq_get());
100101
chip_report_printf(" Embedded Flash : %s\n", (info.features & CHIP_FEATURE_EMB_FLASH) ? "Yes" : "No");
101102
chip_report_printf(" Embedded PSRAM : %s\n", (info.features & CHIP_FEATURE_EMB_PSRAM) ? "Yes" : "No");
102103
chip_report_printf(" 2.4GHz WiFi : %s\n", (info.features & CHIP_FEATURE_WIFI_BGN) ? "Yes" : "No");

‎cores/esp32/esp32-hal-misc.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,9 +252,6 @@ extern bool btInUse();
252252
void initArduino() {
253253
//init proper ref tick value for PLL (uncomment if REF_TICK is different than 1MHz)
254254
//ESP_REG(APB_CTRL_PLL_TICK_CONF_REG) = APB_CLK_FREQ / REF_CLK_FREQ - 1;
255-
#ifdef F_CPU
256-
setCpuFrequencyMhz(F_CPU / 1000000);
257-
#endif
258255
#if CONFIG_SPIRAM_SUPPORT || CONFIG_SPIRAM
259256
psramInit();
260257
#endif

‎cores/esp32/main.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "freertos/FreeRTOS.h"
22
#include "freertos/task.h"
33
#include "esp_task_wdt.h"
4+
#include "soc/rtc.h"
45
#include "Arduino.h"
56
#if (ARDUINO_USB_CDC_ON_BOOT | ARDUINO_USB_MSC_ON_BOOT | ARDUINO_USB_DFU_ON_BOOT) && !ARDUINO_USB_MODE
67
#include "USB.h"
@@ -78,6 +79,15 @@ void loopTask(void *pvParameters) {
7879
}
7980

8081
extern "C" void app_main() {
82+
#ifdef F_XTAL_MHZ
83+
#if !CONFIG_IDF_TARGET_ESP32S2 // ESP32-S2 does not support rtc_clk_xtal_freq_update
84+
rtc_clk_xtal_freq_update((rtc_xtal_freq_t)F_XTAL_MHZ);
85+
rtc_clk_cpu_freq_set_xtal();
86+
#endif
87+
#endif
88+
#ifdef F_CPU
89+
setCpuFrequencyMhz(F_CPU / 1000000);
90+
#endif
8191
#if ARDUINO_USB_CDC_ON_BOOT && !ARDUINO_USB_MODE
8292
Serial.begin();
8393
#endif

‎idf_component.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ dependencies:
8181
version: "^1.4.2"
8282
rules:
8383
- if: "target in [esp32s3]"
84+
espressif/libsodium:
85+
version: "^1.0.20~1"
86+
require: public
8487
joltwallet/littlefs:
8588
version: "^1.10.2"
8689
chmorgan/esp-libhelix-mp3:

‎libraries/Network/src/NetworkClient.cpp

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,34 @@ int NetworkClient::read(uint8_t *buf, size_t size) {
479479
return res;
480480
}
481481

482+
size_t NetworkClient::readBytes(char *buffer, size_t length) {
483+
size_t left = length, sofar = 0;
484+
int r = 0, to = millis() + getTimeout();
485+
while (left) {
486+
r = read((uint8_t *)buffer + sofar, left);
487+
if (r < 0) {
488+
// Error has occurred
489+
break;
490+
}
491+
if (r > 0) {
492+
// We got some data
493+
left -= r;
494+
sofar += r;
495+
to = millis() + getTimeout();
496+
} else {
497+
// We got no data
498+
if (millis() >= to) {
499+
// We have waited for data enough
500+
log_w("Timeout waiting for data on fd %d", fd());
501+
break;
502+
}
503+
// Allow other tasks to run
504+
delay(2);
505+
}
506+
}
507+
return sofar;
508+
}
509+
482510
int NetworkClient::peek() {
483511
int res = -1;
484512
if (fd() >= 0 && _rxBuffer) {
@@ -589,8 +617,24 @@ IPAddress NetworkClient::localIP(int fd) const {
589617
struct sockaddr_storage addr;
590618
socklen_t len = sizeof addr;
591619
getsockname(fd, (struct sockaddr *)&addr, &len);
592-
struct sockaddr_in *s = (struct sockaddr_in *)&addr;
593-
return IPAddress((uint32_t)(s->sin_addr.s_addr));
620+
621+
// IPv4 socket, old way
622+
if (((struct sockaddr *)&addr)->sa_family == AF_INET) {
623+
struct sockaddr_in *s = (struct sockaddr_in *)&addr;
624+
return IPAddress((uint32_t)(s->sin_addr.s_addr));
625+
}
626+
627+
// IPv6, but it might be IPv4 mapped address
628+
if (((struct sockaddr *)&addr)->sa_family == AF_INET6) {
629+
struct sockaddr_in6 *saddr6 = (struct sockaddr_in6 *)&addr;
630+
if (IN6_IS_ADDR_V4MAPPED(saddr6->sin6_addr.un.u32_addr)) {
631+
return IPAddress(IPv4, (uint8_t *)saddr6->sin6_addr.s6_addr + IPADDRESS_V4_BYTES_INDEX);
632+
} else {
633+
return IPAddress(IPv6, (uint8_t *)(saddr6->sin6_addr.s6_addr), saddr6->sin6_scope_id);
634+
}
635+
}
636+
log_e("NetworkClient::localIP Not AF_INET or AF_INET6?");
637+
return (IPAddress(0, 0, 0, 0));
594638
}
595639

596640
uint16_t NetworkClient::localPort(int fd) const {

‎libraries/Network/src/NetworkClient.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ class NetworkClient : public ESPLwIPClient {
6060
int available();
6161
int read();
6262
int read(uint8_t *buf, size_t size);
63+
size_t readBytes(char *buffer, size_t length);
64+
size_t readBytes(uint8_t *buffer, size_t length) {
65+
return readBytes((char *)buffer, length);
66+
}
6367
int peek();
6468
void clear(); // clear rx
6569
void stop();

‎libraries/WebServer/src/WebServer.cpp

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,10 +320,38 @@ RequestHandler& WebServer::on(const Uri &uri, HTTPMethod method, WebServer::THan
320320
return *handler;
321321
}
322322

323+
bool WebServer::removeRoute(const char *uri) {
324+
return removeRoute(String(uri), HTTP_ANY);
325+
}
326+
327+
bool WebServer::removeRoute(const char *uri, HTTPMethod method) {
328+
return removeRoute(String(uri), method);
329+
}
330+
331+
bool WebServer::removeRoute(const String &uri) {
332+
return removeRoute(uri, HTTP_ANY);
333+
}
334+
335+
bool WebServer::removeRoute(const String &uri, HTTPMethod method) {
336+
// Loop through all request handlers and see if there is a match
337+
RequestHandler *handler = _firstHandler;
338+
while (handler) {
339+
if (handler->canHandle(method, uri)) {
340+
return _removeRequestHandler(handler);
341+
}
342+
handler = handler->next();
343+
}
344+
return false;
345+
}
346+
323347
void WebServer::addHandler(RequestHandler *handler) {
324348
_addRequestHandler(handler);
325349
}
326350

351+
bool WebServer::removeHandler(RequestHandler *handler) {
352+
return _removeRequestHandler(handler);
353+
}
354+
327355
void WebServer::_addRequestHandler(RequestHandler *handler) {
328356
if (!_lastHandler) {
329357
_firstHandler = handler;
@@ -334,6 +362,32 @@ void WebServer::_addRequestHandler(RequestHandler *handler) {
334362
}
335363
}
336364

365+
bool WebServer::_removeRequestHandler(RequestHandler *handler) {
366+
RequestHandler *current = _firstHandler;
367+
RequestHandler *previous = nullptr;
368+
369+
while (current != nullptr) {
370+
if (current == handler) {
371+
if (previous == nullptr) {
372+
_firstHandler = current->next();
373+
} else {
374+
previous->next(current->next());
375+
}
376+
377+
if (current == _lastHandler) {
378+
_lastHandler = previous;
379+
}
380+
381+
// Delete 'matching' handler
382+
delete current;
383+
return true;
384+
}
385+
previous = current;
386+
current = current->next();
387+
}
388+
return false;
389+
}
390+
337391
void WebServer::serveStatic(const char *uri, FS &fs, const char *path, const char *cache_header) {
338392
_addRequestHandler(new StaticRequestHandler(fs, path, uri, cache_header));
339393
}

‎libraries/WebServer/src/WebServer.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,12 @@ class WebServer {
148148
RequestHandler& on(const Uri &uri, THandlerFunction fn);
149149
RequestHandler& on(const Uri &uri, HTTPMethod method, THandlerFunction fn);
150150
RequestHandler& on(const Uri &uri, HTTPMethod method, THandlerFunction fn, THandlerFunction ufn); //ufn handles file uploads
151+
bool removeRoute(const char *uri);
152+
bool removeRoute(const char *uri, HTTPMethod method);
153+
bool removeRoute(const String &uri);
154+
bool removeRoute(const String &uri, HTTPMethod method);
151155
void addHandler(RequestHandler *handler);
156+
bool removeHandler(RequestHandler *handler);
152157
void serveStatic(const char *uri, fs::FS &fs, const char *path, const char *cache_header = NULL);
153158
void onNotFound(THandlerFunction fn); //called when handler is not assigned
154159
void onFileUpload(THandlerFunction ufn); //handle file uploads
@@ -231,6 +236,7 @@ class WebServer {
231236
return _currentClient.write_P(b, l);
232237
}
233238
void _addRequestHandler(RequestHandler *handler);
239+
bool _removeRequestHandler(RequestHandler *handler);
234240
void _handleRequest();
235241
void _finalizeResponse();
236242
bool _parseRequest(NetworkClient &client);

‎variants/esp32thing/pins_arduino.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
#include <stdint.h>
55

6+
#define F_XTAL_MHZ 26 //SparkFun ESP32 Thing has 26MHz Crystal
7+
68
static const uint8_t LED_BUILTIN = 5;
79
#define BUILTIN_LED LED_BUILTIN // backward compatibility
810
#define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN

0 commit comments

Comments
 (0)
Please sign in to comment.