missing send callback

Bummibaer
Posts: 2
Joined: Mon Nov 30, 2015 6:14 pm

missing send callback

Postby Bummibaer » Wed Dec 02, 2015 9:48 pm

Hi,
I want to send 23 bytes every second to an android device.
My Server Init :

Code: Select all

  serverConn.type = ESPCONN_TCP;
  serverConn.state = ESPCONN_NONE;
  serverTcp.local_port = port;
  serverConn.proto.tcp = &serverTcp;

   rc = espconn_set_opt (conn, ESPCONN_KEEPALIVE  | ESPCONN_COPY | ESPCONN_NODELAY); // enable write buffer
  rc = espconn_regist_write_finish (conn, user_tcp_write_finish); // register write finish callback
   rc = espconn_regist_sentcb (conn, serverSentCb);


The Sequence of tx is:

Code: Select all

send_buf(...)
   if ( ready_tosend) {
       espconn_send(...)
       ready_tosend = false;
   }
}
user_tcp_write_finish() {
}
serverSentCb() {
   ready_tosend = true;
}


The problem after ~10 sends, I don't get any serverSentCb() :( , it's stuck.
If I send again anyway, I get ESPCONN_MAXNUM, and it's also stays.

Is there a way to debug this?

Please help

I'm using esp_iot_sdk_v1.5.0_15_11_27

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

Re: missing send callback

Postby ESP_Faye » Thu Dec 03, 2015 10:20 am

Hi,

If the network environment is not well, the TCP packet will fail to send, then it will retry several times to send the TCP packets.

ESP8266 can hold 8 TCP packets (or 2920 bytes) waiting for sending (or retry sending) at most. "ESPCONN_MAXNUM" means that this limitation is met, you have already got 8 TCP packets waiting for sending.

So you need to wait till the previous packets sent successfully, or use espconn_set_keepalive to shorter the time of detecting whether the TCP connection broke.

Bummibaer
Posts: 2
Joined: Mon Nov 30, 2015 6:14 pm

Re: missing send callback

Postby Bummibaer » Thu Dec 03, 2015 10:50 pm

Thanks for your fast answer.
With ESPCONN_MAXNUM was only for testing. My problem, that the program never gets a callback, neither a disconnect callback.

I've found
espconn_regist_time
What exactly does this function set? Should I set it to 0?
I send every 1 second a frame, is this not enough?

Which debugging is possible?
I send now a Keep-Alive paket from the Smartphone every second. It looks better, but why?

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

Re: missing send callback

Postby ESP_Faye » Fri Dec 04, 2015 11:30 am

Hi,

If the network environment is not well, the TCP packet will fail to send, then it will retry several times to send the TCP packets. You got no callback means it is still retrying.
You can use "espconn_set_opt" and "espconn_set_keepalive" to enable the TCP keep alive function. It will keep detecting whether the TCP connection broke or not.

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);


It means that ESP8266 will check whether the TCP connection broke or not every 60s, and if the first detection gets no response, it will retry the detection 3 times with 5s interval.

espconn_regist_time: when ESP8266 runs as TCP server, it will disconnect to the TCP client that does not actively (does not communicate with ESP8266 till timeout which is 9~10 seconds by default). If you set it to be 0, ESP8266 will never disconnect to the TCP client which is not actively. We do not suggest that.

Who is online

Users browsing this forum: No registered users and 20 guests