Skip to content

Commit 81a5aed

Browse files
authored
Merge pull request #21 from cjkas/cjkas/wifi-crash-fix
Fix wifi crash on freq scan
2 parents bf0c3d3 + 3152002 commit 81a5aed

5 files changed

Lines changed: 17 additions & 150 deletions

File tree

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,5 @@ build/
1515
coredump_report.txt
1616
coredump.bin
1717
logs/
18-
elf_archive/
18+
elf_archive/
19+
src/SomfyController.ino.cpp

src/Somfy.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4878,6 +4878,15 @@ bool Transceiver::begin() {
48784878
return true;
48794879
}
48804880
void Transceiver::loop() {
4881+
// Dispatch deferred frequency scan requests from the main task so that
4882+
// attachInterrupt/detachInterrupt cross-core IPCs don't race with WiFi.
4883+
if(_pendingScan >= 0) {
4884+
int8_t pending = _pendingScan;
4885+
_pendingScan = -1;
4886+
if(pending == 1) this->beginFrequencyScan();
4887+
else this->endFrequencyScan();
4888+
return;
4889+
}
48814890
somfy_rx_t rx;
48824891
if (noiseDetected && rxmode != 3 && this->config.noiseDetection) {
48834892
if (millis() - noiseStart > 100) {

src/Somfy.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,10 @@ class Transceiver {
490490
bool _received = false;
491491
somfy_frame_t frame;
492492
public:
493+
// -1 = none pending, 1 = beginFrequencyScan pending, 0 = endFrequencyScan pending.
494+
// Set from the async_tcp task; consumed by loop() on the main task to avoid
495+
// concurrent cross-core IPC races with the WiFi stack (EXCCAUSE_LOAD_PROHIBITED).
496+
volatile int8_t _pendingScan = -1;
493497
transceiver_config_t config;
494498
bool printBuffer = false;
495499
//bool toJSON(JsonObject& obj);

src/SomfyController.ino.cpp

Lines changed: 0 additions & 147 deletions
This file was deleted.

src/Web.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2406,7 +2406,7 @@ void Web::begin() {
24062406
}));
24072407

24082408
asyncServer.on("/beginFrequencyScan", HTTP_GET, [](AsyncWebServerRequest *request) {
2409-
somfy.transceiver.beginFrequencyScan();
2409+
somfy.transceiver._pendingScan = 1; // deferred to main task — see Transceiver::loop()
24102410
AsyncJsonResp resp;
24112411
resp.beginResponse(request, g_async_content, sizeof(g_async_content));
24122412
resp.beginObject();
@@ -2416,7 +2416,7 @@ void Web::begin() {
24162416
});
24172417

24182418
asyncServer.on("/endFrequencyScan", HTTP_GET, [](AsyncWebServerRequest *request) {
2419-
somfy.transceiver.endFrequencyScan();
2419+
somfy.transceiver._pendingScan = 0; // deferred to main task — see Transceiver::loop()
24202420
AsyncJsonResp resp;
24212421
resp.beginResponse(request, g_async_content, sizeof(g_async_content));
24222422
resp.beginObject();

0 commit comments

Comments
 (0)