Improve node info.lua (#95)

* Handle "nil", add more info

* Split up subnet mask, move unit to the end.
This commit is contained in:
Marcos 2017-07-01 22:19:38 -05:00 committed by GitHub
parent 7cdbe0ffd0
commit 2bdb2d458c
2 changed files with 20 additions and 8 deletions

View File

@ -28,7 +28,7 @@
<li><a href="args.lua">Arguments</a>: Parses arguments passed in the URL and prints them. (Lua)</li> <li><a href="args.lua">Arguments</a>: Parses arguments passed in the URL and prints them. (Lua)</li>
<li><a href="post.lua">Post</a>: A form that uses POST method. Displays different content based on HTTP method. (Lua)</li> <li><a href="post.lua">Post</a>: A form that uses POST method. Displays different content based on HTTP method. (Lua)</li>
<li><a href="garage_door.html">Garage door opener</a>: Control GPIO lines via the server. Or try this <a href="garage_door_control.html">simpler and nicer UI</a>. (Lua)</li> <li><a href="garage_door.html">Garage door opener</a>: Control GPIO lines via the server. Or try this <a href="garage_door_control.html">simpler and nicer UI</a>. (Lua)</li>
<li><a href="node_info.lua">NodeMCU info</a>: Shows some basic NodeMCU(Lua)</li> <li><a href="node_info.lua">NodeMCU info</a>: Display basic NodeMCU information. (Lua)</li>
<li><a href="file_list.lua">List all server files</a>: Displays a list of all the server files. (Lua)</li> <li><a href="file_list.lua">List all server files</a>: Displays a list of all the server files. (Lua)</li>
<li><a href="upload.html">Upload</a>: Update, remove, list files on the server. Beware security implications. By <a href="https://github.com/ATAMAH">ATAMAH</a>.</li> <li><a href="upload.html">Upload</a>: Update, remove, list files on the server. Beware security implications. By <a href="https://github.com/ATAMAH">ATAMAH</a>.</li>
<li><a href="foo.html">Foo</a>: A file that doesn't exist. Should error (404 error)</li> <li><a href="foo.html">Foo</a>: A file that doesn't exist. Should error (404 error)</li>

View File

@ -1,5 +1,15 @@
local function sendAttr(connection, attr, val) local function sendAttr(connection, attr, val, unit)
connection:send("<li><b>".. attr .. ":</b> " .. (val or "nil") .. "<br></li>\n") --Avoid error when Nil is in atrib=val pair.
if not attr or not val then
return
else
if unit then
unit = ' ' .. unit
else
unit = ''
end
connection:send("<li><b>".. attr .. ":</b> " .. val .. unit .. "<br></li>\n")
end
end end
return function (connection, req, args) return function (connection, req, args)
@ -9,12 +19,14 @@ return function (connection, req, args)
sendAttr(connection, "NodeMCU version" , majorVer.."."..minorVer.."."..devVer) sendAttr(connection, "NodeMCU version" , majorVer.."."..minorVer.."."..devVer)
sendAttr(connection, "chipid" , chipid) sendAttr(connection, "chipid" , chipid)
sendAttr(connection, "flashid" , flashid) sendAttr(connection, "flashid" , flashid)
sendAttr(connection, "flashsize" , flashsize) sendAttr(connection, "flashsize" , flashsize, 'Kb')
sendAttr(connection, "flashmode" , flashmode) sendAttr(connection, "flashmode" , flashmode)
sendAttr(connection, "flashspeed" , flashspeed) sendAttr(connection, "flashspeed" , flashspeed / 1000000 , 'MHz')
sendAttr(connection, "node.heap()" , node.heap()) sendAttr(connection, "heap free" , node.heap() , 'bytes')
sendAttr(connection, 'Memory in use (KB)' , collectgarbage("count")) sendAttr(connection, 'Memory in use' , collectgarbage("count") , 'KB')
sendAttr(connection, 'IP address' , wifi.sta.getip()) ip, subnetMask = wifi.sta.getip()
sendAttr(connection, 'Station IP address' , ip)
sendAttr(connection, 'Station subnet mask' , subnetMask)
sendAttr(connection, 'MAC address' , wifi.sta.getmac()) sendAttr(connection, 'MAC address' , wifi.sta.getmac())
connection:send('</ul></body></html>') connection:send('</ul></body></html>')
end end