-
Notifications
You must be signed in to change notification settings - Fork 13.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ESP-8266 WiFi.config(ip, gateway, subnet); #2371
Comments
Syntax WiFi.config(ip); ip: the IP address of the device (array of 4 bytes) dns: the address for a DNS server. gateway: the IP address of the network gateway (array of 4 bytes). optional: defaults to the device IP address with the last octet set to 1 subnet: the subnet mask of the network (array of 4 bytes). optional: defaults to 255.255.255.0 https://www.arduino.cc/en/Reference/WiFiConfig Good luck |
@kiralikbeyin ESP does not follow same order as arduino, dns is at the end |
@dvukovic WiFi.config(ip, gateway, subnet, gateway); |
I changed the single line as suggested. IP Address: 192.168.0.50 |
@dvukovic assuming your syntax is correct, it sounds like 192.168.0.1 is not the gateway of the router you are trying to connect to - because you get an assigned IP of 10.0.0.14 from your router, it is likely that the router gateway is 10.0.0.1. The way I understand it, if you want to connect to the 192.168.0.1/24 subnet you need to set your router's IP address to 192.168.0.1, which is the same as the gateway IP for your ESP. Think of it like the gateway IP is the gate/entrance to a given subnet (mask of 255.255.255.0 = subnet ip range of 192.168.0.1-192.168.0.255). All of the device you want to talk to each other need to be on the same subnet (including your router, which controls access to that subnet). Is this your problem? |
Let me get back to some basics. I hope I have cleared up my confusion. |
Here are four ways do deal with ESP IP Addressing, in random order. There are probably more:
How to choose static IP: Also make sure to note the first three octects (numbers) of your router IP (probably 10.0.0.x, 192.168.0.x, or 192.168.1.x). Make sure your chosen static IP matches those first 3. Your router IP is the IP Address of the LAN in the settings of your router (also the address you type in to the browser to get to get there). This router IP is your gateway for your ESP. SO, in your case I would guess:
Notice how the first three numbers (octets) of the static IP and gateway are the same. The gateway is the IP address of the Router. The 4th octet of the static IP is outside of the DHCP range of the router. For now, just always use the above subnet. |
I should add that I do not have any access to the router. |
I use an android app called Fing which will show you the IP address of all the esp8266 devices on your network. |
Hi,
I have an arduino ethernet sever where if I include the gateway and subnet, it wouldn't POST data to my php script on a web server. I'm seeing the same problem on the WiFi esp8266. If any body knows how to solve 1 or 2 of the issue, let me know. |
Hi I am getting this, ets Jan 8 2013,rst cause:4, boot mode:(3,6), while using "Wifi.config()" to set static IP. If I am not using this...my code is working fine. But with this...I am getting this issue. Can anyone please help?? |
Upload your code. I'm working with fixed IP and I don't have problems. |
Thanks for helping out. Here is my code. Please have a look.
/*********
Rui Santos
Complete project details at http://randomnerdtutorials.com
*********/
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>
MDNSResponder mdns;
// Replace with your network credentials
const char* ssid = "Vertos";
const char* password ="aNonymous#1797";
ESP8266WebServer server(80);
String webPage = "";
int gpio0_pin = 0;
int gpio2_pin = 2;
IPAddress ip(192, 168, 1, 24); // where xx is the desired IP Address
IPAddress gateway(192, 168, 1, 1); // set gateway to match your network
IPAddress subnet(255, 255, 255, 0); // set subnet mask to match your network
void setup(void){
webPage += "<h1>ESP8266 Web Server</h1><p>Socket #1 <a
href=\"socket1On\"><button>ON</button></a> <a
href=\"socket1Off\"><button>OFF</button></a></p>";
webPage += "<p>Socket #2 <a
href=\"socket2On\"><button>ON</button></a> <a
href=\"socket2Off\"><button>OFF</button></a></p>";
// preparing GPIOs
pinMode(gpio0_pin, OUTPUT);
digitalWrite(gpio0_pin, LOW);
pinMode(gpio2_pin, OUTPUT);
digitalWrite(gpio2_pin, LOW);
delay(1000);
Serial.begin(115200);
Serial.println("Setting static ip to : ");
Serial.println(ip);
Serial.println("Connecting to Vertos...");
WiFi.config(ip, gateway, subnet);
//checking for SHIELD
if (WiFi.status() != WL_NO_SHIELD) {
Serial.println("WiFi shield is present");
while(true); // don't continue
}
WiFi.begin(ssid, password);
// Wait for connection
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.print("Connected to ");
Serial.println(ssid);
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
if (mdns.begin("esp8266", WiFi.localIP())) {
Serial.println("MDNS responder started");
}
server.on("/", [](){
server.send(200, "text/html", webPage);
});
server.on("/socket1On", [](){
server.send(200, "text/html", webPage);
digitalWrite(gpio0_pin, HIGH);
delay(1000);
});
server.on("/socket1Off", [](){
server.send(200, "text/html", webPage);
digitalWrite(gpio0_pin, LOW);
delay(1000);
});
server.on("/socket2On", [](){
server.send(200, "text/html", webPage);
digitalWrite(gpio2_pin, HIGH);
delay(1000);
});
server.on("/socket2Off", [](){
server.send(200, "text/html", webPage);
digitalWrite(gpio2_pin, LOW);
delay(1000);
});
server.begin();
Serial.println("HTTP server started");
}
void loop(void){
server.handleClient();
}
…On Tue, Jun 27, 2017 at 10:45 AM, ZaPpInG ***@***.***> wrote:
Upload your code. I'm working with fixed IP and I don't have problems.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#2371 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AcWbA1s-Qm_On5RiZNBx4FUojKg-EVMEks5sIU3BgaJpZM4JeZbT>
.
|
You must set "WiFi.mode(WIFI_STA);" after WiFi.config and before WiFi.begin Please close this. |
@Irmoreno007 int ledpin=2; void setup() { Serial.print( " use the url to connect: "); } int value = LOW; client.print("ledpin is now: "); } this is my code ....how can i connect my esp8266 to fixed client..no other client cant be able to access my esp8266 wifi. |
Add this code to fixed your ip address : IPAddress ip(192, 168, 11, 23); |
@amirusamah i have tried the above code with my laptop's ip ,gateway,subnet,dns. but it does not work. |
serial moniter returns me a url http://198.163.11.1.......can i control the clients connecting to this url |
your serial monitor returns you the url because in your code have this "IPAddress gateway(192, 168, 11, 1);" which i have give you before. you can change it to any url as long a "192.168........" . what i dont understanding is, what did you mean by control the client connecting to the url? what do you want to control? |
can i control the site from unknown client? i need that site to be connected to some specific clients.....i think to control the clients for the site , it is not the part of the code..is there any way to protect the site |
input and output is based from your esp8266. The information on the url is just to display the output from your esp8266. so anything should be control from esp8266 |
my code will make a url like http.. |
i want to make a password protected website...please help |
@suryanarayanan15 this is not the right place too ask for help, and this issue is closed. Please refer to a community forum for assistance. See our issue policy doc for more details. |
OK.sorry for the disturbances |
Thanks you!! It works! I forgot to write:
|
I had some old code that used to work fine with WiFi.config(staticIP, gateway, subnet) but WiFi.hostByName in my NTP routine stopped working with later (ie. 2.5.0) libraries. Apparently the older libraries didn't need the DNS server in WiFi.config but the newer libraries do. |
You are right, a few years ago static IP worked without specifying DNS - probably the same IP as gateway was used as DNS IP if DNS wasn't specified in I have some older code from 2016. and 2017. I had to rewrite for compiling it with present libraries because the devices couldn't connect to the server with the old code until I added DNS. DHCP has nothing to do with the static IP address, someone will probably confirm the IP used for DNS was the same as gateway in the old libraries. |
I am using a NodeMcu V3 board.
I am using IDE 1.6.8
I updated the ESP-8266 library to ver 2.2.0.
I loaded the HelloServer program and tested that.
It does work.
With the original file, I get an [IP Address: 10.0.0.14] and everything appears to work.
hello from esp8266!
When I add :
IPAddress ip(192, 168, 0, 50); // this 3 lines for a fix IP-address
IPAddress gateway(192, 168, 0, 1);
IPAddress subnet(255, 255, 255, 0);
WiFi.config(ip, gateway, subnet); // before or after Wifi.Begin(ssid, password);
The message states [IP Address: 192.168.0.50] but it does not connect:
This site can't be reached
192.168.0.50 took too long to respond.
Any ideas about this ?
Don
The text was updated successfully, but these errors were encountered: