Close

Weird NodeMCU DNS behavior

A project log for ESP8266 Phant.io and Plot.ly thing

Updates sensor data live to the cloud - with no external microcontroller.

liam-marshallLiam Marshall 05/01/2015 at 20:232 Comments

Adafruit has this code for making a HTTP request:

sk=net.createConnection(net.TCP, 0)
sk:on("receive", function(sck, c) print(c) end )
sk:connect(80,"www.adafruit.com")
sk:send("GET /testwifi/index.html HTTP/1.1\r\nHost: www.adafruit.com\r\nConnection: keep-alive\r\nAccept: */*\r\n\r\n")

The bizarre thing is that this works fine entered line-by-line in the terminal, but if I toss it in a lua file and run it with dofile, it doesn't work. But if I change "www.adafruit.com" in sk:connect to the IP for www.adafruit.com, it works in the file. I wonder if there's a race with the DNS where it can't do the DNS lookup fast enough, and then sk:send tries to send before it's completely connected. I'm going to report it to the NodeMCU devs, but for now I'm going to be using the Arduino port to the ESP8266.

Discussions

plucker wrote 05/09/2015 at 14:11 point

hi Liam,

You are right, if you use a domain name, the esp8266 will do a DNS request first.

In that case, you need to put your send request in the connect event callback:

sk:on("connect", function(sck, c) " do your send " end )

Please visit WWW.esp8266.com forum or the nodeMCU forum for more details.

I have made a prototype to post temperature and humidity, and others system data to thingspeak without any issue.

But, I have switched to native programing because of lack of memory when using lua...

Good luck,

Plucker

  Are you sure? yes | no

Liam Marshall wrote 05/09/2015 at 15:06 point

Thanks for the info! Arduino for ESP8266 is working great, way better in my opinion than either raw native programming or Lua.

  Are you sure? yes | no