Code: Select all
sleep_time_cnt: 60
enter sleep mode
wifi disconnected
pm close 7
fpm open,type:1 0
fpm 758
ets Jan 8 2013,rst cause:2, boot mode:(3,6)
load 0x40100000, len 2408, room 16
tail 8
chksum 0xe5
load 0x3ffe8000, len 776, room 0
tail 8
chksum 0x84
load 0x3ffe8310, len 632, room 0
tail 8
chksum 0xd8
csum 0xd8
Code: Select all
void ICACHE_FLASH_ATTR user_init(){
PIN_FUNC_SELECT(RED_LIGHT_IO_MUX, RED_LIGHT_IO_FUNC);
drv_Switch_Init();
sleep_init();
os_printf("Firmware Version: 20181101\n");
wifi_set_opmode(STATION_MODE);
wifi_station_get_config_default(&stationConf);
if (os_strlen(stationConf.ssid) != 0) {
os_printf("user_scan\n");
//net_status = 1;
os_timer_disarm(&check_ip_timer);
os_timer_setfn(&check_ip_timer, (os_timer_func_t *) user_check_ip, NULL);
os_timer_arm(&check_ip_timer, 100, 0);
} else {
os_printf("smartcfg\n");
smartconfig_start(smartconfig_done);
net_status = 0;
WIFI_DISCONNTED_FLAG;
}
os_timer_disarm(&light_status_timer);
os_timer_setfn(&light_status_timer, (os_timer_func_t *)led_status_timer_func , NULL);
os_timer_arm(&light_status_timer,MAIN_TIMER_PERIOD,1);
os_timer_disarm(&sleep_timer);
os_timer_setfn(&sleep_timer, (os_timer_func_t *)sleep_timer_func , NULL);
os_timer_arm(&sleep_timer,SLEEP_TIMER_PERIOD,1);
}
Code: Select all
void sleep_init(void){
wifi_fpm_set_sleep_type(LIGHT_SLEEP_T); //set force sleep type, clsoe rf&cpu
wifi_fpm_set_wakeup_cb(fpm_wakup_cb_func1); //Set fpm wakeup callback function
}
Code: Select all
void sleep_start(void )
{
os_printf("enter sleep mode\n\n");
if(wifi_station_get_connect_status() == STATION_GOT_IP){
while(!wifi_station_disconnect()){
os_delay_us(10);
}
os_printf("wifi disconnected\n\n");
} else {
smartconfig_stop();
os_printf("wifi not connected\n\n");
}
os_delay_ms(200);
RED_LIGHT_OFF;
wifi_set_opmode(NULL_MODE); //set wifi mode to null mode.
wifi_fpm_open(); //enable force sleep fucntion
int rst = wifi_fpm_do_sleep(FPM_SLEEP_MAX_TIME); // do sleep
os_printf("sleep rst : %d",rst);
}
Code: Select all
void ICACHE_FLASH_ATTR
sleep_timer_func(void )
{
static uint8_t cnt = 0;
if(sleep_time_cnt < SLEEP_TIME_CNT){
sleep_time_cnt++;
os_printf("sleep_time_cnt: %d\n\n",sleep_time_cnt);
}else {//2 min
sleep_time_cnt = 0;
os_timer_disarm(&check_ip_timer);
os_timer_disarm(&light_status_timer);
os_timer_disarm(&KeyScan_timer);
os_timer_disarm(&sleep_timer);
sleep_start();
}
}