#include <ESP8266WiFi.h>
const char* ssid = "REPLACE_WITH_YOUR_SSID"; // Replace with SSID
const char* password = "REPLACE_WITH_YOUR_PASSWORD"; // Replace with WiFi Password
IPAddress subnet(255, 255, 0, 0); // Subnet Mask
IPAddress gateway(192, 168, 1, 1); // Default Gateway
IPAddress local_IP(192, 168, 1, 184); // Static IP Address for ESP8266
void setup() {
Serial.begin(115200);
if (WiFi.config(local_IP, gateway, subnet)) {
Serial.println("Static IP Configured");
}
else {
Serial.println("Static IP Configuration Failed");
}
WiFi.begin(ssid, password);
Serial.print("Connecting...");
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi Connected! IP address:");
Serial.println(WiFi.localIP());
}
void loop(){
// YOUR CODE HERE //
}
Do you have a question ?
If you want the ESP8266 (or any other network connected device) to always have the same IP address then the best way is leave the device configured to get an IP address using DHCP and assign the desired IP address in the router. Most routers allow you to associate a specific IP address with a particular MAC address.
This has the advantage that the router is in control of IP address allocation, and and if you want multiple devices all with different IP addresses you can set them all in one place, in the router, rather than having to hard code different IP addresses in each device.
You can TRY this
I've tried with varying degrees of success
However as Perry says, by far the best way is to assign a fixed IP addresss in your router
@front-man, your topic has been moved to a more suitable location on the forum. Installation and Troubleshooting is not for problems with (nor for advise on) your project See About the Installation & Troubleshooting category.
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.