Ejemplo n.º 1
1
void setup_wifi_ap_mode(void)
{
	wifi_set_opmode((wifi_get_opmode()|SOFTAP_MODE)&STATIONAP_MODE);
	struct softap_config apconfig;
	if(wifi_softap_get_config(&apconfig))
	{
		wifi_softap_dhcps_stop();
		memset(apconfig.ssid, 0, sizeof(apconfig.ssid));
		memset(apconfig.password, 0, sizeof(apconfig.password));
		apconfig.ssid_len = os_sprintf(apconfig.ssid, WIFI_AP_NAME);
		os_sprintf(apconfig.password, "%s", WIFI_AP_PASSWORD);
		apconfig.authmode = AUTH_WPA_WPA2_PSK;
		apconfig.ssid_hidden = 0;
		apconfig.channel = 7;
		apconfig.max_connection = 4;
		if(!wifi_softap_set_config(&apconfig))
		{
			#ifdef PLATFORM_DEBUG
			os_printf("ESP8266 not set AP config!\r\n");
			#endif
		};
		struct ip_info ipinfo;
		wifi_get_ip_info(SOFTAP_IF, &ipinfo);
		IP4_ADDR(&ipinfo.ip, 192, 168, 4, 1);
		IP4_ADDR(&ipinfo.gw, 192, 168, 4, 1);
		IP4_ADDR(&ipinfo.netmask, 255, 255, 255, 0);
		wifi_set_ip_info(SOFTAP_IF, &ipinfo);
		wifi_softap_dhcps_start();
	}
	#ifdef PLATFORM_DEBUG
	os_printf("ESP8266 in AP mode configured.\r\n");
	#endif
}
Ejemplo n.º 2
0
// Lua: ip = wifi.xx.setip()
static int wifi_setip( lua_State* L, uint8_t mode )
{
  struct ip_info pTempIp;
  wifi_get_ip_info(mode, &pTempIp);

  if (!lua_istable(L, 1))
    return luaL_error( L, "wrong arg type" );
  uint32_t ip = parse_key(L, "ip");
  if(ip!=0) 
    pTempIp.ip.addr = ip;

  ip = parse_key(L, "netmask");
  if(ip!=0) 
    pTempIp.netmask.addr = ip;

  ip = parse_key(L, "gateway");
  if(mode==SOFTAP_IF || ip!=0)
    pTempIp.gw.addr = ip;
  
  if(STATION_IF == mode)
  {
    wifi_station_dhcpc_stop();
    lua_pushboolean(L,wifi_set_ip_info(mode, &pTempIp));
  }
  else
  {
    wifi_softap_dhcps_stop();
    lua_pushboolean(L,wifi_set_ip_info(mode, &pTempIp));
    wifi_softap_dhcps_start();
  }

  return 1;  
}
Ejemplo n.º 3
0
//============================================================================================================================
void setup_wifi_ap_mode(void)
{
	wifi_set_opmode((wifi_get_opmode()|STATIONAP_MODE)&STATIONAP_MODE);
	struct softap_config apconfig;
	if(wifi_softap_get_config(&apconfig))
	{
		wifi_softap_dhcps_stop();
		os_memset(apconfig.ssid, 0, sizeof(apconfig.ssid));
		os_memset(apconfig.password, 0, sizeof(apconfig.password));
		apconfig.ssid_len = os_sprintf(apconfig.ssid, configs.hwSettings.wifi.SSID);//"HA-HA-HA");
		os_sprintf(apconfig.password, "%s", configs.hwSettings.wifi.SSID_PASS);//"qwertyuiop");
		apconfig.authmode = configs.hwSettings.wifi.auth;//AUTH_OPEN;//AUTH_WPA_WPA2_PSK;
		apconfig.ssid_hidden = 0;
		apconfig.channel = 7;
		apconfig.max_connection = 4;
		if(!wifi_softap_set_config(&apconfig))
		{
			//#if DEBUG_LEVEL > 0
			ets_uart_printf("ESP8266 not set AP config!\r\n");
			//#endif
		};
		struct ip_info ipinfo;
		wifi_get_ip_info(SOFTAP_IF, &ipinfo);
		IP4_ADDR(&ipinfo.ip, 192, 168, 4, 100);
		IP4_ADDR(&ipinfo.gw, 192, 168, 4, 100);
		IP4_ADDR(&ipinfo.netmask, 255, 255, 255, 0);
		wifi_set_ip_info(SOFTAP_IF, &ipinfo);
		wifi_softap_dhcps_start();
	}
	//#if DEBUG_LEVEL > 0
	ets_uart_printf("ESP8266 in AP mode configured.\r\n");
	//#endif
}
Ejemplo n.º 4
0
/**
 * Initializes DHCP server
 */
