-->
Page 1 of 1

send() working in command-line but not in Lua files?

PostPosted: Tue Feb 02, 2016 6:01 pm
by dexo568
Hi All,
I am a beginner at nodeMCU and am trying to execute a simple GET request. Take a look at my code:

Code: Select allwifi.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.

Re: send() working in command-line but not in Lua files?

PostPosted: Sun Feb 07, 2016 4:36 pm
by zsvo
Hi,
I spent also a lot of time with same problem.
Running from CLI it worked , not as a program.
It was really strange, when I dofile("..lua) - file which consist from :
conn=net.createConnection;
conn:on("receive"..);
conn:connect(..))
it reports (with DEBUG functionality)

socket_connect is called.
....
net_socket_connected is called.

and later I dofile("..lua") which consist from
conn:send("GET...) and it works as expected

if all 4 function calls were in one lua file it didn't work.

it reports
socket_connect is called
only



BUT !
conn:send() encapsulated with conn:on("connection",function(conn,blabla) conn:send(..) end)
WORKS

Re: send() working in command-line but not in Lua files?

PostPosted: Mon Feb 08, 2016 9:14 am
by xtal
If i understand the FW changes that have occured---
You can use consecutive sends with FW 0.9.6 and prior
Later Firm Ware issue 1 send

wait for call back then issue next send
repeat until last send

wait for call back then issue close

FYI limit sends to >= 1459