node_info.lua 1.6 KB

123456789101112131415161718192021222324252627282930313233
  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
  13. end
  14. return function (connection, req, args)
  15. dofile("httpserver-header.lc")(connection, 200, 'html')
  16. 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>')
  17. majorVer, minorVer, devVer, chipid, flashid, flashsize, flashmode, flashspeed = node.info();
  18. sendAttr(connection, "NodeMCU version" , majorVer.."."..minorVer.."."..devVer)
  19. sendAttr(connection, "chipid" , chipid)
  20. sendAttr(connection, "flashid" , flashid)
  21. sendAttr(connection, "flashsize" , flashsize, 'Kb')
  22. sendAttr(connection, "flashmode" , flashmode)
  23. sendAttr(connection, "flashspeed" , flashspeed / 1000000 , 'MHz')
  24. sendAttr(connection, "heap free" , node.heap() , 'bytes')
  25. sendAttr(connection, 'Memory in use' , collectgarbage("count") , 'KB')
  26. ip, subnetMask = wifi.sta.getip()
  27. sendAttr(connection, 'Station IP address' , ip)
  28. sendAttr(connection, 'Station subnet mask' , subnetMask)
  29. sendAttr(connection, 'MAC address' , wifi.sta.getmac())
  30. sendAttr(connection, 'Auth user' , req.user)
  31. connection:send('</ul></body></html>')
  32. end