[ESP32] DHCP Hostname not working correctly
I can't put my finger on which version this stopped working or if it's just my code that's the issue.
def ConnectNetwork(NetworkName, Password):
import network
wlan = network.WLAN()
wlan.active(True)
wlan.config(dhcp_hostname="testname")
wlan.ifconfig(('192.168.0.210', '255.255.255.0', '192.168.0.1', '8.8.8.8'))
if not wlan.isconnected():
print('connecting to network...')
wlan.connect(NetworkName, Password)
print('Network Config:', wlan.ifconfig())
print('DHCP Hostname:', wlan.config('dhcp_hostname'))
ConnectNetwork("SSID", "Password")
When the device is connected to my router it is showing as UNKNOWN name. I am unable to ping the device using its name. Sometimes the name does show up on the router but disappears quickly after.
I have tested this in another home with a different board (same model) and a different router/network. Same things seem to happen.
This is part of some larger code, but pulled this snippet out for testing this issue. I have attempted to use different MicroPython versions below...
- esp32-bluetooth.bin (latest)
- esp32-20190504-v1.10-323-g906fb89fd.bin
- esp32-20180511-v1.9.4.bin
I have also tried removing this line but the same issue happens.
wlan.ifconfig(('192.168.0.210', '255.255.255.0', '192.168.0.1', '8.8.8.8'))
Thanks in advance!
Sparkfun ESP32 "Things" - DNS Not "Sticking"?
Hello all,
This is my first issue in this repo, please forgive if I leave out any information. I am also relatively new to microcontrollers/micropython/SoC boards, and the like; still learning the layout of the land..
I'm experiencing an odd issue on two of my ESP32 boards, and I am unsure what this is stemming from or if this is due to something I am doing improperly.
Problem: When I connect my board to my wireless network, it will connect properly and nic.ifconfig() will report proper parameters for some time, but then, while still remaining connected to the network, my DNS settings in nic.ifconfig() will change unprompted.
I am sure I do not have a rogue DHCP server on my network, nor anything that is advertising/hijacking DNS traffic.
My configuration:
Firmware: esp32-idf3-20200902-v1.13.bin
Boards: Sparkfun ESP32 Thing & SparkFun Thing Plus - ESP32 WROOM
Router: Mikrotik RB4011iGS+5HacQ2HnD (DHCP Server, configured to advertise Pi-Hole for DNS)
DNS: Pi-Hole v5.1.2
Reproduction:
- Flash board per instructions on Micropython website for ESP32 (Link)
- Connect to board for REPL via preferred serial client
- Python:
>>> import network
>>> nic = network.WLAN(network.STA_IF)
>>> nic.active(True)
>>> nic.config(dhcp_hostname="esp32_thing")
>>> nic.connect('myssid', 'secret')
>>> nic.ifconfig()
- I should receive output similar to this, and generally do right after connecting:
('192.168.89.235', '255.255.254.0', '192.168.88.1', '192.168.88.9')
- Some indeterminate amount of time later, if I execute
nic.ifconfig()again, I receive output that has the DNS server changed.
Example code,
def connect_and_print():
nic.disconnect()
time.sleep(2)
nic.connect("myssid", "secret")
while not nic.isconnected():
time.sleep_ms(250)
print("Connecting...")
print("Connected")
dns_expect = "192.168.88.9"
print(dns_expect)
print(nic.ifconfig())
while nic.ifconfig()[3] == dns_expect:
print("DNS OK")
time.sleep_ms(750)
print("DNS CHANGED!")
print(nic.ifconfig())
connect_and_print()
Earlier I used "indeterminate" because I have not seen any consistency with when or how this happens.
It could be within 10 seconds of connecting to the network, or 5 minutes.
I expect my DNS settings to remain "192.168.88.9" - but often they change to an IP something like "253.222.x.x"
Has anybody got an idea of what's happening here? While this is not hugely inconveniencing to me, it is concerning. My plans don't intend for these boards to be reaching out to the internet often, if at all, but also, I would prefer my local DNS server settings to be retained, in case they need to resolve a local address..
Edit: I was looking through recent issues, and this might be a similar/same/possibly-tied together issue with what I'm seeing, https://github.com/micropython/micropython/issues/6492