the keep alive seem failed.

wjzhang
Posts: 25
Joined: Thu Jul 30, 2015 9:56 am

the keep alive seem failed.

Postby wjzhang » Thu Nov 26, 2015 6:22 pm

I meet a problem. i want ESP8266 keep alive about 30mins. but always get 20s to disconnect. SDK: 1.41 NO OS :(

here code for set alive .
void ICACHE_FLASH_ATTR
esp_gateway_tcp_connected(void *arg)
{
uint32_t keeplive;
ESP_DBG("connected\r\n");
pclientConnect = (struct espconn *)arg;

//set keepalive: 30mins=1800s = 1500 + 10*30
keeplive = 3000; //1500s: 500ms*3000
espconn_set_keepalive(pclientConnect, ESPCONN_KEEPIDLE, &keeplive);
keeplive = 60; //again 30s: 500ms*60
espconn_set_keepalive(pclientConnect, ESPCONN_KEEPINTVL, &keeplive);
keeplive = 10; //try times
espconn_set_keepalive(pclientConnect, ESPCONN_KEEPCNT, &keeplive);
espconn_set_opt(pclientConnect, ESPCONN_KEEPALIVE);
espconn_set_opt(pclientConnect, ESPCONN_NODELAY);
espconn_set_opt(pclientConnect, ESPCONN_COPY);

//register write finish call back
tcpTxCounter = 0;
tcpTxReadIndex = 0;
tcpTxWriteIndex = 0;
tcpTxInusing = false;
espconn_regist_write_finish(pclientConnect, esp_gateway_tcp_next_send);

/*Send OnCconnected package to MCU*/
meshtalkdevice_onconnect();
//stop advise
esp_platform_advise_enable(false);
}

PC side(using javascript Nodejs v0.10) also set to
//set TCP keepalive to 30 min
remoteDevice.socket.setKeepAlive(true, 1800000);
remoteDevice.socket.setNoDelay(true);\
....

ESP_Faye
Posts: 1610
Joined: Mon Oct 27, 2014 11:08 am

Re: the keep alive seem failed.

Postby ESP_Faye » Fri Nov 27, 2015 12:18 pm

Hi,

Sorry that I'm confused about your question.

You mean that if the TCP connection broke, ESP8266 can know it immediately, need not to wait 30 minutes ?
Or you mean that the TCP connection does not break, but ESP8266 seems to always disconnect the TCP connection after 20s ?

wjzhang
Posts: 25
Joined: Thu Jul 30, 2015 9:56 am

Re: the keep alive seem failed.

Postby wjzhang » Mon Nov 30, 2015 8:19 am

the esp8266 broken the TCP connection when the TCP connetcion idle about 20s. the TCP FIN start from ESP8266.
i want keep TCP alive about 30 minutes when TCP no data send or receive.

wjzhang
Posts: 25
Joined: Thu Jul 30, 2015 9:56 am

Re: the keep alive seem failed.

Postby wjzhang » Mon Nov 30, 2015 4:20 pm

Hi Faye:
Sorry for confuse, it's 2 split issues.
1) if it not call espconn_regist_time(), it should keep TCP alive about 2 hours, why now became 20 seconds?
and why the timeout is 383s after i call espconn_regist_time(&tcpconnect, 180, 0), do you think it deviation too large?

2) do the espconn_set_keepalive() function time uint change to 1 second from 500ms?

ESP_Faye
Posts: 1610
Joined: Mon Oct 27, 2014 11:08 am

Re: the keep alive seem failed.

Postby ESP_Faye » Wed Dec 02, 2015 10:32 am

Hi,

Please update the lib LWIP as the attachment, based on ESP8266_NONOS_SDK_V1.5.0.

1. If did not call espconn_regist_time, the time out will be about 9~10s.
2. The unit of espconn_set_keepalive is 1 second, not 500 ms.

Code: Select all

keeplive = 60; //60s
espconn_set_keepalive(pclientConnect, ESPCONN_KEEPINTVL, &keeplive);

3. You need to call espconn_set_opt to enable TCP keep alive first, then call espconn_set_keepalive to set the configuration.

Code: Select all

uint32_t keeplive;

espconn_set_opt(pesp_conn, ESPCONN_KEEPALIVE); // enable TCP keep alive

//set keepalive: 75s = 60 + 5*3
keeplive = 60;
espconn_set_keepalive(pesp_conn, ESPCONN_KEEPIDLE, &keeplive);
keeplive = 5;
espconn_set_keepalive(pesp_conn, ESPCONN_KEEPINTVL, &keeplive);
keeplive = 3; //try times
espconn_set_keepalive(pesp_conn, ESPCONN_KEEPCNT, &keeplive);


Thanks for your interest in ESP8266 !
Attachments
liblwip_nonOS_SDK_v1.5.0.zip
(227.07 KiB) Downloaded 216 times

wjzhang
Posts: 25
Joined: Thu Jul 30, 2015 9:56 am

Re: the keep alive seem failed.

Postby wjzhang » Fri Dec 04, 2015 3:35 pm

Hi Faye:
what's the time unit of espconn_regist_time()? 1 second?
in my test result, it show the unit is about 2 second. :o
both in SDK 1.4.1 and 1.5.0

ESP_Faye
Posts: 1610
Joined: Mon Oct 27, 2014 11:08 am

Re: the keep alive seem failed.

Postby ESP_Faye » Fri Dec 04, 2015 4:32 pm

Hi,

Did you use the "liblwip_nonOS_SDK_v1.5.0.zip" above ?

wjzhang
Posts: 25
Joined: Thu Jul 30, 2015 9:56 am

Re: the keep alive seem failed.

Postby wjzhang » Mon Dec 07, 2015 8:46 am

Hi Faye:
sorry, i don't known "liblwip_nonOS_SDK_v1.5.0.zip", but i use No OS SDK. it's esp_iot_sdk_v1.5.0_15_11_27.zip and esp_iot_sdk_v1.4.1_pre2_15_10_22.zip.

ESP_Faye
Posts: 1610
Joined: Mon Oct 27, 2014 11:08 am

Re: the keep alive seem failed.

Postby ESP_Faye » Wed Dec 09, 2015 2:46 pm

Hi,

Please have a try with the "liblwip_nonOS_SDK_v1.5.0.zip" I provided above.

If your problem is still unsolved, please feel free to let us know.

pwolf
Posts: 1
Joined: Thu Mar 30, 2017 7:24 am

Re: the keep alive seem failed.

Postby pwolf » Fri Mar 31, 2017 3:39 am

I am using the ESP8266 in a Arduino enviroment and I have multiple clients connecting to the ESP8266 and sometimes a client can drop off unexpectedly and the TCP socket remains open. I am looking for a way to implement a keepalive function and I found this post. I am not sure how to use/implement the keepalive in the Arduino enviroment, any help would be great.

Who is online

Users browsing this forum: No registered users and 1 guest