Hi all,
I assume that my ESP, when connected to a WLAN, will someday get a renewed IP. I don’t see any way to make the IP static or to connect through hostname, so how do I ensure, that users don’t need to reconnect through the AP?
Renewed IP
Re: Renewed IP
See this example from the docs at http://docs.micropython.org/en/latest/e ... networking to set the device into STA mode and connect to an AP.
You may also use WLAN.ifconfig() (see: http://docs.micropython.org/en/latest/e ... n.ifconfig) to set a static IP address. That all works fine.
Code: Select all
def do_connect():
import network
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
if not wlan.isconnected():
print('connecting to network...')
wlan.connect('essid', 'password')
while not wlan.isconnected():
pass
print('network config:', wlan.ifconfig())
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: Renewed IP
@oswald73 Your router will only allocate a new local IP address if the device is disconnected from the WLAN for some time. If this is likely to occur and you want a fixed IP there are two solutions. One is to set the ESP to use a fixed IP as suggested by @Roberthh. Alternatively configure the router's DHCP to allocate a fixed address to that device.
For many applications a fixed local IP address is unnecessary.
For many applications a fixed local IP address is unnecessary.
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.