Outgoing TCP connection in STATIONAP_MODE

geo.espressif
Posts: 28
Joined: Tue Mar 31, 2015 7:27 pm

Outgoing TCP connection in STATIONAP_MODE

Postby geo.espressif » Thu Sep 24, 2015 5:18 pm

I seem to be unable to make an outgoing TCP connection when the chip is set into STATIONAP_MODE, set in init via:

Code: Select all

wifi_set_opmode_current( STATIONAP_MODE );


My connection code is made from the

Code: Select all

case EVENT_STAMODE_GOT_IP
of the wifi event callback, and my connection code is as follows:

Code: Select all

os_memset( &connector, 0, sizeof(connector));
       connector.type = ESPCONN_TCP;
       connector.state = ESPCONN_NONE;
       connector.proto.tcp = &tcp_con;
   
       os_memset( &tcp_con, 0, sizeof(tcp_con));
       tcp_con.local_port = espconn_port();
       tcp_con.remote_port = tcp_port;
       os_memcpy ( tcp_con.remote_ip, serverIp, 4 );

       espconn_regist_connectcb( &connector, tcpConnected );
       espconn_regist_disconcb( &connector, tcpDisconnected );
      
       if ( err = espconn_connect ( &connector ) != 0 )
       {
      os_printf ( "Error connecting: %d", err );
       }


Basically in STATION_MODE, it connects immediately, in STATIONAP_MODE, it doesn't do anything. I was sure to set the local_ip in the tcp structure, and the esp_connect function seems to return '1', which is indicated as an error in the documentation but it doesn't list which one (i.e. anything non 0 is apparently an error, but 1 is not one of the listed types).

Any ideas? Making an outbound connection when an AP is being hosted should work right? I'm using version 1.3 of the SDK.

User avatar
kolban
Posts: 131
Joined: Tue Jun 16, 2015 1:09 pm
Location: Fort Worth, Texas, USA

Re: Outgoing TCP connection in STATIONAP_MODE

Postby kolban » Thu Sep 24, 2015 9:10 pm

This area has always puzzled me. If I set an ESP8266 into Station+AP mode, I take that to mean that the ESP will connect to an access point using the access point SSID and password I must supply. In addition, I also assume that the ESP will allow OTHER stations to connect to it. Since I do not believe that the ESP can act as a router or gateway, if a station connected to the ESP wishes to reach the Internet, it would form a connection to an APP running on the ESP which would then form a connection to an Internet host.

Sounds great in theory ... but where I now get confused is that in Station+AP mode, the ESP is "multi homed" ... i.e. it has TWO network interfaces. One to the network of stations that are connected to it as an access point and one to the network it joined to the external access point. And THAT then leads me to the need for a routing table ... which I have not seen any mention of in any of the docs.

geo.espressif
Posts: 28
Joined: Tue Mar 31, 2015 7:27 pm

Re: Outgoing TCP connection in STATIONAP_MODE

Postby geo.espressif » Thu Sep 24, 2015 11:13 pm

Thanks for the reply Kolban.

The key to this particular issue was that it appears I can't create the connection from within the callback. When I use a system task & create the connection within the callback it seems to work ok.

geo.espressif
Posts: 28
Joined: Tue Mar 31, 2015 7:27 pm

Re: Outgoing TCP connection in STATIONAP_MODE

Postby geo.espressif » Thu Sep 24, 2015 11:38 pm

Worth saying, this wasn't obvious from the documentation. I think its either a bug or could be made clear in the next release.

Anyway thanks for help.

James

Who is online

Users browsing this forum: No registered users and 27 guests