forked from NodeUSB/nodemcu-ide
-
Notifications
You must be signed in to change notification settings - Fork 0
/
i.lua
37 lines (31 loc) · 778 Bytes
/
i.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
srv=net.createServer(net.TCP)
srv:listen(80,function(conn)
local okHeader= "HTTP/1.0 200 OK\r\nAccess-Control-Allow-Origin:*\r\n\r\n"
local DataToGet = 0
local sending=false
function s_output(str)
if(conn~=nil) then
if(sending) then
conn:send(str)
else
sending=true
conn:send(okHeader..str)
end
end
end
node.output(s_output, 1)
conn:on("receive",function(conn,payload)
local pos=string.find(payload,"%c%-%-%-")
if pos==nil and fstart==nil then
print("ERR")
return
end
node.input(string.sub(payload,pos+4))
end)
conn:on("sent",function(conn)
sending=false
node.output(nil)
conn:close()
end)
end)
print("free:", node.heap())