Closed HomeACcessoryKid closed 6 years ago
I couldn’t find API that notifies you when WiFi state changes
Indeed, the 'wifi_set_event_handler_cb' routine seemed not to exist when esp-open-rtos forked off. That is a pity. But we can make a simple hack. Remember that effectively everything else is still on hold at this time.
Instead of the timer call a routine, and that same routine calls itself and sets its own timer again. Break out of that routine when you got an IP (polling with sdk_wifi_station_get_connect_status). You can poll every 200ms...
In my code I have the routine espconn_browse do the same (removed non-essential code)
void espconn_browse(void *arg)
{
struct espconn *pespconn = arg;
//do your thing
os_timer_disarm(&browse_timer);
os_timer_setfn(&browse_timer, (os_timer_func_t *)espconn_browse, arg);
os_timer_arm(&browse_timer, 12000, 0);
}
the browse_timer is external so can be malloc and free
Pushed update to poll successful connection every 500ms for max of 15s.
Current observation: there is an unnecessary (and long) wait after the IP is acquired Suggestion: add a callback related to assignment of IP and set a semaphore which does the waiting instead of a timer...