-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathm_srv.lua
34 lines (32 loc) · 1016 Bytes
/
m_srv.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
print("starting hc server on port 80")
hc_server=net.createServer(net.TCP,10)
m.node="started"
local_cmd=function(file,input)
pl=input
inp=pl
local _,_,module = string.find(pl, "(%w+)_.*")
print(module)
--if module and m[module]~="disabled" and file.exists(("m_srv_"..module..".lc") then
if module and m[module]=="started" then
dofile("m_srv_"..module..".lc")
elseif string.find(pl,'GET /') and m.http then
dofile("m_srv_http.lc")
else
hc_server_responce=("No module "..pl.." found\nOptions are:\nnode,dimmer,buzzer,speaker,button,petdoor,blind,car,dist,log,battery\nif enabled in init_var.lc")
end
end
hc_server:listen(80,function(con)
con:on("receive", function(con, conin)
local_cmd(conin,conin)
con:send(hc_server_responce.."\n")
end)
con:on("sent", function(con)
if http_end then
http_end=nil
-- con:close()
-- collectgarbage()
end
--hc_server_responce=nil
end)
end)
--node.compile("m_srv.lua")