result every 15 minutes via TCP to a server in my local net.
The sleep phases are done by calling
wifi_fpm_set_sleep_type(LIGHT_SLEEP_T) and
wifi_fpm_do_sleep(sleep_time).
Since sleep_time has a maximal value of about 4 minutes 28 seconds
(268.435.455 mmsec) I had to program a loop with several sleep calls.
Everything works fine but after exactly 4 hours 34 minutes and 40
seconds the system stops working.
This timing is independent of the sleep_time value in the loop
(I tried 3 minutes/5 loops, 4 minutes/4 loops and other values) and
always after 4 hours 34 minutes and 40 seconds I got a "silent death".
I stripped down the program, eliminating all handling except the
sleep calls and after the same time as before: silent death.
Very very weird !
The source of the test program is attached below (add uart.c from SDK)
The test takes a long time (3.6 hours!) until the error happens!
Code: Select all
/*
* user_main.c - Testprogram for
* error in wifi_fpm_set_wakeup_cb()
*
* Author: Wolfgang Gothier
* Created on: 2016-07-05
*/
#include "user_config.h"
#include <c_types.h>
#include <os_type.h>
#include <osapi.h>
#include <user_interface.h>
#define user_procTaskPrio 0
#define user_procTaskQueueLen 1
#define sleepLoops 5 // 5 loops for 15 minutes sleeping
#define sleep_time 180000000 // 3 minutes
#define action_time 8000 // 8 seconds
extern int ets_uart_printf(const char *fmt, ...);
int (*console_printf)(const char *fmt, ...) = ets_uart_printf;
void intr_loop_sleep(void *arg);
void intr_loop_last(void *arg);
void action(void);
static os_timer_t action_evaluate;
os_event_t user_procTaskQueue[user_procTaskQueueLen];
LOCAL uint8_t sleepcount;
LOCAL uint32_t timeroverflow = 0;
LOCAL uint32_t last_time = 0;
LOCAL uint32_t time_overflow_value = (0xFFFFFFFFF / 10000);
const char *FlashSizeMap[] = { "512 KB (256 KB + 256 KB)", // 0x00
"256 KB", // 0x01
"1024 KB (512 KB + 512 KB)", // 0x02
"2048 KB (512 KB + 512 KB)" // 0x03
"4096 KB (512 KB + 512 KB)"// 0x04
"2048 KB (1024 KB + 1024 KB)"// 0x05
"4096 KB (1024 KB + 1024 KB)" // 0x06
};
/* ------ subroutine print time ------ */
void print_time(void) {
char buffer[32];
uint32_t time;
time = system_get_time() / 10000 + timeroverflow;
if ( time < last_time ) {
timeroverflow += time_overflow_value;
time += time_overflow_value;
}
last_time = time;
console_printf("Time = %5d.%02d sec\r\n", time / 100,
(time - ((int) (time / 100)) * 100));
}
void intr_loop_sleep(void *arg) {
/* ------ wakeup callback routine for multiple sleep calls ------ */
sint8 retcode;
os_delay_us(500000);
console_printf("awaken at");
print_time();
wifi_fpm_close(); // disable force sleep function
wifi_fpm_set_sleep_type(LIGHT_SLEEP_T); // light sleep
wifi_fpm_open(); // enable force sleep
sleepcount -= 1; // decrement loop counter
if (sleepcount > 0) {
wifi_fpm_set_wakeup_cb(intr_loop_sleep); // loop again
} else {
wifi_fpm_set_wakeup_cb(intr_loop_last); // awake for measure
}
do {
retcode = wifi_fpm_do_sleep(sleep_time);
if (retcode != 0) {
console_printf("error %d on wifi_fpm_do_sleep\r\n", retcode);
os_delay_us(1000000); // wait a second
}
} while (retcode != 0);
}
void intr_loop_last(void *arg) {
/* ------ wakeup callback routine after last sleep call ------ */
char buff[10];
console_printf("awaken (last) at ");
print_time();
wifi_fpm_close(); // disable force sleep function
os_delay_us(500000);
action();
}
void intr_action_finished(void *arg) {
/* ------ subroutine start sleep loop after action ------ */
os_delay_us(500000);
console_printf("start sleep loop at ");
print_time();
os_timer_disarm(&action_evaluate);
sleepcount = sleepLoops - 1; // except first and last
/* the wifi_fpm_do_sleep(time) has a maximum time of
* about 268 seconds. In order to sleep 15 Minutes
* we must use a sleep loop here */
wifi_set_opmode(NULL_MODE); // set WiFi mode to null mode.
wifi_fpm_set_sleep_type(LIGHT_SLEEP_T); // light sleep
wifi_fpm_open(); // enable force sleep
wifi_fpm_set_wakeup_cb(intr_loop_sleep); // Set wakeup callback
sint8 retcode;
do {
retcode = wifi_fpm_do_sleep(sleep_time); // first sleep
if (retcode != 0) {
console_printf("error %d on wifi_fpm_do_sleep\r\n",
retcode);
os_delay_us(1000000); // wait a second
}
} while (retcode != 0);
}
void action(void) {
console_printf("simulate actions now\r\n");
os_timer_setfn(&action_evaluate, (os_timer_func_t *) intr_action_finished,
NULL);
os_timer_arm(&action_evaluate, action_time, 0);
}
LOCAL void initDone() {
gpio_init();
console_printf("==== System info: ====\r\n");
console_printf("SDK version:%s rom %d\r\n", system_get_sdk_version(),
system_upgrade_userbin_check());
console_printf("Time = %ld\r\n", system_get_time());
console_printf("Chip id = 0x%x\r\n", system_get_chip_id());
console_printf("CPU freq = %d MHz\r\n", system_get_cpu_freq());
console_printf("Flash size map = %s\r\n",
FlashSizeMap[system_get_flash_size_map()]);
console_printf("Free heap size = %d\r\n", system_get_free_heap_size());
action();
} // End of initDone
static void ICACHE_FLASH_ATTR user_procTask(os_event_t *events) {
os_delay_us(5000);
}
void ICACHE_FLASH_ATTR user_init(void) {
uart_init(115200, 115200);
console_printf("\r\n");
console_printf("Start\r\n");
os_delay_us(1000);
system_init_done_cb(initDone);
system_os_task(user_procTask, 0, user_procTaskQueue, 1);
}