ESP8266 Webserver Project

Moderator: Sprite_tm

User avatar
By vnarmy
#32416 Hi,
I try to modify the cgiWiFiConnect to set static IP.
Code: Select allint ICACHE_FLASH_ATTR cgiWiFiConnect(HttpdConnData *connData) {
   char essid[128];
   char passwd[128];
   static ETSTimer reassTimer;
   
   if (connData->conn==NULL) {
      //Connection aborted. Clean up.
      return HTTPD_CGI_DONE;
   }
   
   httpdFindArg(connData->post->buff, "essid", essid, sizeof(essid));
   httpdFindArg(connData->post->buff, "passwd", passwd, sizeof(passwd));



   //wifi_set_opmode(STATION_MODE); // Force Station mode

   wifi_station_dhcpc_stop();
   //wifi_softap_dhcps_stop();

   os_memset(&stconf, 0, sizeof(struct station_config));

   os_strncpy((char*)stconf.ssid, essid, 32);
   os_strncpy((char*)stconf.password, passwd, 64);
   os_printf("Try to connect to AP %s pw %s\n", essid, passwd);

   IP4_ADDR(&info.ip, 192, 168, 15, 10);
   IP4_ADDR(&info.gw, 192, 168, 15, 1);
   IP4_ADDR(&info.netmask, 255, 255, 255, 0);
   wifi_set_ip_info(STATION_IF, &info);

   //Schedule disconnect/connect
   os_timer_disarm(&reassTimer);
   os_timer_setfn(&reassTimer, reassTimerCb, NULL);
//Set to 0 if you want to disable the actual reconnecting bit
#ifdef DEMO_MODE
   httpdRedirect(connData, "/wifi");
#else
   os_timer_arm(&reassTimer, 500, 0);
   httpdRedirect(connData, "connecting.html");
#endif
   return HTTPD_CGI_DONE;
}

But the IP info seem not to be saved in flash so that when the esp8266 restart, dhcp is used to get the IP. If i try to disable the dhcp, the IP is wrong.
What am i missing here?
Any help would be greatly appreciate.
Thanks.