As the title says... Chat on...

User avatar
By DrRob
#31748 Hello,

My little battery-powered project sleeps most of the time and wakes occasionally to takes some readings and post them to the 'net. I'm trying to reduce the amount of time it spends awake, so would like to switch to using a static IP, to save having to wait for a response from DHCP.

I see that I can use wifi.sta.setip(), and I gather from other posts that this must be called every time it wakes up.

My question is - how to set the address of the DNS server(s) (which would normally be obtained via DHCP)?

Thanks,
Rob.
User avatar
By DrRob
#31755
danbicks wrote:Use something like this: WiFi.config(Staticip, gateway, subnet);


Hi Dans,

Thanks, but that doesn't set the DNS server address...?

I've just done a little experiment, using Wireshark to monitor traffic, with steps equivalent to this:

node.dsleep(1000,4)

then after it wakes:
=wifi.sta.status() is 0

wifi.sta.setip({ip="192.168.1.10", netmask="255.255.255.0", gateway="192.168.1.1"})
=wifi.sta.status() is still 0

wifi.sta.connect()
The esp sends a IGMPv2 membership report for group 224.0.0.1 (what's that for?)
=wifi.sta.status() is now 5

conn=net.createConnection(net.TCP, false)
conn:on("receive", function(conn, pl) print(pl) end)
conn:connect(80,"www.nodemcu.com")
conn:send("GET / HTTP/1.1\r\nHost: www.nodemcu.com\r\n"
.."Connection: keep-alive\r\nAccept: */*\r\n\r\n")

The esp sends a DNS request to 208.67.222.222 to query www.nodemcu.com (twice in quick succession, actually).

That's not the usual DNS server for my network, so it looks like the esp has this DNS server address baked into it...? Maybe this is good enough for my requirements, but is there any way to override this address?

Rob.