Updated examples to remove yields, pass req param. Integration woes.
This commit is contained in:
parent
d31b2d2c89
commit
5ccc69dc73
@ -1,4 +1,4 @@
|
|||||||
return function (connection, args)
|
return function (connection, req, args)
|
||||||
dofile("httpserver-header.lc")(connection, 200, 'html')
|
dofile("httpserver-header.lc")(connection, 200, 'html')
|
||||||
|
|
||||||
connection:send([===[
|
connection:send([===[
|
||||||
@ -6,21 +6,18 @@ return function (connection, args)
|
|||||||
<body>
|
<body>
|
||||||
<h1>Server File Listing</h1>
|
<h1>Server File Listing</h1>
|
||||||
]===])
|
]===])
|
||||||
coroutine.yield()
|
|
||||||
|
|
||||||
local remaining, used, total=file.fsinfo()
|
local remaining, used, total=file.fsinfo()
|
||||||
connection:send("<b>Total size: </b> " .. total .. " bytes<br/>\n" ..
|
connection:send("<b>Total size: </b> " .. total .. " bytes<br/>\n" ..
|
||||||
"<b>In Use: </b> " .. used .. " bytes<br/>\n" ..
|
"<b>In Use: </b> " .. used .. " bytes<br/>\n" ..
|
||||||
"<b>Free: </b> " .. remaining .. " bytes<br/>\n" ..
|
"<b>Free: </b> " .. remaining .. " bytes<br/>\n" ..
|
||||||
"<p>\n<b>Files:</b><br/>\n<ul>\n")
|
"<p>\n<b>Files:</b><br/>\n<ul>\n")
|
||||||
coroutine.yield()
|
|
||||||
|
|
||||||
for name, size in pairs(file.list()) do
|
for name, size in pairs(file.list()) do
|
||||||
local isHttpFile = string.match(name, "(http/)") ~= nil
|
local isHttpFile = string.match(name, "(http/)") ~= nil
|
||||||
if isHttpFile then
|
if isHttpFile then
|
||||||
local url = string.match(name, ".*/(.*)")
|
local url = string.match(name, ".*/(.*)")
|
||||||
connection:send(' <li><a href="' .. url .. '">' .. url .. "</a> (" .. size .. " bytes)</li>\n")
|
connection:send(' <li><a href="' .. url .. '">' .. url .. "</a> (" .. size .. " bytes)</li>\n")
|
||||||
coroutine.yield()
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
connection:send("</ul>\n</p>\n</body></html>")
|
connection:send("</ul>\n</p>\n</body></html>")
|
||||||
|
|||||||
@ -17,7 +17,6 @@ local function pushTheButton(connection, pin)
|
|||||||
|
|
||||||
-- Send back JSON response.
|
-- Send back JSON response.
|
||||||
connection:send("HTTP/1.0 200 OK\r\nContent-Type: application/json\r\nCache-Control: private, no-store\r\n\r\n")
|
connection:send("HTTP/1.0 200 OK\r\nContent-Type: application/json\r\nCache-Control: private, no-store\r\n\r\n")
|
||||||
coroutine.yield()
|
|
||||||
connection:send('{"error":0, "message":"OK"}')
|
connection:send('{"error":0, "message":"OK"}')
|
||||||
|
|
||||||
end
|
end
|
||||||
@ -28,7 +27,6 @@ return function (connection, req, args)
|
|||||||
elseif args.door == "2" then pushTheButton(connection, 2) -- GPIO2
|
elseif args.door == "2" then pushTheButton(connection, 2) -- GPIO2
|
||||||
else
|
else
|
||||||
connection:send("HTTP/1.0 400 OK\r\nContent-Type: application/json\r\nCache-Control: private, no-store\r\n\r\n")
|
connection:send("HTTP/1.0 400 OK\r\nContent-Type: application/json\r\nCache-Control: private, no-store\r\n\r\n")
|
||||||
coroutine.yield()
|
|
||||||
connection:send('{"error":-1, "message":"Bad door"}')
|
connection:send('{"error":-1, "message":"Bad door"}')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -1,12 +1,10 @@
|
|||||||
local function sendAttr(connection, attr, val)
|
local function sendAttr(connection, attr, val)
|
||||||
connection:send("<li><b>".. attr .. ":</b> " .. val .. "<br></li>\n")
|
connection:send("<li><b>".. attr .. ":</b> " .. val .. "<br></li>\n")
|
||||||
coroutine.yield()
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return function (connection, args)
|
return function (connection, req, args)
|
||||||
dofile("httpserver-header.lc")(connection, 200, 'html')
|
dofile("httpserver-header.lc")(connection, 200, 'html')
|
||||||
connection:send('<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><title>A Lua script sample</title></head><body><h1>Node info</h1><ul>')
|
connection:send('<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><title>A Lua script sample</title></head><body><h1>Node info</h1><ul>')
|
||||||
coroutine.yield()
|
|
||||||
majorVer, minorVer, devVer, chipid, flashid, flashsize, flashmode, flashspeed = node.info();
|
majorVer, minorVer, devVer, chipid, flashid, flashsize, flashmode, flashspeed = node.info();
|
||||||
sendAttr(connection, "NodeMCU version" , majorVer.."."..minorVer.."."..devVer)
|
sendAttr(connection, "NodeMCU version" , majorVer.."."..minorVer.."."..devVer)
|
||||||
sendAttr(connection, "chipid" , chipid)
|
sendAttr(connection, "chipid" , chipid)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user