-->
Page 1 of 4

"Fatal Exception (0) " after Wifi mode change in loop()

PostPosted: Sat Nov 14, 2015 5:50 pm
by diffstorm
Hello friends,

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:
Code: Select allFatal 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

Re: "Fatal Exception (0) " after Wifi mode change in loop()

PostPosted: Sun Nov 15, 2015 9:05 am
by diffstorm
Any help?

I ve written on setup() that it will be STA mode.
In loop() with a condition I call WiFi.mode(WIFI_AP) and I get Fatal Exception (0) and reset.

Also disconnect routines does not work cuz it reconnects immediately as it before.

Re: "Fatal Exception (0) " after Wifi mode change in loop()

PostPosted: Sun Nov 15, 2015 10:18 am
by martinayotte
diffstorm wrote:If I do the connection in setup() there is no problem, but in loop() it causes periodic resets..

Why do you want to place those calls into loop() instead of setup() ?
Maybe you should share you code to allows people giving you hints.

Re: "Fatal Exception (0) " after Wifi mode change in loop()

PostPosted: Mon Nov 16, 2015 11:24 am
by diffstorm
Hello,

Thanks for the answer.

I simply want to change wifi mode at runtime. For example I have my own wifi network and I've powered the esp device and it goes to connect to my network, BUT if my network is not available temporarily, I want it to be an AP first that I can connect to it's network, after a specific time it should re-try to connect my own network as STA, if it cannot - again it will be AP.

I just call that peace of code in loop() and "mostly" it gets crashed with fatal exception (0) and restarting.
Code: Select all       WiFi.mode(WIFI_STA);
        if(strlen(psk) == 0)
          WiFi.begin(ssid);
        else
          WiFi.begin(ssid, psk);


My test case is to power down my home router and start up the esp, esp goes AP, after that I power up again my home router. So esp retries after 1 min to be a STA and I face that problem.
I've added Serial.print codes on the lines and understood that it crashes on the WiFi.mode(WIFI_STA); line of code.
(I tried disconnect routines before wifi.mode, but no chance)

I need to learn why.

Sincerely.