node_info.lua 1.2 KB

12345678910111213141516171819202122
  1. local function sendAttr(connection, attr, val)
  2. connection:send("<li><b>".. attr .. ":</b> " .. val .. "<br></li>\n")
  3. coroutine.yield()
  4. end
  5. return function (connection, args)
  6. dofile("httpserver-header.lc")(connection, 200, 'html')
  7. 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>')
  8. coroutine.yield()
  9. majorVer, minorVer, devVer, chipid, flashid, flashsize, flashmode, flashspeed = node.info();
  10. sendAttr(connection, "NodeMCU version" , majorVer.."."..minorVer.."."..devVer)
  11. sendAttr(connection, "chipid" , chipid)
  12. sendAttr(connection, "flashid" , flashid)
  13. sendAttr(connection, "flashsize" , flashsize)
  14. sendAttr(connection, "flashmode" , flashmode)
  15. sendAttr(connection, "flashspeed" , flashspeed)
  16. sendAttr(connection, "node.heap()" , node.heap())
  17. sendAttr(connection, 'Memory in use (KB)' , collectgarbage("count"))
  18. sendAttr(connection, 'IP address' , wifi.sta.getip())
  19. sendAttr(connection, 'MAC address' , wifi.sta.getmac())
  20. connection:send('</ul></body></html>')
  21. end