Cicero wrote:You shouldn't duplicate posts for the same question ---> viewtopic.php?f=160&t=17965
Anyway, sounds like it can't find the espconn connection anymore. Could you post your code of how you're receiving and then sending your data?
My gut feeling is you're trying to transfer the data without extra buffering, and the data buffer is probably being free()'d along with your connection handle before it can do so. I would suggest buffering your data you want to send in the receive callback, then send from that when you can.
sorry for the duplicate post.
Code: Select allint espcon_status = espconn_connect(&TcpSTAClientConn);
//#ifdef PLATFORM_DEBUG
switch(espcon_status)
{
case ESPCONN_OK:
ets_uart_printf("TCP CLINET created.\r\n");
tcpClientFalg = 1;
break;
case ESPCONN_RTE:
ets_uart_printf("Error connection, routing problem.\r\n\r");
break;
case ESPCONN_TIMEOUT:
ets_uart_printf("Error connection, timeout.\r\n\r");
break;
case ESPCONN_MEM:
ets_uart_printf("OUT OF MEMORY.\r\n\r");
break;
case ESPCONN_INPROGRESS:
ets_uart_printf("in progress.\r\n\r");
break;
case ESPCONN_ABRT:
ets_uart_printf("ABORT.\r\n\r");
break;
case ESPCONN_RST:
ets_uart_printf("RESET.\r\n\r");
break;
case ESPCONN_CLSD:
ets_uart_printf("CLOSED \r\n\r");
break;
case ESPCONN_CONN:
ets_uart_printf("NOT CONNECTED\r\n\r");
break;
case ESPCONN_ARG:
ets_uart_printf("ILLEGAL ARGUMENT.\r\n\r");
break;
case ESPCONN_ISCONN:
ets_uart_printf("ALREADY CONNECTED.\r\n\r");
break;
default:
ets_uart_printf("Connection error: %d\r\n\r", (int)espsscon_status);
}
i am getting Connection error: 1. none of the errors mentioned in the espconn.h is received. i have mentioned all the errors in the switch case but i still get error code 1.
my code for tcp connection is as follows
Code: Select allchar tcpserverip[10];
TcpSTAClientConn.proto.tcp = &ConnTcp;
TcpSTAClientConn.type = ESPCONN_TCP;
TcpSTAClientConn.state = ESPCONN_NONE;
//os_sprintf(tcpserverip, "%s", "10.10.10.1");
//uint32_t ip = ipaddr_addr(tcpserverip);
uint32_t ip = ipaddr_addr("10.10.10.1");
os_memcpy(TcpSTAClientConn.proto.tcp->remote_ip, &ip, 4);
TcpSTAClientConn.proto.tcp->local_port = 1234;//espconn_port();
TcpSTAClientConn.proto.tcp->remote_port = 2345;
espconn_regist_connectcb(&TcpSTAClientConn, tcp_connect_cb);
espconn_regist_reconcb(&TcpSTAClientConn, tcp_reconnect_cb);
espconn_regist_disconcb(&TcpSTAClientConn, tcp_disconnect_cb);
//#ifdef PLATFORM_DEBUG
ets_uart_printf("Start espconn_connect to " IPSTR ":%d\r\n", IP2STR(TcpSTAClientConn.proto.tcp->remote_ip), TcpSTAClientConn.proto.tcp->remote_port);
//#endif
//#ifdef LWIP_DEBUG
ets_uart_printf("Start espconn_connect local port %u\r\n", TcpSTAClientConn.proto.tcp->local_port);
//#endif
ets_uart_printf("FREE HEAP = %d\r\n",system_get_free_heap_size());
int espcon_status = espconn_connect(&TcpSTAClientConn);
//#ifdef PLATFORM_DEBUG
switch(espcon_status)
{
case ESPCONN_OK:
ets_uart_printf("TCP CLINET created.\r\n");
tcpClientFalg = 1;
break;
case ESPCONN_RTE:
ets_uart_printf("Error connection, routing problem.\r\n\r");
break;
case ESPCONN_TIMEOUT:
ets_uart_printf("Error connection, timeout.\r\n\r");
break;
case ESPCONN_MEM:
ets_uart_printf("OUT OF MEMORY.\r\n\r");
break;
case ESPCONN_INPROGRESS:
ets_uart_printf("in progress.\r\n\r");
break;
case ESPCONN_ABRT:
ets_uart_printf("ABORT.\r\n\r");
break;
case ESPCONN_RST:
ets_uart_printf("RESET.\r\n\r");
break;
case ESPCONN_CLSD:
ets_uart_printf("CLOSED \r\n\r");
break;
case ESPCONN_CONN:
ets_uart_printf("NOT CONNECTED\r\n\r");
break;
case ESPCONN_ARG:
ets_uart_printf("ILLEGAL ARGUMENT.\r\n\r");
break;
case ESPCONN_ISCONN:
ets_uart_printf("ALREADY CONNECTED.\r\n\r");
break;
default:
ets_uart_printf("Connection error: %d\r\n\r", (int)espsscon_status);
}
my code for soft tcp data rec callback is as follows
Code: Select allLOCAL void ICACHE_FLASH_ATTR sap_tcp_server_rec_cb(void *arg,char* data,uint16_t len){
struct espconn *con = arg;
ets_uart_printf("sap_tcp rec data: %s \n\r",data); // this will go to the tcp connection
espconn_sent(&TcpSTAClientConn,"helloWorld\n\r",strlen("helloWorld\n\r"));
i have declared TcpSTAClientConn as a global variable
Code: Select allLOCAL struct espconn TcpSTAClientConn;