Fall back to AP mode, when connection to other network fails
con-f-use opened this issue · 5 comments
This version doesn't seem to fall back to AP mode, when connecting to another network fails. ColorChord firmware seems to do that.
This is odd... I left bredcrumbs for me in commonservices.c, maybe this will help.
In colorchord:
if( need_to_switch_back_to_soft_ap == 2 )
{
need_to_switch_back_to_soft_ap = 0;
EnterCritical();
wifi_set_opmode_current( SOFTAP_MODE );
ExitCritical();
}
In ESP8266WS2812I2S
static void ICACHE_FLASH_ATTR SwitchToSoftAP( )
{
EnterCritical();
wifi_set_opmode_current( SOFTAP_MODE );
struct softap_config sc;
wifi_softap_get_config(&sc);
printed_ip = 0;
printf( "SoftAP mode: \"%s\":\"%s\" @ %d %d/%d\n", sc.ssid, sc.password, wifi_get_channel(), sc.ssid_len, wifi_softap_dhcps_status() );
ExitCritical();
}
But, in that, it has this note
retry_count++;
if( retry_count > MAX_RETRY_COUNT )
{
SwitchToSoftAP(); //XXX WARNING: This does not /actually/ work.
} else {
wifi_station_connect(); //re-attempt... 3x.
}
ColorChord also has HandleIPStuff()
in its user_main.c
that ESP8266WS2812I2S doesn't. It's invoked at the end of static void procTask(os_event_t *events)
, but I don't know the code well enough to know, what procTask()
does or when it's called.
static void ICACHE_FLASH_ATTR HandleIPStuff()
{
//Idle Event.
struct station_config wcfg;
char stret[256];
char *stt = &stret[0];
struct ip_info ipi;
int stat = wifi_station_get_connect_status();
//printf( "STAT: %d %d\n", stat, wifi_get_opmode() );
if( stat == STATION_WRONG_PASSWORD || stat == STATION_NO_AP_FOUND || stat == STATION_CONNECT_FAIL )
{
wifi_set_opmode_current( 2 );
stt += ets_sprintf( stt, "Connection failed: %i\n", stat );
uart0_sendStr(stret);
}
if( stat == STATION_GOT_IP && !printed_ip )
{
wifi_station_get_config( &wcfg );
wifi_get_ip_info(0, &ipi);
stt += ets_sprintf( stt, "STAT: %d\n", stat );
stt += ets_sprintf( stt, "IP: %d.%d.%d.%d\n", (ipi.ip.addr>>0)&0xff,(ipi.ip.addr>>8)&0xff,(ipi.ip.addr>>16)&0xff,(ipi.ip.addr>>24)&0xff );
stt += ets_sprintf( stt, "NM: %d.%d.%d.%d\n", (ipi.netmask.addr>>0)&0xff,(ipi.netmask.addr>>8)&0xff,(ipi.netmask.addr>>16)&0xff,(ipi.netmask.addr>>24)&0xff );
stt += ets_sprintf( stt, "GW: %d.%d.%d.%d\n", (ipi.gw.addr>>0)&0xff,(ipi.gw.addr>>8)&0xff,(ipi.gw.addr>>16)&0xff,(ipi.gw.addr>>24)&0xff );
stt += ets_sprintf( stt, "WCFG: /%s/%s/\n", wcfg.ssid, wcfg.password );
uart0_sendStr(stret);
printed_ip = 1;
}
}
Generally I'm a bit lost in the code. There aren't many doc-strings and I've just started getting into the esp stuff, so most of the library functions tell me nothing. But my understanding is improving slowly. Thanks for your help.
procTask is what gets called when the chip is idle. I use a quick tick/slow tick architecture, meaning whenever the chip is idle, it's quick ticking to service everything, then, every 10 - 100 ms, I do a "slowtick" to handle updating of internal timers, etc.
As you start to find things out, especially something that was confusing and now makes sense, please add comments and commit. There are things obvious to me that are not obvious to others!
Seems this has magically disappeared.