Statistics: Posted by ESP_Faye — Thu Sep 10, 2015 10:25 am
Code:
#define WIFI_STATUS_NAME(status) \
(STATION_IDLE == status ? "STATION_IDLE" : \
(STATION_CONNECTING == status ? "STATION_CONNECTING" : \
(STATION_WRONG_PASSWORD == status ? "STATION_WRONG_PASSWORD" : \
(STATION_NO_AP_FOUND == status ? "STATION_NO_AP_FOUND" : \
(STATION_CONNECT_FAIL == status ? "STATION_CONNECT_FAIL" : \
(STATION_GOT_IP == status ? "STATION_GOT_IP" : "Unknown" ))))))
/******************************************************************************
* FunctionName : wifi_event_handler
* Description : handles the event of wifi connection state change
* Parameters : System_Event_t
* Returns : none
*******************************************************************************/
void ICACHE_FLASH_ATTR
wifi_event_handler(System_Event_t *evt) {
uint8 wifi_status = wifi_station_get_connect_status();
switch (evt->event) {
case EVENT_STAMODE_DISCONNECTED: {
os_printf("-> wifi status : (%d) - ", wifi_status );
switch (wifi_status) {
case STATION_CONNECTING: {
wifi_connect_tries++;
if ( wifi_connect_tries >= wifi_connect_max_tries ) {
os_printf("STATION_CONNECTING..timeout!!!\n");
if (wifi_get_opmode()==STATION_MODE) {
wifi_set_opmode(SOFTAP_MODE);
wifi_connect_tries = 0;
}
else if (wifi_get_opmode()==STATIONAP_MODE) {
}
}
else
os_printf("STATION_CONNECTING..%d\n", wifi_connect_tries);
break;
}
default: {
os_printf("-> %s\n",WIFI_STATUS_NAME(wifi_status));
wifi_connect_tries = 0;
wifi_set_opmode(SOFTAP_MODE);
break;
}
}
break;
} // end EVENT_STAMODE_DISCONNECTED
case EVENT_STAMODE_GOT_IP: {
if (wifi_get_opmode() != STATION_MODE) { // get current mode, if not station
wifi_set_opmode(STATION_MODE); // set current mode to station and save to flash
wifi_connect_tries = 0;
}
break;
}
}
Statistics: Posted by paritosharya007 — Mon Aug 31, 2015 4:27 pm