Renewed IP

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
Post Reply
oswald73
Posts: 1
Joined: Sun Feb 12, 2017 3:18 pm

Renewed IP

Post by oswald73 » Sun Feb 12, 2017 4:13 pm

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?

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: Renewed IP

Post by Roberthh » Tue Feb 14, 2017 9:16 am

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.

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())
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.

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Renewed IP

Post by pythoncoder » Tue Feb 14, 2017 9:42 am

@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.
Peter Hinch
Index to my micropython libraries.

Post Reply