I'm getting a nil payload while trying to get data from a page using ESP8266 WiFi module using Lua.
Here's my pseudo-code :
wifi.setmode(wifi.STATION)
wifi.sta.config("SSID","password")
wifi.sta.connect()
tmr.alarm(1,10000, 1, function()
if (wifi.sta.getip() == nil) then
print("IP unavaiable, Waiting...")
else
foo()
end
end)
function foo()
print("Inside foo function"..node.heap());
conn = nil
conn=net.createConnection(net.TCP,0) -- 30 seconds timeout time of server
conn:on("receive", function(conn, payload)
-- local buf = "";
startRead = false
gpioData = ""
print("payload : "..#payload);
for i = 1, #payload do
print(i);
end
end)
conn:connect(80,"server.co.in")
conn:on("connection", function(conn, payload)
print("Server Connected, sending event")
conn:send("GET /mypage?id=deadbeef HTTP/1.1 200 OK\r\nHost: server.co.in\r\nConnection: keep-alive\r\nAccept: */*\r\n\r\n") end)
conn:on("sent",function(conn)
print("Closing server connection")
conn:close()
end)
end
I'm using NodeMCU Lua, and guess will be same even if i use Arduino framework.
NodeMCU custom build by frightanic.com
branch: master
commit: 22e1adc4b06c931797539b986c85e229e5942a5f
SSL: false
modules: adc,bit,cjson,file,gpio,http,i2c,mdns,mqtt,net,node,ow,struct,tmr,uart,websocket,wifi
build built on: 2017-05-03 11:24
powered by Lua 5.1.4 on SDK 2.0.0(656edbf)
I'm able to see all requests on my server which means server request code is ok, but payload/response is coming out blank.
Output is complete blank...
Please help.