Hi all,
as the title, I have the main thread that connects the Electron to 3rd-party sim cell but I get red blinking led when I try to open a UDP socket in another thread…
A resume of the flow is pasted here: https://pastebin.com/9spVtYzi
You can actually embed the code in a preformatted (code) block
And you may also want to state what kind of red blink you see.
I’d guess it’s an SOS+13 (stack overflow)
Also, in some previous device OS version calling Log.xxxx() inside an independet thread caused problems too - not sure whether this is already fixed in 1.4.0.
You can actually embed the code in a preformatted (code) block
You mean instead of pastebin or you want the complete code? (It's quite long )
I checked the SOS sequence. Yes It's stack overflow.
I tried to comment all Logs.xxx() and also SerialLogHandler, but it doesn't solve the problem
I checked with only SerialLogHandler too, but it hangs always after the UDP begin (basically around 50sec, at those AT commands).
If it's not Log it may well be UDP.
However, since we now know it's a stack overflow you can donate more stack to the thread as a fourth parameter in the Thread() constructor.
The default value is 3K.
I went into this problem deeply.
The problem was due to a char array allocation BEFORE opening the socket.
SpiffsParticleFile f = fs.openFile(filePath, SPIFFS_O_RDWR|SPIFFS_O_CREAT|SPIFFS_O_APPEND);
if (f.isValid()) {
int len = f.length();
char buf[len];
with len = 4096 and it's probably too large (It happens even in the main Thread)
It's not clear why the electron blinks red only when I open the UDP socket and not when I declare the array though.
When you almost exhaust the stack with your local variably any function that may acquire more than what's left the stack overflow will happen. As such opening the UDP socket is probably somewhat heavy on the stack but could't execute properly after the array had claimed too much of that stack.