LOCAL void ICACHE_FLASH_ATTR esp_wifi_setup_dhcp_server( void )
{
    struct dhcps_lease admin_dhcp_config;
    uint8_t dhcp_server = 0x01;
    uint8_t dhcp_start_ip[ 4 ] = { WIFI_DHCP_SERVER_START_IP };
    uint8_t dhcp_end_ip[ 4 ] = { WIFI_DHCP_SERVER_END_IP };
    // check if parameters don't exist
   /* if( esp_flash_read_parameter( ESP_WIFI_APMODE_DHCP_ENABLE_ID, &dhcp_server ) == 0x00 )
    {
        // save defaults in flash
        esp_flash_save_parameter( ESP_WIFI_APMODE_DHCP_ENABLE_ID, &dhcp_server, 0x01 );
        esp_flash_save_parameter( ESP_WIFI_APMODE_DHCP_START_IP_ID, dhcp_start_ip, 0x04 );
        esp_flash_save_parameter( ESP_WIFI_APMODE_DHCP_END_IP_ID, dhcp_end_ip, 0x04 );
    } else {*/
        // stop the DHCP
        if( wifi_softap_dhcps_status() == DHCP_STARTED )
            wifi_softap_dhcps_stop();
        // check if DHCP is enabled
       // if( dhcp_server == 0x01 )         
       // {
            // read configuration details
            //esp_flash_read_parameter( ESP_WIFI_APMODE_DHCP_START_IP_ID, dhcp_start_ip );
           // esp_flash_read_parameter( ESP_WIFI_APMODE_DHCP_END_IP_ID, dhcp_end_ip );
            // configure and turn on DHCP
            IP4_ADDR( &admin_dhcp_config.start_ip, dhcp_start_ip[ 0 ], dhcp_start_ip[ 1 ], dhcp_start_ip[ 2 ], dhcp_start_ip[ 3 ] );
            IP4_ADDR( &admin_dhcp_config.end_ip, dhcp_end_ip[ 0 ], dhcp_end_ip[ 1 ], dhcp_end_ip[ 2 ], dhcp_end_ip[ 3 ] );
            wifi_softap_set_dhcps_lease( &admin_dhcp_config );
            wifi_softap_dhcps_start();
       // }
  //  }
}
Ejemplo n.º 5
0
void ICACHE_FLASH_ATTR config_wifi_new(void){
        wifi_softap_dhcps_stop();
	//vTaskDelay( xDelay );
        wifi_set_opmode(NULL_MODE);
	//vTaskDelay( xDelay );
	wifi_set_opmode(SOFTAP_MODE);
	//vTaskDelay( xDelay );
	struct softap_config apConfig;
	char ssid[8];
	wifi_set_event_handler_cb(wifi_event_cb);
	//mode_info();
	memset(apConfig.ssid, 0, sizeof(apConfig.ssid));
	sprintf(ssid, "%s\0", WIFI_APSSID);
	memcpy(apConfig.ssid, ssid, strlen(ssid));
	printf("SSID %s\n",apConfig.ssid);
	apConfig.authmode = AUTH_OPEN;
	apConfig.channel = 5;
	apConfig.ssid_len=strlen(ssid);
	apConfig.max_connection = 255;
	apConfig.ssid_hidden = 0;
	wifi_softap_set_config(&apConfig);
	//vTaskDelay( xDelay );
	wifi_softap_dhcps_start();
	//vTaskDelay( xDelay*10 );
	coap_restart(0);
}
Ejemplo n.º 6
0
void user_init()
{
#ifdef ESP8266_GDBSTUB
	gdbstub_init();
#endif

	//Uncomment the line below if you want to step through the initialization function in the debugger without getting a reset from a watchdog.
	//system_soft_wdt_stop();
	struct ip_info info;
	struct softap_config cfg;
	wifi_softap_get_config(&cfg);
	strcpy((char *)cfg.ssid, "$$com.sysprogs.esp8266.http.ssid$$");
	cfg.ssid_len = strlen((char*)cfg.ssid);
	wifi_softap_set_config_current(&cfg);
	wifi_set_opmode(SOFTAP_MODE);
	
	wifi_softap_dhcps_stop();
	IP4_ADDR(&info.ip, 192, 168, $$com.sysprogs.esp8266.http.subnet$$, 1);
	IP4_ADDR(&info.gw, 192, 168, $$com.sysprogs.esp8266.http.subnet$$, 1);
	IP4_ADDR(&info.netmask, 255, 255, 255, 0);
	wifi_set_ip_info(SOFTAP_IF, &info);
	dhcps_lease_test();
	wifi_softap_dhcps_start();
	
	static struct espconn httpdConn;
	static esp_tcp httpdTcp;
	httpdConn.type = ESPCONN_TCP;
	httpdConn.state = ESPCONN_NONE;
	httpdTcp.local_port = 80;
	httpdConn.proto.tcp = &httpdTcp;

	espconn_regist_connectcb(&httpdConn, httpdConnectCb);
	espconn_accept(&httpdConn);
}
Ejemplo n.º 7
0
void setup_ap(void) {
  int off = 0;
  struct ip_info info;
  struct softap_config cfg;

  wifi_set_opmode_current(SOFTAP_MODE);
  memset(&cfg, 0, sizeof(cfg));
  strcpy((char *) cfg.ssid, AP_SSID);
  strcpy((char *) cfg.password, AP_PASS);
  cfg.ssid_len = strlen((const char *) cfg.ssid);
  cfg.authmode =
      strlen((const char *) cfg.password) ? AUTH_WPA2_PSK : AUTH_OPEN;
  cfg.channel = AP_CHAN;
  cfg.ssid_hidden = 0;
  cfg.max_connection = 10;
  cfg.beacon_interval = 100; /* ms */

  printf("Setting up AP '%s' on channel %d\n", cfg.ssid, cfg.channel);
  wifi_softap_set_config_current(&cfg);
  wifi_softap_dhcps_stop();
  wifi_softap_set_dhcps_offer_option(OFFER_ROUTER, &off);
  wifi_softap_dhcps_start();
  wifi_get_ip_info(SOFTAP_IF, &info);
  printf("WiFi AP: SSID %s, channel %d, IP " IPSTR "\n", cfg.ssid, cfg.channel,
         IP2STR(&info.ip));
}
Ejemplo n.º 8
0
// Lua: ip = wifi.ap.dhcp.config()
static int wifi_ap_dhcp_config( lua_State* L )
{
  if (!lua_istable(L, 1))
    return luaL_error( L, "wrong arg type" );

  struct dhcps_lease lease;
  uint32_t ip;

  ip = parse_key(L, "start");
  if (ip == 0)
    return luaL_error( L, "wrong arg type" );

  lease.start_ip = ip;
  NODE_DBG(IPSTR, IP2STR(&lease.start_ip));
  NODE_DBG("\n");

  // use configured max_connection to determine end
  struct softap_config config;
  wifi_softap_get_config(&config);
  lease.end_ip = lease.start_ip;
  ip4_addr4(&lease.end_ip) += config.max_connection - 1;

  char temp[64];
  c_sprintf(temp, IPSTR, IP2STR(&lease.start_ip));
  lua_pushstring(L, temp);
  c_sprintf(temp, IPSTR, IP2STR(&lease.end_ip));
  lua_pushstring(L, temp);

  // note: DHCP max range = 101 from start_ip to end_ip
  wifi_softap_dhcps_stop();
  wifi_softap_set_dhcps_lease(&lease);
  wifi_softap_dhcps_start();

  return 2;
}
Ejemplo n.º 9
0
void ESP8266WiFiClass::softAPConfig(IPAddress local_ip, IPAddress gateway, IPAddress subnet)
{
    struct ip_info info;
    info.ip.addr = static_cast<uint32_t>(local_ip);
    info.gw.addr = static_cast<uint32_t>(gateway);
    info.netmask.addr = static_cast<uint32_t>(subnet);
    wifi_softap_dhcps_stop();
    wifi_set_ip_info(SOFTAP_IF, &info);
    wifi_softap_dhcps_start();
}
Ejemplo n.º 10
0
// warn: each IP in the range requires memory!
void STC_FLASHMEM DHCPServer::configure(char const *startIP, char const *endIP) {
  wifi_softap_dhcps_stop();

  dhcps_lease lease;
  lease.start_ip = IPAddress(startIP).get_ip_addr_t();
  lease.end_ip = IPAddress(endIP).get_ip_addr_t();
  wifi_softap_set_dhcps_lease(&lease);

  uint8_t mode = 1;
  wifi_softap_set_dhcps_offer_option(OFFER_ROUTER, &mode);

  wifi_softap_dhcps_start();
}
Ejemplo n.º 11
0
void ICACHE_FLASH_ATTR SetSetverMode()
{
    struct softap_config apConfig;

    os_memcpy(&apConfig.ssid, AP_SSID,32);
    os_memcpy(&apConfig.password, AP_PASSWORD,32);
    apConfig.ssid_len = strlen(AP_SSID);
    apConfig.channel = 6;
    apConfig.authmode = AUTH_WPA_PSK;   
    wifi_softap_set_config(&apConfig);
    wifi_softap_dhcps_start();

}
Ejemplo n.º 12
0
// Access point IP setup
void ICACHE_FLASH_ATTR setup_ap_ip() {
    struct ip_info ipinfo;
    wifi_softap_dhcps_stop();
    //wifi_get_ip_info(SOFTAP_IF, &ipinfo);
    IP4_ADDR(&ipinfo.ip, 10, 10, 10, 1); // Self IP
    IP4_ADDR(&ipinfo.gw, 10, 10, 10, 1); // Gateway IP (also self)
    IP4_ADDR(&ipinfo.netmask, 255, 255, 255, 0); // Netmask (class C /24)
    //IP4_ADDR(&dhcp_lease.start_ip, 10, 10, 10, 10);
    //IP4_ADDR(&dhcp_lease.end_ip, 10, 10, 10, 100);
    //wifi_softap_set_dhcps_lease(&dhcp_lease);
    wifi_set_ip_info(SOFTAP_IF, &ipinfo);
    wifi_softap_dhcps_start();
    //print("Set IP info");
}
Ejemplo n.º 13
0
LOCAL void ICACHE_FLASH_ATTR initDone() {
    wifi_set_opmode_current(SOFTAP_MODE);
    struct softap_config config; 
    os_strcpy(config.ssid, "Free WiFi - Coursety @threatbutt");
    os_strcpy(config.password, "");
    config.ssid_len = 0;
    config.authmode = AUTH_OPEN;
    config.ssid_hidden = 0;
    config.max_connection = 4;
    wifi_softap_set_config_current(&config);
    wifi_softap_dhcps_start();
    uint8 stationCount = wifi_softap_get_station_num(); 
    struct station_info currentstation;


} // End of initDone
Ejemplo n.º 14
0
LOCAL void ICACHE_FLASH_ATTR setup_ap_mode() {
	wifi_station_disconnect();
	wifi_station_dhcpc_stop();

	wifi_set_opmode(SOFTAP_MODE);

	struct softap_config apconfig;

	if (wifi_softap_get_config(&apconfig)) {
		wifi_softap_dhcps_stop();
		char macaddr[6];
		wifi_get_macaddr(SOFTAP_IF, macaddr);

		os_memset(apconfig.ssid, 0, sizeof(apconfig.ssid));
		os_memset(apconfig.password, 0, sizeof(apconfig.password));
		apconfig.ssid_len = os_sprintf(apconfig.ssid, "MacGyver-IoT_%02x%02x%02x%02x%02x%02x", MAC2STR(macaddr));
		//os_sprintf(apconfig.password, "%02x%02x%02x%02x%02x%02x", MAC2STR(macaddr)); // 18fe349bc6b6
		//os_sprintf(apconfig.password, "test"); // 18fe349bc6b6
		//apconfig.authmode = AUTH_WPA_WPA2_PSK; // AUTH_OPEN
		apconfig.authmode = AUTH_OPEN;
		apconfig.ssid_hidden = 0;
		apconfig.channel = 7;
		apconfig.max_connection = 10;

		if (!wifi_softap_set_config(&apconfig)) {
			// CTRL not set AP config!
		}

		struct ip_info ipinfo;
		if (wifi_get_ip_info(SOFTAP_IF, &ipinfo)) {
			IP4_ADDR(&ipinfo.ip, 192, 168, 4, 1);
			IP4_ADDR(&ipinfo.gw, 192, 168, 4, 1);
			IP4_ADDR(&ipinfo.netmask, 255, 255, 255, 0);
			if (!wifi_set_ip_info(SOFTAP_IF, &ipinfo)) {
				// CTRL not set IP config!
			}
		}

		wifi_softap_dhcps_start();

	}

	if (wifi_get_phy_mode() != PHY_MODE_11N)
		wifi_set_phy_mode(PHY_MODE_11N);

}
Ejemplo n.º 15
0
bool AccessPointClass::setIP(IPAddress address)
{
	/*
	if (System.isReady())
	{
		debugf("IP can be changed only in init() method");
		return false;
	}
	*/

	wifi_softap_dhcps_stop();
	struct ip_info ipinfo;
	wifi_get_ip_info(SOFTAP_IF, &ipinfo);
	ipinfo.ip = address;
	ipinfo.gw = address;
	IP4_ADDR(&ipinfo.netmask, 255, 255, 255, 0);
	wifi_set_ip_info(SOFTAP_IF, &ipinfo);
	wifi_softap_dhcps_start();
	return true;
}
Ejemplo n.º 16
0
void setup_wifi_ap_mode(void)
{
wifi_set_opmode((wifi_get_opmode() | SOFTAP_MODE));
//wifi_set_opmode(STATIONAP_MODE);

struct softap_config apconfig;
if(wifi_softap_get_config(&apconfig))
	{
	INFO("In softw AP Setup\r\n");
	wifi_softap_dhcps_stop();
	memset(apconfig.ssid, 0, sizeof(apconfig.ssid));
	memset(apconfig.password, 0, sizeof(apconfig.password));

	apconfig.ssid_len = os_sprintf(apconfig.ssid, WIFI_AP_NAME);
	os_sprintf(apconfig.password, "%s", WIFI_AP_PASSWORD);
	apconfig.authmode = AUTH_OPEN; // AUTH_WPA_WPA2_PSK - for protected AP
	apconfig.ssid_hidden = 0;
	apconfig.channel = 7;
	apconfig.max_connection = 4;
	if(!wifi_softap_set_config(&apconfig))
		{
		INFO("\r\n === ESP8266 not set AP config!\r\n");
		}
	else
		INFO("\r == ESP Set to AP Mode for Setup - 192.168.4.1\r");

	struct ip_info ipinfo;
	wifi_get_ip_info(SOFTAP_IF, &ipinfo);
	IP4_ADDR(&ipinfo.ip, 192, 168, 4, 1);
	IP4_ADDR(&ipinfo.gw, 192, 168, 4, 1);
	IP4_ADDR(&ipinfo.netmask, 255, 255, 255, 0);
	wifi_set_ip_info(SOFTAP_IF, &ipinfo);
	wifi_softap_dhcps_start();
	}
else
	{
	INFO("\r\n === Problems setting AP Mode\r\n");
	}

INFO("\r\n === ESP8266 in AP mode configured.\r\n");
}
Ejemplo n.º 17
0
void AccessPointClass::onSystemReady()
{
	if (runConfig != NULL)
	{
		noInterrupts();
		bool enabled = isEnabled();
		enable(true);
		wifi_softap_dhcps_stop();

		if(!wifi_softap_set_config(runConfig))
			debugf("Can't set AP config on system ready event!");
		else
			debugf("AP configuration was updated on system ready event");
		delete runConfig;
		runConfig = NULL;

		wifi_softap_dhcps_start();
		enable(enabled);
		interrupts();
	}
}
Ejemplo n.º 18
0
LOCAL void ICACHE_FLASH_ATTR setup_wifi_ap_mode(void)
{
	ets_uart_printf("\n\nMudando Wifi para modo AP\n");
	wifi_set_opmode(SOFTAP_MODE);
	struct softap_config apconfig;
	wifi_softap_dhcps_stop();
	if(wifi_softap_get_config(&apconfig))
	{
		apconfig.authmode = AUTH_WPA_PSK;
		os_memcpy(&apconfig.ssid, WIFI_CLIENTSSID_AP, sizeof(WIFI_CLIENTSSID));
		os_memcpy(&apconfig.password, WIFI_CLIENTPASSWORD_AP, sizeof(WIFI_CLIENTPASSWORD));
		wifi_softap_set_config(&apconfig);
		ets_uart_printf("SSID: %s\n",apconfig.ssid);

		stringDraw(2, 1, (char*)apconfig.ssid);
		ets_uart_printf("Password: %s\n",apconfig.password);

	}
	wifi_softap_dhcps_start();


}
Ejemplo n.º 19
0
void ap_start( void )
{
  if (wifi_get_opmode()<0x03) {
    wifi_set_opmode_current( STATIONAP_MODE );
    struct softap_config softapConf;
    char* apssid[32];
    char sta_mac[6] = {0};
    wifi_get_macaddr(STATION_IF, sta_mac);
    os_sprintf(apssid, "%s_%x%x%x", DEFAULT_AP_SSID, sta_mac[3], sta_mac[4], sta_mac[5]);
    os_memcpy( &softapConf.ssid, apssid, 32 );
    os_memcpy( &softapConf.password, "", 64 );
    softapConf.ssid_len=os_strlen( &apssid );
    //softapConf.channel= 6;
    softapConf.authmode= AUTH_OPEN;
    softapConf.max_connection= 2;
    softapConf.ssid_hidden= false;
    wifi_softap_set_config_current(&softapConf);
    wifi_softap_dhcps_start();
    os_printf("Setup network is enabled.\n\r");
    board_statusLed2(1);
  }
}
Ejemplo n.º 20
0
void RAMFUNC user_init(void)
{
#ifdef ESP32_GDBSTUB
	gdbstub_init();
#endif

	struct ip_info info;
	struct softap_config cfg;
	wifi_softap_get_config(&cfg);
	strcpy((char *)cfg.ssid, "$$com.sysprogs.esp32.http.ssid$$");
	cfg.ssid_len = strlen((char*)cfg.ssid);
	wifi_softap_set_config_current(&cfg);
	wifi_set_opmode(SOFTAP_MODE);
	
	wifi_softap_dhcps_stop();
	IP4_ADDR(&info.ip, 192, 168, $$com.sysprogs.esp32.http.subnet$$, 1);
	IP4_ADDR(&info.gw, 192, 168, $$com.sysprogs.esp32.http.subnet$$, 1);
	IP4_ADDR(&info.netmask, 255, 255, 255, 0);
	wifi_set_ip_info(SOFTAP_IF, &info);
	dhcps_lease_test();
	wifi_softap_dhcps_start();

	xTaskCreate(ServerTask, "Server", 256, NULL, 2, NULL);
}
Ejemplo n.º 21
0
/**
 * Set up an access point
 * @param ssid              Pointer to the SSID (max 63 char).
 * @param passphrase        (for WPA2 min 8 char, for open use NULL)
 * @param channel           WiFi channel number, 1 - 13.
 * @param ssid_hidden       Network cloaking (0 = broadcast SSID, 1 = hide SSID)
 * @param max_connection    Max simultaneous connected clients, 1 - 4.
 */
