-->
Page 1 of 6

Cannot connect to ESP8266 in AP mode with Android

PostPosted: Thu Jun 04, 2015 2:18 pm
by Dave S
I don't get it. Hopefully, someone knows the secret sauce.

Here's the problem:
  • ESP8266 WIFI is set to AP mode using the SDK 1.0.1 24 April 2015
  • Callback installed to send a serial port message (for testing) when a device joins and leaves the AP
  • My laptop joins and leaves the AP as expected.
  • My iPhone also joins and leaves the AP as expected.
  • My Android smartphone running 4.4.2 will not connect to the AP. The ssid is visible, but no connection made when attempted.
  • My Android tablet also will not connect to the ESP8266 AP.
  • But....if I run an ESP8266 sketch compiled with Arduino IDE 1.6.1 with the ESP8266 in AP, I can join and leave the AP with my Android devices

Does anyone know what the Android IDE for ESP8266 do to satisfy Android devices that is missing from the SDK compiled code? Very strange that it is only a problem with Android devices. :o

Re: Cannot connect to ESP8266 in AP mode with Android

PostPosted: Thu Jun 04, 2015 3:08 pm
by hdrut
Hi, can you provide the following info:

What SSID are you using?
What type of encryption?

Also the piece of code where you set up the AP parameters.


Greetings

Horacio

Re: Cannot connect to ESP8266 in AP mode with Android

PostPosted: Thu Jun 04, 2015 4:29 pm
by Dave S
I set the ssid (WIFI_AP_NAME) to "ESP8266_4" as this is my 4th module in service.

No encryption (AUTH_OPEN). Also tested each encryption type and they all worked with my Windows7 laptop and iPhone but not the Android devices.

Here is the function used to setup the AP mode. Also printed via serial port the wifi_get_opmode() to confirm it was 0x2 (SOFTAP_MODE)
Code: Select allvoid setup_wifi_ap_mode(void)
{
   wifi_set_opmode(SOFTAP_MODE);
   wifi_softap_dhcps_stop();

   struct softap_config apconfig;
   if(wifi_softap_get_config(&apconfig))
   {
      os_memset(apconfig.ssid, 0, sizeof(apconfig.ssid));
      os_memset(apconfig.password, 0, sizeof(apconfig.password));
      os_sprintf(apconfig.ssid, "%s", WIFI_AP_NAME);
      os_sprintf(apconfig.password, "%s", WIFI_AP_PASSWORD);
      apconfig.authmode = AUTH_OPEN;
      apconfig.ssid_hidden = 0;
      apconfig.max_connection = 4;
      apconfig.channel=7;
      if(!wifi_softap_set_config(&apconfig))
      {
         #ifdef PLATFORM_DEBUG
         ets_uart_printf("ESP8266 not set ap config!\r\n");
         #endif
      }
   }

   wifi_set_event_handler_cb(wifi_event_cb);

    LOCAL struct ip_info info;
    IP4_ADDR(&info.ip, 192, 168, 22, 1);
    IP4_ADDR(&info.gw, 192, 168, 22, 1);
    IP4_ADDR(&info.netmask, 255, 255, 255, 0);
    wifi_set_ip_info(SOFTAP_IF, &info);

    struct dhcps_lease dhcp_lease;
    IP4_ADDR(&dhcp_lease.start_ip, 192, 168, 22, 2);
    IP4_ADDR(&dhcp_lease.end_ip, 192, 168, 22, 5);
    wifi_softap_set_dhcps_lease(&dhcp_lease);

    wifi_softap_dhcps_start();
    ets_uart_printf("SOFTAP Status:%d\r\n",wifi_softap_dhcps_status());

}


And here is the WIFI event callback

Code: Select allvoid wifi_event_cb(System_Event_t *evt) {
   static int serverinit=0;
   switch (evt->event) {
      case EVENT_SOFTAPMODE_STACONNECTED:
         ets_uart_printf("station: " MACSTR " join, AID = %d\n",
         MAC2STR(evt->event_info.sta_connected.mac),
         evt->event_info.sta_connected.aid);
         //Start Web Server
         if(!serverinit) {
            user_webserver_init(SERVER_PORT);
            serverinit=1;
         }
         //Start periodic loop
         os_timer_disarm(&loop_timer);
         os_timer_setfn(&loop_timer, (os_timer_func_t *)loop_cb, (void *)0);
         os_timer_arm(&loop_timer, DELAY, 10);
         break;
      case EVENT_SOFTAPMODE_STADISCONNECTED:
         ets_uart_printf("station: " MACSTR " leave, AID = %d\n",
         MAC2STR(evt->event_info.sta_disconnected.mac),
         evt->event_info.sta_disconnected.aid);
         //Stop Web Server
         //???;
         //Stop periodic loop
         os_timer_disarm(&loop_timer);
         break;
      default:
         break;
   }
}


After connection was made, I further confirmed the webserver was functional on my laptop by sending a request to the ESP8266 AP IP (http://192.168.22.1:9703/?request=GetSensors). My server was set to listen on port 9703(SERVER_PORT). The correct JSON string was returned from this request, as programmed in the web server.

But no connection with the Android device?? :cry:

Thanks for any light you might shine on this...

Re: Cannot connect to ESP8266 in AP mode with Android

PostPosted: Thu Jun 04, 2015 5:58 pm
by hdrut
HI,

i have had issues with sizeof() in the past. Try printing the value from sizeof(<yourSSID>) and compare it with the actual length of your SSID (which is 9 i believe).

Also, try CHAR casting in accessing your structure elements (this works for me on android ):

os_sprintf((char *)softApConf.ssid, "%s%02X%02X%02X", sysCfg.softap_ssid, macaddr[3], macaddr[4], macaddr[5] );
os_sprintf((char *)softApConf.password, "%s", sysCfg.softap_pass);

Good luck!