Advertisement
GyroGearloose

ESP8266_assign_static_IP_addresses

Mar 11th, 2016
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.05 KB | None | 0 0
  1. /*
  2. It always is a hassle if the router assigns a different IP address through DHCP because you have to open the serial monitor to see what's going on. I was already about to install in my lamps a little display, but the I found the solution.
  3. So it is much easier if you can set a static IP:
  4. I wasn't able to put it so neatly into the code like you, so I just commented in and out;  but here is the recipe:
  5. */
  6. AccessPoint:
  7. ESP8266WebServer server(80);
  8. IPAddress apIP(192, 168, 5, 1);  // if you want to configure another IP address comment it out for WebServer
  9.  
  10. [in setup()]
  11.   WiFi.mode(WIFI_AP);
  12.   WiFi.softAPConfig(apIP, apIP, IPAddress(255, 255, 255, 0));          
  13.   WiFi.softAP(ssid, password);
  14.   server.begin();
  15.  
  16.  
  17. Webserver:
  18. WiFi.mode(WIFI_STA);
  19. // WiFi.config(IPAddress (your_new_IP), IPAddress (StandardGateway IP), IPAddress (255, 255, 255, 0));  // works only when I explicitely enter values
  20. WiFi.config(IPAddress (192,168,1,160), IPAddress (192,168,1,1), IPAddress (255, 255, 255, 0));  // works only when I explicitely enter values
  21. WiFiStart();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement