Chat freely about anything...

User avatar
By parmar7725274
#21481 Hi,

In my recent project I want communications between two esp8266 chip without external MCU or router.

To achieve this I have written two different firmware which I'm flashing it to two different chips.
Firmwares are :
1 . Configure esp in "SoftAP" mode, act as TCP server and listen for TCP client connection
2 . configure esp in "STATION " mode, act as a TCP client and tries to connect to TCP server.

I'm facing problem in connection between them and need help to solve it.

When client tries to connect with server it unable to get IP address form AP. Here is log :

SOftAP mode :
mode : sta(18:fe:34:9e:16:b5) + softAP(1a:fe:34:9e:16:b5)
add if0
dhcp server start:(ip:192.168.4.1,mask:255.255.255.0,gw:192.168.4.1)
add if1
bcn 100
add 1
aid 1
station: 18:fe:34:9e:18:21 join, AID = 1
station: 18:fe:34:9e:18:21 leave, AID = 1
rm match
add 1
aid 1
station: 18:fe:34:9e:18:21 join, AID = 1
station: 18:fe:34:9e:18:21 leave, AID = 1


STATION mode:
mode : sta(18:fe:34:9e:18:21)
add if0
scandone
add 0
aid 1
pm open phy_2,type:2 0 0
cnt
reconnect
rm match
pm close 7 0 0/10001392
scandone
add 0
aid 1
pm open phy_2,type:2 0 0
cnt
reconnect
rm match
pm close 7 0 0/10001361
scandone
add 0
aid 1
pm open phy_2,type:2 0 0
cnt
reconnect
rm match
pm close 7 0 0/10000192
WiFi connecting fail


Anyone have idea what's going wrong ?

After successfully completed, I'm going to release code !!

I also posted in companies forum. Here's link. http://bbs.espressif.com/viewtopic.php?f=7&t=544
He suggested solution but it won't work. I also tries with different combinations of mode like STATION + SOFTAP, STATION and SOFTAP but not succeed.

Thanks and regards,
Prakash P.
User avatar
By hdrut
#21511 Can you give some more info on your tests please?
Have your tried connecting other devices to your SoftAP-configured module? What's thre result of that?
Have you tried using 802.11G or B, instead of N?
Have you tried using WPA2_PSK ?

Hope these ideas may help.

Rgds

Horacio
User avatar
By Alex P
#21513 So the client connects, but then leaves (or is forced to) for some reason. Can you post your code here? You are connecting to the AP in the user_init, not the main loop right?

Also what version of SDK are you using?

PS: If you want duplex communication over TCP you might want to have TCP server AND client running on BOTH the softAP and STA devices.
User avatar
By parmar7725274
#21532 Hi,

Thanks Alex P and Hdrut.

Here is code I'm using :

Server :
Code: Select all/******************************************************************************
 * FunctionName : user_set_softap_config
 * Description  : set SSID and password of ESP8266 softAP
 * Parameters   : none
 * Returns      : none
*******************************************************************************/
void ICACHE_FLASH_ATTR
user_set_softap_config(void)
{
   struct softap_config config;

   wifi_softap_get_config(&config);

   os_memset(config.ssid, 0, 32);
   os_memcpy(config.ssid, "NeelKanth", 9);

   os_memset(config.password, 0, 64);
   os_memcpy(config.password, "12345678", 8);

   config.authmode = AUTH_WPA_WPA2_PSK;

   config.ssid_len = 0;

   config.max_connection = 4;

   config.beacon_interval = 100;

   wifi_softap_set_config(&config);

}


/******************************************************************************
 * FunctionName : user_init
 * Description  : entry of user application, init user function here
 * Parameters   : none
 * Returns      : none
*******************************************************************************/
void user_init(void)
{
   uart_init(BIT_RATE_115200, BIT_RATE_115200);
   os_delay_us(100);

    os_printf("SDK version:%s\n", system_get_sdk_version());

    wifi_set_opmode(STATIONAP_MODE);

   // ESP8266 softAP set config.
    user_set_softap_config();

}


Client :
Code: Select allLOCAL os_timer_t test_timer;

/******************************************************************************
 * FunctionName : user_esp_platform_check_ip
 * Description  : check whether get ip addr or not
 * Parameters   : none
 * Returns      : none
*******************************************************************************/
void ICACHE_FLASH_ATTR
user_esp_platform_check_ip(void)
{
    struct ip_info ipconfig;

   //disarm timer first
    os_timer_disarm(&test_timer);

   //get ip info of ESP8266 station
    wifi_get_ip_info(STATION_IF, &ipconfig);

    switch(wifi_station_get_connect_status())
   {
      case STATION_GOT_IP:

         wifi_get_ip_info(STATION_IF, &ipConfig);

         if(ipConfig.ip.addr != 0)
         {
            os_printf("WiFi connected\r\n");
         }
         break;

      case STATION_WRONG_PASSWORD:

         os_printf("WiFi connecting error, wrong password\r\n");
         break;

      case STATION_NO_AP_FOUND:

         os_printf("WiFi connecting error, ap not found\r\n");
         break;

      case STATION_CONNECT_FAIL:

         os_printf("WiFi connecting fail\r\n");
         break;

      default:
   //      os_printf("WiFi connecting...\r\n");
   }

   //re-arm timer to check ip
   os_timer_setfn(&test_timer, (os_timer_func_t *)user_esp_platform_check_ip, NULL);
   os_timer_arm(&test_timer, 100, 0);

}


/******************************************************************************
 * FunctionName : user_set_station_config
 * Description  : set the router info which ESP8266 station will connect to
 * Parameters   : none
 * Returns      : none
*******************************************************************************/
void ICACHE_FLASH_ATTR
user_set_station_config(void)
{
   // Wifi configuration
   char ssid[32] = "NeelKanth";
   char password[64] = "12345678";
   struct station_config stationConf;

   wifi_station_disconnect();
   wifi_station_dhcpc_stop();

   //need not mac address
   stationConf.bssid_set = 0;

   //Set ap settings
   os_memcpy(&stationConf.ssid, ssid, strlen(ssid));
   os_memcpy(&stationConf.password, password, strlen(password));
   wifi_station_set_config(&stationConf);

   wifi_station_connect();
   wifi_station_dhcpc_start();
   wifi_station_set_auto_connect(1);


   //set a timer to check whether got ip from router succeed or not.
   os_timer_disarm(&test_timer);
   os_timer_setfn(&test_timer, (os_timer_func_t *)user_esp_platform_check_ip, NULL);
   os_timer_arm(&test_timer, 100, 0);
}


/******************************************************************************
 * FunctionName : user_init
 * Description  : entry of user application, init user function here
 * Parameters   : none
 * Returns      : none
*******************************************************************************/
void user_init(void)
{
   uart_init(BIT_RATE_115200, BIT_RATE_115200);

    os_printf("SDK version:%s\n", system_get_sdk_version());

   //Set softAP + station mode
   wifi_set_opmode( STATIONAP_MODE );

   // ESP8266 connect to router.
    user_set_station_config();

}


I'm using SDK 1.0.1.

Thanks & Regards,
Prakash P.