Wifi connection state when user_init() returns
Posted: Wed Jul 22, 2015 11:29 am
Hello folks,
What happens to the wifi connection state when user_init() returns? Also, is user_init() called in some while (true) loop in the actual main function?
The reason I ask this is some of Sprite_tm's code in his espeink project:
How does httpclientFetch() work if the wifi connection is lost upon returning from the user_init() function? The only way I see this working is if the wifi connection persists even after user_init() returns and user_init() is called again by the actual main function.
PS: Regardless, I'll probably try it out myself tomorrow morning
What happens to the wifi connection state when user_init() returns? Also, is user_init() called in some while (true) loop in the actual main function?
The reason I ask this is some of Sprite_tm's code in his espeink project:
Code: Select all
void user_init(void)
{
int rtcmagic;
int batEmptyShown;
stdoutInit();
ioInit();
configLoad();
system_rtc_mem_read(128, &rtcmagic, 4);
system_rtc_mem_read(128+4, &batEmptyShown, 4);
if (rtcmagic!=RTC_MAGIC) {
//Make sure we're in STA+AP mode
if (wifi_get_opmode()!=3) {
wifi_set_opmode(3);
system_restart();
return;
}
//For the next time: start in normal mode
rtcmagic=RTC_MAGIC;
system_rtc_mem_write(128, &rtcmagic, 4);
//Magic word has fallen out of the RTC. Probably means the battery has been changed or
//taken out. Go into reconfig mode.
einkFile=espFsOpen("apconnect.bm");
einkDisplay(2048, fileEinkNeedData, fileEinkDoneCb);
httpdInit(builtInUrls, 80);
os_timer_disarm(&wdtTimer);
os_timer_setfn(&wdtTimer, wdtTimerCb, NULL);
os_timer_arm(&wdtTimer, 120000, 0); //shut down after 120 seconds
return;
}
if (wifi_get_opmode()!=1) {
wifi_set_opmode(1);
system_restart();
return;
}
ioEinkEna(1);
os_delay_us(2000);
//Battery voltage is divided by an 4.7K/1K resistor divider.
//ADC: 1024 = 1V
batteryMeasMv=(system_adc_read()*9765*5.7)/10000;
if (batteryMeasMv<BAT_LOW_LVL_MV) {
//Crap, battery is dying.
if (batEmptyShown!=1) {
os_printf("Battery empty! Showing bat empty icon...\n");
batEmptyShown=1;
system_rtc_mem_write(128+4, &batEmptyShown, 4);
einkFile=espFsOpen("batempty.bm");
einkDisplay(2048, fileEinkNeedData, fileEinkDoneCb);
return;
} else {
os_printf("Battery empty! Sleeping...\n");
sleepmode();
}
} else {
batEmptyShown=0;
system_rtc_mem_write(128+4, &batEmptyShown, 4);
}
os_printf("Datasource %s\n", myConfig.url);
tcpConnState=TCPSTATE_HEADER;
einkHeaderPos=0;
einkHeaderIsValid=0;
httpclientFetch(myConfig.url, httpclientCb, httpclientHdrCb);
einkDisplay(24*1024, tcpEinkNeedData, einkDoneCb);
os_timer_disarm(&wdtTimer);
os_timer_setfn(&wdtTimer, wdtTimerCb, NULL);
os_timer_arm(&wdtTimer, 20000, 0); //shut down after 15 seconds
}
How does httpclientFetch() work if the wifi connection is lost upon returning from the user_init() function? The only way I see this working is if the wifi connection persists even after user_init() returns and user_init() is called again by the actual main function.
PS: Regardless, I'll probably try it out myself tomorrow morning