I have written a state machine code which has WiFi.mode, WiFi.softAP, WiFi.begin, WiFi.softAPConfig, WiFi.disconnect and WiFi.hostname functions in loop(). These functions are kind of write functions and sometimes I think that when another process tries to access to the same target with my code (for ex: disconnect writes somewhere at the same time the wifi thread writes there too) and the other process gets exception and restarts the ESP chip. Sometimes it can be unstoppable infinitive resets of the chip.
Here is the output:
Fatal exception (0):<CR><LF>
epc1=0x402022b0, epc2=0x00000000, epc3=0x00000000, excvaddr=0x00000000, depc=0x00000000<CR><LF>
<CR><LF>
Exception (0):<CR><LF>
epc1=0x402022b0 epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000000 depc=0x00000000<CR><LF>
<CR><LF>
ctx: cont <CR><LF>
sp: 3ffeccf0 end: 3ffed120 offset: 01a0<CR><LF>
I want to learn is there any mutex-like protection method to avoid this issue?
If I do the connection in setup() there is no problem, but in loop() it causes periodic resets..
Also another question:
I've connected the ESP to my wifi one time and after that I've reflashed the sketch without any connection code (deleted the wifi codes to leave it on its own) and I saw that it goes to connect to my wifi again. So it has written the last config in non volatile place and uses that data to connect if nobody calls wifi functions.
Where it is written this config? Can I read this to compare with needed data to decide that I should change the config or not?
How can I delete that config data? I've tried WiFi.disconnect() but it didn't delete the config.
So long question, sorry for details. I hope the answer is useful for others too.
Thanks in advance