2

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.

3
  • 2
    You connect to the WiFi first, then try to change the IP, of course it will not work. Config first, then connect. Commented Apr 18, 2023 at 12:33
  • @hcheung I forgot to mention all solutions I've tried, I tried this but didn't work Commented Apr 18, 2023 at 13:15
  • 3
    Shouldn't the network mask be 255.255.255.0 rather than 225.225.225.0 ? Also does anything else on your network have an IP of 192.168.1.129 ? Commented Apr 18, 2023 at 16:17

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.