Chat freely about anything...

User avatar
By buzzy
#64734 Sorry if this has been answered before, but I could not find anything when searching.

How do I configure the DHCP server settings on the esp8266?

When I turn on AP, it seems the DHCP server defaults to giving out IPs from the range 192.168.4.2 to 192.168.4.50 with netmask 255.255.255.0 and gateway/dns to 192.168.4.1

How do I change those settings? As an example, I set the esp8266 IP to 10.0.0.1 and want the DHCP server to assign IPs in the 10.0.1.1 - 255 range with netmask 255.0.0.0 to clients connecting to the esp.
User avatar
By piersfinlayson
#64746
buzzy wrote:Sorry if this has been answered before, but I could not find anything when searching.

How do I configure the DHCP server settings on the esp8266?

When I turn on AP, it seems the DHCP server defaults to giving out IPs from the range 192.168.4.2 to 192.168.4.50 with netmask 255.255.255.0 and gateway/dns to 192.168.4.1

How do I change those settings? As an example, I set the esp8266 IP to 10.0.0.1 and want the DHCP server to assign IPs in the 10.0.1.1 - 255 range with netmask 255.0.0.0 to clients connecting to the esp.


There's quite a decent example in the SDK guide on doing this, under "wifi_softap_set_dhcps_lease":

Code: Select allvoid dhcps_lease_test(void)
{
   struct dhcps_lease dhcp_lease;
   IP4_ADDR(&dhcp_lease.start_ip, 192, 168, 5, 100);
   IP4_ADDR(&dhcp_lease.end_ip, 192, 168, 5, 105);
   wifi_softap_set_dhcps_lease(&dhcp_lease);
}
void user_init(void)
{
   struct ip_info info;
   wifi_set_opmode(STATIONAP_MODE); //Set softAP + station mode
   wifi_softap_dhcps_stop();
   IP4_ADDR(&info.ip, 192, 168, 5, 1);
   IP4_ADDR(&info.gw, 192, 168, 5, 1);
   IP4_ADDR(&info.netmask, 255, 255, 255, 0);
  wifi_set_ip_info(SOFTAP_IF, &info);
   dhcps_lease_test();
   wifi_softap_dhcps_start();
}