node_info.lua 1.3 KB

1234567891011121314151617181920212223242526
  1. local function sendHeader(connection)
  2. connection:send("HTTP/1.0 200 OK\r\nContent-Type: text/html\r\nCache-Control: private, no-store\r\n\r\n")
  3. end
  4. local function sendAttr(connection, attr, val)
  5. connection:send("<li><b>".. attr .. ":</b> " .. val .. "<br></li>\n")
  6. end
  7. return function (connection, req, args)
  8. collectgarbage()
  9. sendHeader(connection)
  10. 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>')
  11. majorVer, minorVer, devVer, chipid, flashid, flashsize, flashmode, flashspeed = node.info();
  12. sendAttr(connection, "NodeMCU version" , majorVer.."."..minorVer.."."..devVer)
  13. sendAttr(connection, "chipid" , chipid)
  14. sendAttr(connection, "flashid" , flashid)
  15. sendAttr(connection, "flashsize" , flashsize)
  16. sendAttr(connection, "flashmode" , flashmode)
  17. sendAttr(connection, "flashspeed" , flashspeed)
  18. sendAttr(connection, "node.heap()" , node.heap())
  19. sendAttr(connection, 'Memory in use (KB)' , collectgarbage("count"))
  20. sendAttr(connection, 'IP address' , wifi.sta.getip())
  21. sendAttr(connection, 'MAC address' , wifi.sta.getmac())
  22. connection:send('</ul></body></html>')
  23. end