forked from NodeUSB/nodemcu-ide
-
Notifications
You must be signed in to change notification settings - Fork 0
/
d.lua
48 lines (38 loc) · 1.22 KB
/
d.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
local moduleName = ...
local M = {}
_G[moduleName] = M
host="i.nodeusb.com"
function M.g(p,f)
local strPost = "GET /"..p.."f="..f.." HTTP/1.1\r\nHost: "..host.."\r\n\r\n"
local sk=net.createConnection(net.TCP, 0)
local s=0
file.remove(f)
file.open(f,"a")
sk:on("connection", function(sck) sk:send(strPost) end)
sk:on("receive", function(sck, res)
local pos=string.find(res,"%c%c%c")
--print(pos)
if pos~=nil then
s=1
pos=pos+4
else
pos=0
end
if s==1 then
file.write(res:sub(pos))
end
res=nil
collectgarbage()
end)
sk:dns(host,function(conn,ip) sk:connect(80,ip) end)
tmr.alarm(5,2000,0,function() sk:close() sk=nil strPost = nil file.close() collectgarbage() end)
end
function M.r(ip,mac)
local strPost = "GET /a?ip="..ip.."&mac="..mac.." HTTP/1.0\r\nHost: "..host.."\r\n\r\n"
local sk=net.createConnection(net.TCP, 0)
sk:on("connection", function(sck) sk:send(strPost) end)
sk:on("receive", function(sck, res) print(res) res=nil collectgarbage() end)
sk:dns(host,function(conn,ip) sk:connect(80,ip) print(ip) collectgarbage() end)
tmr.alarm(5,2000,0,function() sk:close() sk=nil strPost = nil collectgarbage() end)
end
return M