send() working in command-line but not in Lua files?
Posted: Tue Feb 02, 2016 6:01 pm
Hi All,
I am a beginner at nodeMCU and am trying to execute a simple GET request. Take a look at my code:
(You can ignore the timers if you like, they were just part of some attempted debugging.)
This code, when run using dofile, does not print out the contents of google.com. However, when I copy/paste the last line after running the dofile, and run it directly in the console, correctly prints out the webpage. What could be going on to cause this line to run in the console but not in lua files?
Thanks.
I am a beginner at nodeMCU and am trying to execute a simple GET request. Take a look at my code:
Code: Select all
wifi.setmode(wifi.STATION)
wifi.sta.config("WIFI NAME", "WIFI PASSWORD")
wifi.sta.connect()
tmr.delay(1000000) -- wait 1,000,000 us = 1 second
print(wifi.sta.status())
print(wifi.sta.getip())
sk=net.createConnection(net.TCP, false)
sk:on("receive", function(sck, c) print(c) end )
tmr.delay(10000000)
print("About to connect!")
sk:connect(80,"www.google.com")
tmr.delay(10000000)
print("About to send!")
sk:send("GET / HTTP/1.1\r\nHost: www.google.com\r\nConnection: keep-alive\r\nAccept: */*\r\n\r\n")
(You can ignore the timers if you like, they were just part of some attempted debugging.)
This code, when run using dofile, does not print out the contents of google.com. However, when I copy/paste the last line after running the dofile, and run it directly in the console, correctly prints out the webpage. What could be going on to cause this line to run in the console but not in lua files?
Thanks.