Is user_init() called after connecting to AP?
Posted:
Wed May 13, 2015 12:40 pm
by dayzman
Does anyone know if user_init() is called after trying to establish a connection to the AP? If a connection can be established, would it be safe to assume that by the time it reaches user_init(), there is already a connection? Otherwise, how to ensure that the device is already connected?
Thanks
Re: Is user_init() called after connecting to AP?
Posted:
Thu May 14, 2015 4:10 am
by dayzman
Thanks. But is the callback registered with system_init_done_cb() triggered after a connection to the AP is established or is it triggered once the system boot sequence is complete (regardless of the state of the WiFi connection)?
Thanks
Re: Is user_init() called after connecting to AP?
Posted:
Fri May 15, 2015 9:15 am
by eriksl
It's a little bit different.
The user_init routine is called when barely any initialisation is done. That's good because that way it has major influence on the initialisation and process. That also means you can't cannot to an ap at that stage. You can call the relevant functions but the actual connecting will only take place after initialisation has been completed.
So imho there are a few approaches if you want to connect to a specific access point.
1) simplest; load any AT+ firmware, join the access point, the data will be stored into flash and the next time after reboot the system code will connect to the access point again, even if another firmware is loaded in the meantime
2) disable "autoconnect", and/or disconnect in the user_init code and also connect there. The actual connection will be made when the user_init function has returned, you cannot wait for it
3) add the above callback and do all wifi initialisation there, it will be processed "immediately" (although some things need to run in the background and will run when you return from the callback).
4) add a sytem "post" background task, it will only be called when the system is completely up and running; never wait on something but simply return from the task, let the system do it's processing, and everytime the background task is called, check if it has completed. IMHO that's the best way, because some non-time-critical tasks from the system need to be run regularly and only get run when you return control to the system.