bool ESP8266WiFiAPClass::softAP(const char* ssid, const char* passphrase, int channel, int ssid_hidden, int max_connection) {

    if(!WiFi.enableAP(true)) {
        // enable AP failed
        DEBUG_WIFI("[AP] enableAP failed!\n");
        return false;
    }

    if(!ssid || strlen(ssid) == 0 || strlen(ssid) > 31) {
        // fail SSID too long or missing!
        DEBUG_WIFI("[AP] SSID too long or missing!\n");
        return false;
    }

    if(passphrase && strlen(passphrase) > 0 && (strlen(passphrase) > 63 || strlen(passphrase) < 8)) {
        // fail passphrase to long or short!
        DEBUG_WIFI("[AP] fail passphrase to long or short!\n");
        return false;
    }

    bool ret = true;

    struct softap_config conf;
    strcpy(reinterpret_cast<char*>(conf.ssid), ssid);
    conf.channel = channel;
    conf.ssid_len = strlen(ssid);
    conf.ssid_hidden = ssid_hidden;
    conf.max_connection = max_connection;
    conf.beacon_interval = 100;

    if(!passphrase || strlen(passphrase) == 0) {
        conf.authmode = AUTH_OPEN;
        *conf.password = 0;
    } else {
        conf.authmode = AUTH_WPA2_PSK;
        strcpy(reinterpret_cast<char*>(conf.password), passphrase);
    }

    struct softap_config conf_compare;
    if(WiFi._persistent){
        wifi_softap_get_config_default(&conf_compare);
    }
    else {
        wifi_softap_get_config(&conf_compare);
    }

    if(!softap_config_equal(conf, conf_compare)) {

        ETS_UART_INTR_DISABLE();
        if(WiFi._persistent) {
            ret = wifi_softap_set_config(&conf);
        } else {
            ret = wifi_softap_set_config_current(&conf);
        }
        ETS_UART_INTR_ENABLE();

        if(!ret) {
            DEBUG_WIFI("[AP] set_config failed!\n");
            return false;
        }

    } else {
        DEBUG_WIFI("[AP] softap config unchanged\n");
    }

    if(wifi_softap_dhcps_status() != DHCP_STARTED) {
        DEBUG_WIFI("[AP] DHCP not started, starting...\n");
        if(!wifi_softap_dhcps_start()) {
            DEBUG_WIFI("[AP] wifi_softap_dhcps_start failed!\n");
            ret = false;
        }
    }

    // check IP config
    struct ip_info ip;
    if(wifi_get_ip_info(SOFTAP_IF, &ip)) {
        if(ip.ip.addr == 0x00000000) {
            // Invalid config
            DEBUG_WIFI("[AP] IP config Invalid resetting...\n");
            //192.168.244.1 , 192.168.244.1 , 255.255.255.0
            ret = softAPConfig(0x01F4A8C0, 0x01F4A8C0, 0x00FFFFFF);
            if(!ret) {
                DEBUG_WIFI("[AP] softAPConfig failed!\n");
                ret = false;
            }
        }
    } else {
        DEBUG_WIFI("[AP] wifi_get_ip_info failed!\n");
        ret = false;
    }

    return ret;
}
Ejemplo n.º 22
0
// Lua: wifi.ap.dhcp.start()
static int wifi_ap_dhcp_start( lua_State* L )
{
  lua_pushboolean(L, wifi_softap_dhcps_start());
  return 1;
}
Ejemplo n.º 23
0
bool AccessPointClass::config(String ssid, String password, AUTH_MODE mode, bool hidden /* = false*/, int channel /* = 7*/, int beaconInterval /* = 200*/)
{
	softap_config config = {0};
	if (mode == AUTH_WEP) return false; // Not supported!

	if (mode == AUTH_OPEN)
		password = "";

	bool enabled = isEnabled();
	enable(true);
	wifi_softap_dhcps_stop();
	wifi_softap_get_config(&config);
	config.channel = channel;
	config.ssid_hidden = hidden;
	memset(config.ssid, 0, sizeof(config.ssid));
	memset(config.password, 0, sizeof(config.password));
	strcpy((char*)config.ssid, ssid.c_str());
	strcpy((char*)config.password, password.c_str());
	config.ssid_len = ssid.length();
	config.authmode = mode;
	config.max_connection = 4; // max 4
	config.beacon_interval = beaconInterval;

// RTOS TODO Check Systemready procedure including sotsp setup

	noInterrupts();
	if (!wifi_softap_set_config(&config))
	{
		interrupts();
		wifi_softap_dhcps_start();
		enable(enabled);
		debugf("Can't set AP configuration!");
		return false;
	}
	interrupts();
	debugf("AP configuration was updated");


/*
	if (System.isReady())
	{
		noInterrupts();
		if (!wifi_softap_set_config(&config))
		{
			interrupts();
			wifi_softap_dhcps_start();
			enable(enabled);
			debugf("Can't set AP configuration!");
			return false;
		}
		interrupts();
		debugf("AP configuration was updated");
	}
	else
	{
		debugf("Set AP configuration in background");
		if (runConfig != NULL)
			delete runConfig;
		runConfig = new softap_config();
		memcpy(runConfig, &config, sizeof(softap_config));
	}
	*/

	wifi_softap_dhcps_start();
	enable(enabled);

	return true;
}
Ejemplo n.º 24
0
void wifi_init() {
	wifi_set_opmode(NULL_MODE); //Next time start up in NULL mode
	wifi_set_opmode_current(NULL_MODE);

	//Initialize station config parameters
	struct station_config stconf;
	memset(&stconf, 0, sizeof(stconf));
	strncpy((char *)stconf.ssid, szWifiSsid, sizeof(stconf.ssid));
	strncpy((char *)stconf.password, szWifiPassword, sizeof(stconf.password));
	stconf.ssid[sizeof(stconf.ssid)-1]='\0';
	stconf.password[sizeof(stconf.password)-1]='\0';

	//Initialize AP config parameters
	struct softap_config apconf;
	memset(&apconf, 0, sizeof(apconf));
	// SSID
	strncpy((char *)apconf.ssid, szWifiSsid, sizeof(apconf.ssid));
	apconf.ssid[sizeof(apconf.ssid)-1]='\0';
	// Password & encryption
	strncpy((char *)apconf.password, szWifiPassword, sizeof(apconf.password));
	apconf.password[sizeof(apconf.password)-1]='\0';
	if (strlen(szWifiPassword) >= 8) {
		apconf.authmode = AUTH_WPA_WPA2_PSK;
	} else {
		// if password <8 characters, don't use password.
		apconf.authmode = AUTH_WEP;
		memset(apconf.password, 0, sizeof(apconf.password));
	}
	apconf.max_connection = 255;
	apconf.beacon_interval = 100;

	wifi_set_opmode_current(nWifiMode);
	wifi_softap_set_config_current(&apconf);
	wifi_station_set_config_current(&stconf);

	struct ip_info ipinfo;
	memset(&ipinfo, 0, sizeof(ipinfo));
	ipinfo.ip.addr = aIP;
	ipinfo.netmask.addr = aNetmask;
	ipinfo.gw.addr = aGateway;

	if (nWifiMode == STATION_MODE) {
		wifi_station_dhcpc_stop();
		wifi_station_set_hostname(szHostname);
		if (bUseDhcp) {
			wifi_station_dhcpc_start();
		} else {
			wifi_set_ip_info(STATION_IF, &ipinfo);
		}
	} else {
		// DHCP Server should be stopped to change IP information
		wifi_softap_dhcps_stop();
		wifi_set_ip_info(SOFTAP_IF, &ipinfo);

		uint32_t aFirstIp = (aIP & aNetmask) | 1;
		uint32_t aLastIp = (aIP & aNetmask) | (-1 & ~aNetmask);
		struct dhcps_lease leases;
		memset(&leases, 0, sizeof(leases));
		// Determine whether the range before or after our IP is bigger
		if (aIP - aFirstIp > aLastIp - aIP) {
			leases.start_ip.addr = aFirstIp;
			leases.end_ip.addr = aIP - 1;
		} else {
			leases.start_ip.addr = aIP + 1;
			leases.end_ip.addr = aLastIp;
		}
		wifi_softap_set_dhcps_lease(&leases);
		uint8_t offer_router = 0;
		wifi_softap_set_dhcps_offer_option(OFFER_ROUTER, &offer_router);
		wifi_softap_dhcps_start();
	}
}
Ejemplo n.º 25
0
/******************************************************************************
 * FunctionName : udp_test_port_recv
 * Returns      : none
*******************************************************************************/
LOCAL void ICACHE_FLASH_ATTR
udp_test_port_recv(void *arg, struct udp_pcb *upcb, struct pbuf *p, ip_addr_t *addr, u16_t port)
{
	uint8 usrdata[32];
    if (p == NULL)  return;
    if(p->tot_len < 2) {
        pbuf_free(p);
    	return;
    }
    uint16 length = mMIN(p->tot_len, sizeof(usrdata)-1);
#if DEBUGSOO > 0
    os_printf("udp " IPSTR ":%u [%d]\n", IP2STR(addr), port, p->tot_len);
#endif
    length = pbuf_copy_partial(p, usrdata, length, 0);
    pbuf_free(p);

    uint8 *pudpbuf = (uint8 *)os_zalloc(udpbufsize+1);
    if(pudpbuf == NULL) return;
    uint16 udpbuflen = 0;
    int x = 0;
    if(length>2) x = atoi((char *)&usrdata[2]);
    if ((length>1)&&(usrdata[1]=='?')) switch(usrdata[0])
    {
      case 'M':
          system_print_meminfo();
      case 'A':
        {
          udp_puts("\nChip_id: %08x Flash_id: %08x\nsys_time:%08x ADC:%d\n", system_get_chip_id(), spi_flash_get_id(), system_get_time(), system_adc_read());
          struct softap_config wiconfig;
          wifi_softap_get_config(&wiconfig);
          udp_puts("OPMode:%u SSID:'%s' Pwd:'%s' Ch:%u Authmode:%u MaxCon:%u Phu:%u ACon:%u\n", wifi_get_opmode(), wiconfig.ssid, wiconfig.password, wiconfig.channel, wiconfig.authmode, wiconfig.max_connection, wifi_get_phy_mode(), wifi_station_get_auto_connect());
          udp_puts("Connect status:%u\n", wifi_station_get_connect_status());
        };
      case 'I':
          udp_puts("heapsize: %d\n", system_get_free_heap_size() + udpbufsize);
          udpbuflen += print_udp_psc(pudpbuf+udpbuflen, udpbufsize-udpbuflen);
          udpbuflen += print_tcp_psc(pudpbuf+udpbuflen, udpbufsize-udpbuflen);
          udpbuflen += chow_tcp_connection_info(pudpbuf+udpbuflen, udpbufsize-udpbuflen);
          break;
      case 'H':
          udp_puts("heapsize: %d\n", system_get_free_heap_size() + udpbufsize);
          break;
      case 'U':
          udp_puts("heapsize: %d\n", system_get_free_heap_size() + udpbufsize);
          udpbuflen += print_udp_psc(pudpbuf+udpbuflen, udpbufsize-udpbuflen);
          break;
      case 'T':
          udp_puts("heapsize: %d\n", system_get_free_heap_size() + udpbufsize);
          udpbuflen += print_tcp_psc(pudpbuf+udpbuflen, udpbufsize-udpbuflen);
          break;
#ifdef USE_SRV_WEB_PORT
      case 'S':
          udp_puts("heapsize: %d\n", system_get_free_heap_size() + udpbufsize);
          udpbuflen += chow_tcp_connection_info(pudpbuf+udpbuflen, udpbufsize-udpbuflen);
          break;
#endif
      case 'R':
          system_restart();
          break;
      case 'P':
          udp_puts("system_set_os_print(%u)\n", x);
          system_set_os_print(x);
          break;
      case 'O':
          udp_puts("wifi_set_opmode(%u):%u\n", x, wifi_set_opmode(x));
          break;
      case 'B':
          udp_puts("wifi_station_set_auto_connect(%u):%u\n", x, wifi_station_set_auto_connect(x));
          break;
      case 'D':
          switch(x) {
          case 0:
              udp_puts("wifi_station_dhcpc_start:%u\n", wifi_station_dhcpc_start());
              break;
          case 1:
              udp_puts("wifi_station_dhcpc_stop:%u\n", wifi_station_dhcpc_stop());
              break;
          case 2:
              udp_puts("wifi_softap_dhcps_start:%u\n",wifi_softap_dhcps_start());
              break;
          case 3:
              udp_puts("wifi_softap_dhcps_stop:%u\n", wifi_softap_dhcps_stop());
              break;
          default:
              udp_puts("D(%u)?\n", x);
          }
          break;
          case 'F':
        	  if(flashchip != NULL) {
        		  udp_puts("FlashID: 0x%08x\nChip size: %d\nBlock size: %d\nSector size: %d\nPage size: %d\nStatus mask: 0x%08x\n", flashchip->deviceId, flashchip->chip_size, flashchip->block_size, flashchip->sector_size, flashchip->page_size, flashchip->status_mask );
        		  udp_puts("Real Flash size: %u\n", spi_flash_real_size());
        	  }
        	  else udp_puts("Unknown Flash type!\n");
              break;
          case 'E':
        	  udp_puts("wifi_set_sleep_type(%d):%u\n", x, wifi_set_sleep_type(x));
        	  break;
          case 'G':
        	  udp_puts("g_ic = %p\n", &g_ic);
        	  break;
      default:
          udp_puts("???\n");
    }
    if(udpbuflen) {
    	struct pbuf *z = pbuf_alloc(PBUF_TRANSPORT, udpbuflen, PBUF_RAM);
    	if(z != NULL) {
        	err_t err = pbuf_take(z, pudpbuf, udpbuflen);
        	os_free(pudpbuf);
        	if(err == ERR_OK) {
        	    udp_sendto(upcb, z, addr, port);
        	}
      	    pbuf_free(z);
        	return;
    	}
    }
    os_free(pudpbuf);
}
Ejemplo n.º 26
0
//Read configuration settings and apply them
bool WIFI_CONFIG::Setup()
{
  char pwd[MAX_PASSWORD_LENGH+1];
  char sbuf[MAX_SSID_LENGH+1];
  int wstatus;
   IPAddress currentIP;
  byte bflag=0;
  //set the sleep mode
  if (!CONFIG::read_byte(EP_SLEEP_MODE, &bflag ))return false;
  wifi_set_sleep_type ((sleep_type)bflag);
  //AP or client ?
  if (!CONFIG::read_byte(EP_WIFI_MODE, &bflag ) ||  !CONFIG::read_string(EP_SSID, sbuf , MAX_SSID_LENGH) ||!CONFIG::read_string(EP_PASSWORD, pwd , MAX_PASSWORD_LENGH)) return false;
    //disconnect if connected
  WiFi.disconnect();
  current_mode=bflag;
   //this is AP mode
  if (bflag==AP_MODE)
    {
		//setup Soft AP
      WiFi.mode(WIFI_AP);
      WiFi.softAP(sbuf, pwd);
      //setup PHY_MODE
	  if (!CONFIG::read_byte(EP_PHY_MODE, &bflag ))return false;
      wifi_set_phy_mode((phy_mode)bflag);
      //get current config
      struct softap_config apconfig;
       wifi_softap_get_config(&apconfig);
       //set the chanel
       if (!CONFIG::read_byte(EP_CHANNEL, &bflag ))return false;
       apconfig.channel=bflag;
       //set Authentification type
        if (!CONFIG::read_byte(EP_AUTH_TYPE, &bflag ))return false;
       apconfig.authmode=(AUTH_MODE)bflag;
       //set the visibility of SSID
        if (!CONFIG::read_byte(EP_SSID_VISIBLE, &bflag ))return false;
       apconfig.ssid_hidden=!bflag;
       //no need to add these settings to configuration just use default ones
       apconfig.max_connection=DEFAULT_MAX_CONNECTIONS;
       apconfig.beacon_interval=DEFAULT_BEACON_INTERVAL;
      //apply settings to current and to default
      if (!wifi_softap_set_config(&apconfig) || !wifi_softap_set_config_current(&apconfig))
		{
			Serial.println(F("M117 Error Wifi AP!"));
			delay(1000);
		}
      wifi_softap_dhcps_start();
    }
  else
    {//setup station mode
      WiFi.mode(WIFI_STA);
      WiFi.begin(sbuf, pwd);
       //setup PHY_MODE
	   if (!CONFIG::read_byte(EP_PHY_MODE, &bflag ))return false;
	   wifi_set_phy_mode((phy_mode)bflag);
      byte i=0;
      //try to connect
      while (WiFi.status() != WL_CONNECTED && i<40) {

          switch(WiFi.status())
          {
			  case 1:Serial.println(F("M117 No SSID found!"));
					break;
			  case 4:Serial.println(F("M117 No Connection!"));
					break;
			   default: Serial.println(F("M117 Connecting..."));
					break;
		  }
          delay(500);
          i++;
          }
    }
  //DHCP or Static IP ?
  if (!CONFIG::read_byte(EP_IP_MODE, &bflag )) return false;
  if (bflag==STATIC_IP_MODE)
    {
      //get the IP 
      if (!CONFIG::read_buffer(EP_IP_VALUE,(byte *)sbuf , IP_LENGH))return false;
      IPAddress local_ip (sbuf[0],sbuf[1],sbuf[2],sbuf[3]);
      //get the gateway 
      if (!CONFIG::read_buffer(EP_GATEWAY_VALUE,(byte *)sbuf , IP_LENGH))return false;
      IPAddress gateway (sbuf[0],sbuf[1],sbuf[2],sbuf[3]);
      //get the mask 
      if (!CONFIG::read_buffer(EP_MASK_VALUE,(byte *)sbuf , IP_LENGH))return false;
      IPAddress subnet (sbuf[0],sbuf[1],sbuf[2],sbuf[3]);
     //apply according active wifi mode
      if (wifi_get_opmode()==WIFI_AP || wifi_get_opmode()==WIFI_AP_STA)  WiFi.softAPConfig( local_ip,  gateway,  subnet);
      else WiFi.config( local_ip,  gateway,  subnet); 
    }
    #ifdef MDNS_FEATURE
    // Set up mDNS responder:
    if (wifi_get_opmode()==WIFI_STA )
		if (!mdns.begin(PROGMEM2CHAR(LOCAL_NAME))) {
		Serial.println(F("M117 Error with mDNS!"));
		delay(1000);
		}
    #endif
    //Get IP
    if (wifi_get_opmode()==WIFI_STA)currentIP=WiFi.localIP();
    else currentIP=WiFi.softAPIP();
    Serial.print(PROGMEM2CHAR(M117_));
    Serial.println(currentIP);
  return true;
}
Ejemplo n.º 27
0
/**
 * Configure access point
 * @param local_ip      access point IP
 * @param gateway       gateway IP
 * @param subnet        subnet mask
 */
