-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.lua
More file actions
66 lines (57 loc) · 1.36 KB
/
Copy pathserver.lua
File metadata and controls
66 lines (57 loc) · 1.36 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
local pw = require "password"
local sw = require "rc_switch"
wifi.setmode(wifi.STATION)
wifi.sta.config(pw.ssid, pw.pass)
local pin=3
local plen = 160 -- pulse length 160 us
local rep = 3 -- send each frame this number of times
sw.init(pin, plen, rep)
local html = [[
<html>
<head><title>remote outlet switch</title></head>
<body>
<div>
<h3>remote outlet switch</h3>
<form method="POST" name="switch">
<p>
<input type="submit" name="b1" value="on"/>
1
<input type="submit" name="b1" value="off"/>
<p>
<input type="submit" name="b2" value="on"/>
2
<input type="submit" name="b2" value="off"/>
<p>
<input type="submit" name="b3" value="on"/>
3
<input type="submit" name="b3" value="off"/>
<p>
<input type="submit" name="b4" value="on"/>
4
<input type="submit" name="b4" value="off"/>
<p>
<input type="submit" name="b5" value="on"/>
5
<input type="submit" name="b5" value="off"/>
</form>
</div>
</body>
</html>
]]
srv=net.createServer(net.TCP, 4)
if srv then
srv:listen(80,function(conn)
conn:on("receive",function(conn,data)
if debug then print(data) end
button, state = string.match(data, "b(%d)=(%a+)")
if button ~= nil then
button = tonumber(button)
sw.switch(button, state)
end
if string.find(data,"favicon.ico") == nil then
conn:send(html)
end
end)
conn:on("sent",function(conn) conn:close() end)
end)
end