- Thu Jun 04, 2015 4:29 pm
#19478
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??
Thanks for any light you might shine on this...