Assigning static IP in nodemcu

Thread Starter

eonshopact

Joined Sep 2, 2023
19
I want to assign static IP to the webserver. I am using my mobile phone's hotspot to connect internet. Can you please guide me a tutorial.
 

Thread Starter

eonshopact

Joined Sep 2, 2023
19

WBahn

Joined Mar 31, 2012
32,704
Is your demo always running on the same network? Or are you moving around and demoing it at different places using the local network?
 

Ya’akov

Joined Jan 27, 2019
10,226
Thanks for your response.

No. It is ok, if it is accessible within a range.

This is the tutorial i followed. https://srituhobby.com/nodemcu-esp8266-web-server-relay-control-tutorial-step-by-step-instructions/
It works fine. But, each time a new IP is generated. I want a static ip. So that I can access with the same IP whenever i want to show the demo.
You will need to pick an address within your tethering network. Unless they’ve secured it in such a way that it will not allow access unless your MAC received a DHCP assignment ( a common security feature) this code should work.

ESP32 Static IP in the Arduino Environment:
// Outside setup()

// IP address
IPAddress local_IP(192, 168, 1, 100);
// gateway address
IPAddress gateway(192, 168, 1, 1);
// netmask
IPAddress subnet(255, 255, 0, 0);
IPAddress primaryDNS(8, 8, 8, 8);   // optional
IPAddress secondaryDNS(8, 8, 4, 4); // optional

setup(
bool config(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dns1 = INADDR_ANY, IPAddress dns2 = INADDR_ANY);
    ...
)
There is a tutorial here.
 

Ya’akov

Joined Jan 27, 2019
10,226
Is your demo always running on the same network? Or are you moving around and demoing it at different places using the local network?
Since he is tethering to his cell phone, effectively he is. It will be whatever the tethering DHCP server hands out, and it will not change.
 

Thread Starter

eonshopact

Joined Sep 2, 2023
19
You will need to pick an address within your tethering network. Unless they’ve secured it in such a way that it will not allow access unless your MAC received a DHCP assignment ( a common security feature) this code should work.

ESP32 Static IP in the Arduino Environment:
// Outside setup()

// IP address
IPAddress local_IP(192, 168, 1, 100);
// gateway address
IPAddress gateway(192, 168, 1, 1);
// netmask
IPAddress subnet(255, 255, 0, 0);
IPAddress primaryDNS(8, 8, 8, 8);   // optional
IPAddress secondaryDNS(8, 8, 4, 4); // optional

setup(
bool config(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dns1 = INADDR_ANY, IPAddress dns2 = INADDR_ANY);
    ...
)
There is a tutorial here.
Thanks once again.

From where do i get the local_Ip, gateway, subnet, primaryDNS and secondaryDNS numbers? Are they are in my mobile phone or some random addresses?
 

Ya’akov

Joined Jan 27, 2019
10,226
Thanks once again.

From where do i get the local_Ip, gateway, subnet, primaryDNS and secondaryDNS numbers? Are they are in my mobile phone or some random addresses?
You should allow the device to get a DHCP address and then record those parameters. Use those.

You will need to pick an address within your tethering network. Unless they’ve secured it in such a way that it will not allow access unless your MAC received a DHCP assignment ( a common security feature) this code should work.
 
Top