ESP8266 Developer Zone The Official ESP8266 Forum 2014-11-08T16:35:31+08:00 https://bbs.espressif.com:443/feed.php?f=7&t=29 2014-11-08T16:35:31+08:00 2014-11-08T16:35:31+08:00 https://bbs.espressif.com:443/viewtopic.php?t=29&p=110#p110 <![CDATA[Re: TCP Client Connection breaks after AP reconnect]]>
1. When module connects to AP for the first time after power-up, everything works perfect
2. When I shut down my AP the module detects and starts reconnecting internally...
3. When I turn my AP back ON, the module reconnects and detects that it is connected, and that it got IP.
4. Now after ~59seconds the module looses WIFI connection and reconnects. This happens forever...

Did anyone else try shutting their AP down while module is in STATION mode and currently connected to WIFI? Now that I think of it, maybe it is my AP that is causing this problem, I can't be sure.

I opened another thread for this issue here: viewtopic.php?f=7&t=33

Statistics: Posted by muris — Sat Nov 08, 2014 4:35 pm


]]>
2014-11-07T01:04:00+08:00 2014-11-07T01:04:00+08:00 https://bbs.espressif.com:443/viewtopic.php?t=29&p=99#p99 <![CDATA[Re: TCP Client Connection breaks after AP reconnect]]> Thanks

Statistics: Posted by muris — Fri Nov 07, 2014 1:04 am


]]>
2014-11-06T03:47:57+08:00 2014-11-06T03:47:57+08:00 https://bbs.espressif.com:443/viewtopic.php?t=29&p=90#p90 <![CDATA[Re: TCP Client Connection breaks after AP reconnect]]>
I changed my code according to user_esp_platform.c and I still have the problem with WIFI loosing connection every ~22 seconds after I turn my Access Point OFF and then ON. If I never turn OFF/ON my Access Point the module works without problems. But as soon as it looses WIFI connection and reconnects, it keeps reconnecting automatically every ~22 seconds for some reason.

I uploaded my changed code to https://github.com/elektronika-ba/ctrl- ... form.c#L42 and here is my log file: http://www.ctrl.ba/20141105202427.txt

The ESP8266EX is always in STATION_MODE and I never change the mode during operation.

I don't know what I am doing wrong as everything is like in "user_esp_platform.c".

Thanks in advance!

Statistics: Posted by muris — Thu Nov 06, 2014 3:47 am


]]>
2014-11-05T20:34:28+08:00 2014-11-05T20:34:28+08:00 https://bbs.espressif.com:443/viewtopic.php?t=29&p=88#p88 <![CDATA[Re: TCP Client Connection breaks after AP reconnect]]>

Statistics: Posted by muris — Wed Nov 05, 2014 8:34 pm


]]>
2014-11-05T20:13:31+08:00 2014-11-05T20:13:31+08:00 https://bbs.espressif.com:443/viewtopic.php?t=29&p=87#p87 <![CDATA[Re: TCP Client Connection breaks after AP reconnect]]> You can refer to user_esp_platform.c in IoT_Demo.

Statistics: Posted by jackon — Wed Nov 05, 2014 8:13 pm


]]>
2014-11-05T19:46:39+08:00 2014-11-05T19:46:39+08:00 https://bbs.espressif.com:443/viewtopic.php?t=29&p=86#p86 <![CDATA[Re: TCP Client Connection breaks after AP reconnect]]>
You advise that I do this:

Code:

espconn_disconnect(ctrlConn);
os_free(ctrlConn); // new line of code

In the meantime, if my method is wrong, do you have any pseudocode of how I should:

1. create a TCP client connection
2. in case of connection break (tcp reconnect callback) how do I re-create the connection
3. in case of connection close (normal closing by server) how do I re-create the connection

I need a TCP Client socket connection that is always connected!

Thanks.

Statistics: Posted by muris — Wed Nov 05, 2014 7:46 pm


]]>
2014-11-05T19:14:30+08:00 2014-11-05T19:14:30+08:00 https://bbs.espressif.com:443/viewtopic.php?t=29&p=85#p85 <![CDATA[Re: TCP Client Connection breaks after AP reconnect]]> espconn_disconnect(ctrlConn) will not free your ctrlConn internal, you should call os_free(ctrlConn) by yourself.
pls post your log here, we will take a look.