bool ESP8266WiFiAPClass::softAPConfig(IPAddress local_ip, IPAddress gateway, IPAddress subnet) {
    DEBUG_WIFI("[APConfig] local_ip: %s gateway: %s subnet: %s\n", local_ip.toString().c_str(), gateway.toString().c_str(), subnet.toString().c_str());
    if(!WiFi.enableAP(true)) {
        // enable AP failed
        DEBUG_WIFI("[APConfig] enableAP failed!\n");
        return false;
    }
    bool ret = true;

    struct ip_info info;
    info.ip.addr = static_cast<uint32_t>(local_ip);
    info.gw.addr = static_cast<uint32_t>(gateway);
    info.netmask.addr = static_cast<uint32_t>(subnet);

    if(!wifi_softap_dhcps_stop()) {
        DEBUG_WIFI("[APConfig] wifi_softap_dhcps_stop failed!\n");
    }

    if(!wifi_set_ip_info(SOFTAP_IF, &info)) {
        DEBUG_WIFI("[APConfig] wifi_set_ip_info failed!\n");
        ret = false;
    }

    struct dhcps_lease dhcp_lease;
    IPAddress ip = local_ip;
    ip[3] += 99;
    dhcp_lease.start_ip.addr = static_cast<uint32_t>(ip);
    DEBUG_WIFI("[APConfig] DHCP IP start: %s\n", ip.toString().c_str());

    ip[3] += 100;
    dhcp_lease.end_ip.addr = static_cast<uint32_t>(ip);
    DEBUG_WIFI("[APConfig] DHCP IP end: %s\n", ip.toString().c_str());

    if(!wifi_softap_set_dhcps_lease(&dhcp_lease)) {
        DEBUG_WIFI("[APConfig] wifi_set_ip_info failed!\n");
        ret = false;
    }

    // set lease time to 720min --> 12h
    if(!wifi_softap_set_dhcps_lease_time(720)) {
        DEBUG_WIFI("[APConfig] wifi_softap_set_dhcps_lease_time failed!\n");
        ret = false;
    }

    uint8 mode = 1;
    if(!wifi_softap_set_dhcps_offer_option(OFFER_ROUTER, &mode)) {
        DEBUG_WIFI("[APConfig] wifi_softap_set_dhcps_offer_option failed!\n");
        ret = false;
    }

    if(!wifi_softap_dhcps_start()) {
        DEBUG_WIFI("[APConfig] wifi_softap_dhcps_start failed!\n");
        ret = false;
    }

    // check config
    if(wifi_get_ip_info(SOFTAP_IF, &info)) {
        if(info.ip.addr == 0x00000000) {
            DEBUG_WIFI("[APConfig] IP config Invalid?!\n");
            ret = false;
        } else if(local_ip != info.ip.addr) {
            ip = info.ip.addr;
            DEBUG_WIFI("[APConfig] IP config not set correct?! new IP: %s\n", ip.toString().c_str());
            ret = false;
        }
    } else {
        DEBUG_WIFI("[APConfig] wifi_get_ip_info failed!\n");
        ret = false;
    }

    return ret;
}
//---------------------------------------------------------------------------------
//-- Read MavLink message from GCS
bool
MavESP8266GCS::_readMessage()
{
    bool msgReceived = false;
    int udp_count = _udp.parsePacket();
    if(udp_count > 0)
    {
        mavlink_status_t gcs_status;
        while(udp_count--)
        {
            int result = _udp.read();
            if (result >= 0)
            {
                // Parsing
                msgReceived = mavlink_parse_char(MAVLINK_COMM_2, result, &_message, &gcs_status);
                if(msgReceived) {
                    //-- We no longer need to broadcast
                    _status.packets_received++;
                    if(_ip[3] == 255) {
                        _ip = _udp.remoteIP();
                        getWorld()->getLogger()->log("Response from GCS. Setting GCS IP to: %s\n", _ip.toString().c_str());
                    }
                    //-- First packets
                    if(!_heard_from) {
                        if(_message.msgid == MAVLINK_MSG_ID_HEARTBEAT) {
                            //-- We no longer need DHCP
                            if(getWorld()->getParameters()->getWifiMode() == WIFI_MODE_AP) {
                                wifi_softap_dhcps_stop();
                            }
                            _heard_from      = true;
                            _system_id       = _message.sysid;
                            _component_id    = _message.compid;
                            _seq_expected    = _message.seq + 1;
                            _last_heartbeat  = millis();
                        }
                    } else {
                        if(_message.msgid == MAVLINK_MSG_ID_HEARTBEAT)
                            _last_heartbeat = millis();
                        _checkLinkErrors(&_message);
                    }



                    //-- Check for message we might be interested
                    if(getWorld()->getComponent()->handleMessage(this, &_message)){
                        //-- Eat message (don't send it to FC)
                        memset(&_message, 0, sizeof(_message));
                        msgReceived = false;
                        continue;
                    }


                    //-- Got message, leave
                    break;
                }
            }
        }
    }
    if(!msgReceived) {
        if(_heard_from && (millis() - _last_heartbeat) > HEARTBEAT_TIMEOUT) {
            //-- Restart DHCP and start broadcasting again
            if(getWorld()->getParameters()->getWifiMode() == WIFI_MODE_AP) {
                wifi_softap_dhcps_start();
            }
            _heard_from = false;
            _ip[3] = 255;
            getWorld()->getLogger()->log("Heartbeat timeout from GCS\n");
        }
    }
    return msgReceived;
}
Ejemplo n.º 29
0
int sj_wifi_setup_ap(const struct sys_config_wifi_ap *cfg) {
  struct softap_config ap_cfg;
  struct ip_info info;
  struct dhcps_lease dhcps;

  size_t pass_len = strlen(cfg->pass);
  size_t ssid_len = strlen(cfg->ssid);

  if (ssid_len > sizeof(ap_cfg.ssid) || pass_len > sizeof(ap_cfg.password)) {
    LOG(LL_ERROR, ("AP SSID or PASS too long"));
    return 0;
  }

  if (pass_len != 0 && pass_len < 8) {
    /*
     * If we don't check pwd len here and it will be less than 8 chars
     * esp will setup _open_ wifi with name ESP_<mac address here>
     */
    LOG(LL_ERROR, ("AP password too short"));
    return 0;
  }

  /* If in STA-only mode, switch to AP. If in AP or AP+STA, keep it. */
  if (wifi_get_opmode() == STATION_MODE) {
    wifi_set_opmode_current(SOFTAP_MODE);
  }

  memset(&ap_cfg, 0, sizeof(ap_cfg));
  strncpy((char *) ap_cfg.ssid, cfg->ssid, sizeof(ap_cfg.ssid));
  strncpy((char *) ap_cfg.password, cfg->pass, sizeof(ap_cfg.password));
  ap_cfg.ssid_len = ssid_len;
  if (pass_len != 0) {
    ap_cfg.authmode = AUTH_WPA2_PSK;
  }
  ap_cfg.channel = cfg->channel;
  ap_cfg.ssid_hidden = (cfg->hidden != 0);
  ap_cfg.max_connection = cfg->max_connections;
  ap_cfg.beacon_interval = 100; /* ms */

  LOG(LL_DEBUG, ("Setting up %s on channel %d", ap_cfg.ssid, ap_cfg.channel));
  wifi_softap_set_config_current(&ap_cfg);

  LOG(LL_DEBUG, ("Restarting DHCP server"));
  wifi_softap_dhcps_stop();

  /*
   * We have to set ESP's IP address explicitly also, GW IP has to be the
   * same. Using ap_dhcp_start as IP address for ESP
   */
  info.netmask.addr = ipaddr_addr(cfg->netmask);
  info.ip.addr = ipaddr_addr(cfg->ip);
  info.gw.addr = ipaddr_addr(cfg->gw);
  wifi_set_ip_info(SOFTAP_IF, &info);

  dhcps.enable = 1;
  dhcps.start_ip.addr = ipaddr_addr(cfg->dhcp_start);
  dhcps.end_ip.addr = ipaddr_addr(cfg->dhcp_end);
  wifi_softap_set_dhcps_lease(&dhcps);
  /* Do not offer self as a router, we're not one. */
  {
    int off = 0;
    wifi_softap_set_dhcps_offer_option(OFFER_ROUTER, &off);
  }

  wifi_softap_dhcps_start();

  wifi_get_ip_info(SOFTAP_IF, &info);
  LOG(LL_INFO, ("WiFi AP: SSID %s, channel %d, IP " IPSTR "", ap_cfg.ssid,
                ap_cfg.channel, IP2STR(&info.ip)));

  return 1;
}