LOCAL void ICACHE_FLASH_ATTR set_ips()
{
struct ip_info info;
memset(&info, 0, sizeof(info));
info.ip.addr = ipaddr_addr("192.168.0.24");
info.netmask.addr = ipaddr_addr("255.255.255.0");
info.gw.addr = ipaddr_addr("192.168.0.1");
wifi_set_ip_info(STATION_IF, &info);
//system_station_got_ip_set(&info.ip, &info.netmask, &info.gw);
}
[...]
struct station_config stationConf;
memset(&stationConf, 0, sizeof(stationConf));
const char ssid[32] = "ssid";
const char password[32] = "pswd";
wifi_set_opmode( STATION_MODE );
set_ips();
wifi_station_dhcpc_stop();
wifi_station_set_auto_connect(FALSE);
os_memcpy(&stationConf.ssid, ssid, 32);
os_memcpy(&stationConf.password, password, 32);
wifi_station_set_config(&stationConf);
set_ips();
wifi_station_connect();
os_printf("Wifi connected\n");
set_ips(); // redo just in case, sometimes it does not work without it
The problem is that if I put this code in user_init, the IP does not get set. I need to start a timer and then call this couple of seconds after booting. But if I init http server from the timer later on, it does not work. I use the following code for that:
LOCAL void ICACHE_FLASH_ATTR init_httpd()
{
captdnsInit();
// 0x40200000 is the base address for spi flash memory mapping, ESPFS_POS is the position
// where image is written in flash that is defined in Makefile.
#ifdef ESPFS_POS
espFsInit((void*)(0x40200000 + ESPFS_POS));
#else
espFsInit((void*)(webpages_espfs_start));
#endif
httpdInit(builtInUrls, 80);
#ifdef SHOW_HEAP_USE
os_timer_disarm(&prHeapTimer);
os_timer_setfn(&prHeapTimer, prHeapTimerCb, NULL);
os_timer_arm(&prHeapTimer, 3000, 1);
#endif
os_timer_disarm(&websockTimer);
os_timer_setfn(&websockTimer, websockTimerCb, NULL);
os_timer_arm(&websockTimer, 1000, 1);
os_printf("\nReady\n");
}
It also does not work if I start http server first and then I set IPs for the WiFi connection. If anyone has a working code that sets the IP to static value and start HTTP server, please share.
Thanks.