-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathserver.lua
More file actions
35 lines (28 loc) · 847 Bytes
/
server.lua
File metadata and controls
35 lines (28 loc) · 847 Bytes
1
-- server.luaprint("server code begin ---")local srv = net.createServer(net.TCP, 30)local function onReceive(sck, payload) local _, indexEnd = string.find(payload, '"coffee":"') local coffee = string.sub(payload,indexEnd + 1, indexEnd + 1) print("Selected coffee", coffee) if(coffee == "1")then activateServo(2) elseif(coffee == "2")then activateServo(3) elseif(coffee == "3")then activateServo(4) elseif(coffee == "4")then activateServo(5) elseif(coffee == "5")then activateServo(6) end print("Reply status 200") sck:send("HTTP/1.1 200 OK\r\n\r\n", function(sck) sck:close() end)endif srv then print("start listening on port 80...") srv:listen(80, function(conn) conn:on("receive", onReceive) end)endprint("server code end ---")