How to Assign a Static / Fixed IP Address | ESP8266 | ESP32 | Arduino
ฝัง
- เผยแพร่เมื่อ 10 พ.ย. 2024
- Mish Mash Labs present how to set a static of fixed IP address for your Espressif ESP8266, ESP32 or Arduino Board.
If you’re running a web server or client over WiFi or Ethernet with your Espressif ESP8266, ESP32 or Arduino Board and every time you restart your board it has a new IP address which is what happens when you use the default DHCP (Dynamic Host Configuration Protocol) you can follow this tutorial to change the settings to assign a static or fixed IP address.
Code used:
Before the setup loop:
// Set your Static IP Address Settings
IPAddress local_IP(192, 168, 1, 199);
IPAddress gateway(192, 168, 1, 1);
IPAddress subnet(255, 255, 0, 0);
IPAddress primaryDNS(8, 8, 8, 8); // this is optional
IPAddress secondaryDNS(8, 8, 4, 4); // this is optional
In the setup loop:
// Print feedback if the settings are not configured
if (!WiFi.config(local_IP, gateway, subnet, primaryDNS, secondaryDNS)) {
Serial.println("STA Failed to configure");
}
See our GitHub for complete sketch:
github.com/mis...
#ESP32 #ESP8266 #Arduino #Static #IP #tutorial #mishmash
Instagram: mishmashlabs
Twitter: mishmashlabs/
Music Credits:
Intro & Outro by audionautix.com
Thanks so much bro i really needed this for a school project ive been strugging to find a way so the ip is constant and wont change.
Once again thank you so much!
did this work?
Nice explainned. It would be interesting (if you are running a bult in webserver in the ESPXX) :1- Begin as AP (Access Point) with predefined Host. 2- Once your device get connected to the AP through built in webserver, have the ability to SCAN near by WIFI SSIDs (including your Wifi router) . 3- After selection and reboot you get logged and ESPXX became STA (station) .4- Since you are connected to it through webserver and your SOHO router asigned an IP (DHCP method) , will be outstanding to have the option to do that particular IP Fixed. It is a long process but once (in my opinion) you get it done would be easier for an "End-User" instead of using Arduino/VScode IDE.
That's a really nice idea. And it has so many applications for IoT prototypes, I guess you would need to use eeprom or some form of memory and maybe a button on a GPIO pin to use a reset to the hardcoded AP setting you mentioned, perhaps I'll give it a go in a few weeks.
@@MishMashLabs you are right ! it would need a "Factory default" (hard-Switch or Software) and should keep saved the parameters on eeprom ( ESP32XX flash memory) . If you decide to you go into that that would be interesting . Thanks for A Detailed Yet Simple to Understand Guide.
This is so useful and I'm so surprised... You're the only one I've seen share this information
My god, i just thank you a lot, this video helped me so much that i can-t find the right words to express my joy ☺
You're very welcome. This is the reason we make videos.
Im going to test this, and if this solves my problems i will PRAY for you❤
did this work ?
As always people that deserves credits dont get them.. I watched perhaps 100 videos trying to to do what you made me (understand) in 4 minutes... No words to thank you and sorry for my english.
Thanks for the kind words George! Please like the video and subscribe if you enjoy the style and content. This is a marathon project. Not a sprint!
i got some errors when i complied your gethub file, but was able to get the info to do what i needed. i guess there are a lot of different libraries out there. thanks!!!
This is wonderful stuff. You deserved a larger following.
Thanks for the support Paul!
thanks a lot. Worked fine for me except one error > Serial.printIn is not recognised so changed to > Serial.print
Hi there,
Both are correct, the difference is Serial.println starts printing on a new line from the next Serial.print or Serial.println function. While Serial.print will continue on the same line.
You may have had another error if there was an issue uploading, missing a semicolon perhaps?
Thanks for the feedback!
what if I use ESPAsyncWebServer instead of Webserver?
How to find
Local ip
Gateway
Subnet
Primary dns
Mac address
??
I am trying but cant compile: no matching function for call to 'WiFiClass::config(IPAddress&, IPAddress&, IPAddress&, IPAddress&, IPAddress&)'
Thanks for this video. I did as the video but the IP that serial sent is different from the IP that I see in my phone's hotspot.(IP is as previous). What's the problem?
Each device on a network will have a unique IP. The range should be the same, for example if your phone/hotspot IP is 192.168.0.1, your ESP can be 192.168.0.X where X can be any number between 2-254.
For me it does not work, i am trying to give my ESP8266 (That is functioning as a server for some domotica devices) a static IP, it is connected to my laptop hotspot. But for some reason it does not stay static..
Where i find gatewayIP my phone is a router
??
thank you for this video
it solved a big problem in my project
thank you once again
You are most welcome.
Just what I needed!! Thank youuuuu
did this work ?
@@meryamhad2916it worked for me, yes
hi i don't know if you can help me but i i have an ip adess that i gave to my esp32 when i create a webserver it works fine but when i change the esp32 adress to a static ip the webserver doesn't work i also tried to ping and i get no response coudl you help me?
Same problem here
Same problem 😢
how to we remove the wifi network hosted from esp?
My esp8266 not connect mobile hotspot, ssid and password ok, but not connect😢😢
hello brother,can you please try this method without router,instead of router coonect with mobile hotspot ..??? please do same with mobile subnet and gateway credntials ...
hello Sir good video how to read from spiffs a IPAddress local_IP(192, 168, 1, 199); i want to put it as a variable sored in the memory
tried network id and pass of my router didnt work
This is greatest stuff.
Ip address is not comming
Am using esp8266
Hi sir
When i search the ip address
it asks me for username and password.
What should i write?
The network id and password of your wifi router
@@MishMashLabs it didn't work
@@MishMashLabs do you have what's app number ?
Hello, thank you, these are good and practical tutorials
I compiled the code but it warned
(no matching function for call to 'WiFiClass :: config (IPAddress &, IPAddress &, IPAddress &, IPAddress &, IPAddress &)))
Please guide me to fix this error
Confirm you have the esp32 boards installed and have selected the correct board before upload.
@@MishMashLabs I use the 8266 range.
The library of this board is installed.
Set up a HTTP Web Server and Control program works without any problems, but this program displays the following warning.
no matching function for call to 'WiFiClass :: config (IPAddress &, IPAddress &, IPAddress &, IPAddress &, IPAddress &)'
@@MishMashLabs me too facing same issue
no matching function
Thanks