after some unsuccessful searching for any relevant info, I need to ask for some hints how to make an ESP running TCP server (started with espconn_regist_connectcb) to be capable of low power/sleep modes.
I know how to get the ESP to a sleep if I would have an infinite loop, using wifi_fpm_do_sleep, but how do I do it with the TCP server? I don't have any loop where I could put this.
The only idea I came up with is that I send the ESP to sleep at the end of a request handling, i.e. like this:
// set up callback somewhere
espconn_regist_disconcb(pespconn, shell_tcp_disconcb);
LOCAL void ICACHE_FLASH_ATTR
shell_tcp_disconcb(void *arg) {
struct espconn *pespconn = (struct espconn *) arg;
os_printf("tcp connection disconnected\n");
// go to sleep mode here for some time
}
But how do I resume the sleep if no request comes? I guess I could instead have some global state variable and in main() there would be just dummy loop with the sleep handling - and the disconnect handler would set it to "you can sleep now", while the connection opened handler would forbid the sleep. But is this a good solution? Isn't there some built-in way already in libraries? I would expect I'm trying to invent a wheel with this...
Thanks for any reply.