Skip to content

Commit 2bdb2d4

Browse files
authored
Improve node info.lua (marcoskirsch#95)
* Handle "nil", add more info * Split up subnet mask, move unit to the end.
1 parent 7cdbe0f commit 2bdb2d4

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

http/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ <h3>Serve me some pages!</h3>
2828
<li><a href="args.lua">Arguments</a>: Parses arguments passed in the URL and prints them. (Lua)</li>
2929
<li><a href="post.lua">Post</a>: A form that uses POST method. Displays different content based on HTTP method. (Lua)</li>
3030
<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>
31-
<li><a href="node_info.lua">NodeMCU info</a>: Shows some basic NodeMCU(Lua)</li>
31+
<li><a href="node_info.lua">NodeMCU info</a>: Display basic NodeMCU information. (Lua)</li>
3232
<li><a href="file_list.lua">List all server files</a>: Displays a list of all the server files. (Lua)</li>
3333
<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>
3434
<li><a href="foo.html">Foo</a>: A file that doesn't exist. Should error (404 error)</li>

http/node_info.lua

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
1-
local function sendAttr(connection, attr, val)
2-
connection:send("<li><b>".. attr .. ":</b> " .. (val or "nil") .. "<br></li>\n")
1+
local function sendAttr(connection, attr, val, unit)
2+
--Avoid error when Nil is in atrib=val pair.
3+
if not attr or not val then
4+
return
5+
else
6+
if unit then
7+
unit = ' ' .. unit
8+
else
9+
unit = ''
10+
end
11+
connection:send("<li><b>".. attr .. ":</b> " .. val .. unit .. "<br></li>\n")
12+
end
313
end
414

515
return function (connection, req, args)
@@ -9,12 +19,14 @@ return function (connection, req, args)
919
sendAttr(connection, "NodeMCU version" , majorVer.."."..minorVer.."."..devVer)
1020
sendAttr(connection, "chipid" , chipid)
1121
sendAttr(connection, "flashid" , flashid)
12-
sendAttr(connection, "flashsize" , flashsize)
22+
sendAttr(connection, "flashsize" , flashsize, 'Kb')
1323
sendAttr(connection, "flashmode" , flashmode)
14-
sendAttr(connection, "flashspeed" , flashspeed)
15-
sendAttr(connection, "node.heap()" , node.heap())
16-
sendAttr(connection, 'Memory in use (KB)' , collectgarbage("count"))
17-
sendAttr(connection, 'IP address' , wifi.sta.getip())
24+
sendAttr(connection, "flashspeed" , flashspeed / 1000000 , 'MHz')
25+
sendAttr(connection, "heap free" , node.heap() , 'bytes')
26+
sendAttr(connection, 'Memory in use' , collectgarbage("count") , 'KB')
27+
ip, subnetMask = wifi.sta.getip()
28+
sendAttr(connection, 'Station IP address' , ip)
29+
sendAttr(connection, 'Station subnet mask' , subnetMask)
1830
sendAttr(connection, 'MAC address' , wifi.sta.getmac())
1931
connection:send('</ul></body></html>')
2032
end

0 commit comments

Comments
 (0)