I'm trying to connect NODEMCU to my home network and set static IP address, but the static IP didn't set properly this is the code:
#include <ESP8266WiFi.h>
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
WiFi.mode(WIFI_STA);
WiFi.config(IPAddress(192,168,1,129), IPAddress(192,168,1,1), IPAddress(225,225,225,0));
WiFi.begin("Bam", "123456789");
Serial.print("\nConnecting");
while(WiFi.status()!=3){
Serial.print(".");
delay(500);
}
Serial.println("Connected");
Serial.println(WiFi.localIP());
}
void loop() {
// put your main code here, to run repeatedly:
}
and this is the output on the Serial monitor:
13:28:46.715 -> Connecting.......Connected
13:28:50.937 -> 192.168.1.100
when I set the same static IP address to my phone it sets with no problem.
I tried to config the IP before connecting to WIFI:
WiFi.mode(WIFI_STA);
WiFi.config(ip, gateway, subnet);
WiFi.begin(ssid, pass);
I tried to add delay before printing the local IP:
WiFi.mode(WIFI_STA);
WiFi.config(ip, gateway, subnet);
delay(2000);
WiFi.begin(ssid, pass);
//loop to check if nodemcu is connected
Serial.println(WiFi.localIP);
I tried to disconnect and reconnect the WIFI I tried to disable the WIFI and start a new connection I tried to add the 4th and 5th argument which are DNS1 DNS2 none of these work for me.
I wanna see when printing the local IP the address I set to NODEMCU.