Left here for archival purposes.

User avatar
By dexo568
#40312 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")
tmr.delay(1000000)   -- wait 1,000,000 us = 1 second
sk=net.createConnection(net.TCP, false)
sk:on("receive", function(sck, c) print(c) end )
print("About to connect!")
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?

User avatar
By zsvo
#40648 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 :
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

conn:send() encapsulated with conn:on("connection",function(conn,blabla) conn:send(..) end)
User avatar
By xtal
#40699 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