當使用Lua使用ESP8266 WiFi模塊嘗試從頁面獲取數據時,我得到一個無負載。對ESP8266中的服務器頁面發出GET請求後的空有效負載Lua
這裏是我的僞代碼:
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
我使用Lua的NodeMCU,並猜測將是相同的,即使我將使用Arduino框架。
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)
我能看到我的服務器,這意味着服務器請求的代碼是好的,但有效載荷/響應出來空白的所有請求。
輸出是完全空白...
請幫助。
查看我們在https://nodemcu.readthedocs.io/en/latest/en/modules/net/#example_5和https://nodemcu.readthedocs.io/en/文檔中提供的示例。最新/ EN /模塊/網絡/#example_6。 –