-->
Page 1 of 2

ESPCONN_ARG ERROR

PostPosted: Tue Jul 10, 2018 12:24 am
by ade2010
I have 2 esp8288 modules.
Both works in StationAP mode

The first module connects to a router
the second module connects to first modules softAP

the first modules softAP acts as a tcp server
the second modules connects to the first modules softAP as a tcp client

data transfer between both is working as well

now when i connect my laptop to the second modules softAP and start a tcp connection , everything works perfectly. The second module receives the data , but when i try to send the received data to the first modules tcp connection i get a -12(ESPCONN_ARG) error. Can any please help me with this problem?

Thanks in advance.

Re: ESPCONN_ARG ERROR

PostPosted: Wed Jul 11, 2018 5:25 am
by Cicero
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.

Re: ESPCONN_ARG ERROR

PostPosted: Wed Jul 11, 2018 6:27 am
by QuickFix
Cicero wrote:You shouldn't duplicate posts for the same question

I guess that's because TS is a first timer, so his posts are being moderated (which is a bit confusing, because this isn't clearly stated and first posts "Get lost" for a while).
I see this happen a lot, you can't really blame people new here for it.

Re: ESPCONN_ARG ERROR

PostPosted: Thu Jul 12, 2018 11:33 pm
by ade2010
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;