forked from tjclement/esp-dimmer-software
-
Notifications
You must be signed in to change notification settings - Fork 1
/
pwmServer.lua
34 lines (28 loc) · 840 Bytes
/
pwmServer.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
local pwmDimmer = require("pwmDimmer")
local webServer = require("webServer")
local pwmService = require("pwmService")
local legacyRM04 = require("legacyRM04")
local pwmServer = {}
local pin = 7 -- NodeMCU pin 7, ESP GPIO 13
local function onRequest(connection, request)
-- We call the handlers manually instead of neatly in a for loop,
-- in order to save RAM. Creating tables is expensive.
if pwmService(connection, request) then
return
end
if legacyRM04(connection, request) then
return
end
if webServer(connection, request) then
return
end
connection:close()
end
function pwmServer.start()
local srv = net.createServer(net.TCP, 30)
srv:listen(80, function(conn)
conn:on("receive", onRequest)
end)
pwmDimmer.fadeTo(pin, 1023)
end
return pwmServer