Statistics: Posted by jackon — Wed Nov 05, 2014 7:14 pm


]]>
2014-11-05T02:29:33+08:00 2014-11-05T02:29:33+08:00 https://bbs.espressif.com:443/viewtopic.php?t=29&p=83#p83 <![CDATA[TCP Client Connection breaks after AP reconnect]]>
I made a custom firmware to connect to TCP Socket Server and everything works great until WIFI loses connection and reconnects again. I will try to explain:

1. ESP8266EX starts up, and when it gets connected to my AP (I check in timer when wifi_station_get_connect_status() == STATION_GOT_IP because there is no WIFI CONNECTION CALLBACK) then I create a TCP connection by calling my custom function like so:

Code:

struct espconn *ctrlConn; // global variable holding connection

// creates a TCP connection and starts connecting
static void ICACHE_FLASH_ATTR tcp_connection_create(void)
{
   enum espconn_type linkType = ESPCONN_TCP;
   ctrlConn = (struct espconn *)os_zalloc(sizeof(struct espconn));

   ctrlConn->type = linkType;
   ctrlConn->state = ESPCONN_NONE;
   ctrlConn->proto.tcp = (esp_tcp *)os_zalloc(sizeof(esp_tcp));
   ctrlConn->proto.tcp->local_port = espconn_port();
   ctrlConn->proto.tcp->remote_port = ctrlSetup.serverPort;
   os_memcpy(ctrlConn->proto.tcp->remote_ip, ctrlSetup.serverIp, 4);
   ctrlConn->reverse = NULL; // I don't need this, right?
   espconn_regist_connectcb(ctrlConn, tcpclient_connect_cb);
   espconn_regist_reconcb(ctrlConn, tcpclient_recon_cb);

   espconn_connect(ctrlConn);
   uart0_sendStr("TCP connection created.\r\n");
}


When callback function tcpclient_connect_cb() executes, then I start communicating with the server and everything works great without problems.

2. Now, when I turn my AP off, the ESP8266EX detects the connection break and calls a callback function tcpclient_recon_cb(). That function gets parameters: sint8 errType which has value -11 (ESPCONN_CONN), and the state of espconn (arg->State is 6 ... ESPCONN_CLOSE). In that function I call my other function to destroy the connection because I will create it again when AP gets connected again:

Code:

// closes and destroys current connection
static void ICACHE_FLASH_ATTR tcp_connection_destroy(void)
{
   uart0_sendStr("tcp_connection_destroy()\r\n");

   ctrlState &= ~CTRL_STATE_AUTHENTICATED; // my custom variables
   connState = CTRL_TCP_DISCONNECTED; // my custom variables

   espconn_disconnect(ctrlConn); // this will os_free() my ctrlConn so I can create it again by calling tcp_connection_create(); when WIFI gets IP again
}


3. When I turn my AP back ON, after few seconds the ESP8266EX will get connected automatically and it will get IP. My timer will detect that it got IP again and will start the process of connecting a TCP client. Now it connects to TCP successfully, and communication works, but after ~30 seconds I get unexpected TCP connection break and call to my tcpclient_recon_cb() function. Again, it gets parameters sint8 errType which has value -11 (ESPCONN_CONN), and the state of espconn (arg->State is 6 ... ESPCONN_CLOSE). After that I destroy the current connection and recreate it again but from then it just hangs and doesn't work.

What is happening and why does ESP8266EX break the TCP Client connection after few seconds when it gets IP from WIFI AP once again?

Here is my full code if anyone is interested: https://github.com/elektronika-ba/ctrl-esp8266-test
My TCP Client code is in "user/ctrl_platform.c".

I use lubuntu and SDK v0.9.2 to compile everything.

Please HELP because I am going crazy here for three days now!!! :cry:

Statistics: Posted by muris — Wed Nov 05, 2014 2:29 am


]]>