user68625: I'm new to Arduino programming. I want to make my ESP8266 get a static IP address based on the gateway's IP address.
I mean if the gateway is at 192.168.0.1 then the ESP8266 should get 192.168.0.15 as a static IP address. And if the gateway is at 192.168.1.1 then it should get 192.168.1.15 as an IP address.

user61722: You can either set the router to allocate a static IP address based on your ESP8266's MAC address, or go the DHCP-way first, read the gateway IP address you got, and then do a WiFi.config(), something roughly like this (untested):
WiFi.begin(ssid, password);
IPAddress ip = WiFi.gatewayIP();
IP[3] = 15;
IPAddress dns(8, 8, 8, 8);
WiFi.config(ip, WiFi.gatewayIP(), dns, WiFi.subnetMask());

It is a bit of a trick, and not pretty, and you don't get to set the DNS as provided by the DHCP, because there is no getDNS(), for some silly reason, hence the use of Google's DNS server.
Note that when doing this, you run the risk of setting the ESP8266's IP address to an address already taken by another device on the same router.

68625: <p>I'm new to Arduino programming. I want to make my ESP8266 get a static IP address based on the gateway's IP address.</p>
<p>I mean if the gateway is at 192.168.0.1 then the ESP8266 should get 192.168.0.15 as a static IP address. And if the gateway is at 192.168.1.1 then it should get 192.168.1.15 as an IP address.</p>
 61722: <p>You can either set the router to allocate a static IP address based on your ESP8266's MAC address, or go the DHCP-way first, read the gateway IP address you got, and then do a <code>WiFi.config()</code>, something roughly like this (untested):</p>
<pre class="lang-cpp prettyprint-override"><code>WiFi.begin(ssid, password);
IPAddress ip = WiFi.gatewayIP();
IP[3] = 15;
IPAddress dns(8, 8, 8, 8);
WiFi.config(ip, WiFi.gatewayIP(), dns, WiFi.subnetMask());
</code></pre>
<p>It is a bit of a trick, and not pretty, and you don't get to set the DNS as provided by the DHCP, because there is no <code>getDNS()</code>, for some silly reason, hence the use of Google's DNS server.</p>
<p>Note that when doing this, you run the risk of setting the ESP8266's IP address to an address already taken by another device on the same router.</p>
