[SOLVED] How to I create an access point DHCP server?


  • Pybytes Beta

    How do I start up a DHCP server on the device to serve clients when I have configured the device to act as an access point? I want one client and I want it to have the IP 10.10.10.9. No gateway or DNS. Short lease. (30 min or so.)

    from network import WLAN
    import machine
    
    AP_PASSWORD = '123456'
    AP_wlan = WLAN(mode=WLAN.AP)
    AP_wlan.init(ssid='WiPy', auth = (WLAN.WPA2, AP_PASSWORD), antenna = WLAN.INT_ANT)
    AP_wlan.ifconfig(id = 1, config = ('10.10.10.10', '255.255.255.252', '0.0.0.0', '0.0.0.0'))
    

  • Pybytes Beta

    I was doing the init wrong. I can't get it to give 10.10.10.9 (it gives 10.10.10.11) but I should be able to work with that somehow; will play with it more.

    Changes: Longer password, combine init into object instantiation.

    from network import WLAN
    import machine
    
    AP_PASSWORD = '123456abcdef'
    AP_wlan = WLAN(mode=WLAN.AP, ssid='WiPy', auth = (WLAN.WPA2, AP_PASSWORD), antenna = WLAN.INT_ANT)
    AP_wlan.ifconfig(id = 1, config = ('10.10.10.10', '255.255.255.252', '0.0.0.0', '0.0.0.0'))
    

Log in to reply
 

Pycom on Twitter