system-info.lua 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. return function (connection, req, args)
  2. dofile('httpserver-header.lc')(connection, 200, 'html')
  3. connection:send('<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><title>WiFi info</title></head><body>')
  4. connection:send('<p><b>Chip ID:</b> '..node.chipid()..'</p>')
  5. connection:send('<p><b>Flash ID:</b> '..node.flashid()..'</p>')
  6. connection:send('<p><b>Heap:</b> '..node.heap()..'</p>')
  7. connection:send('<p><b>Info:</b> '..node.info()..'</p>')
  8. connection:send('<p><b>Vdd:</b> '..adc.readvdd33()..' mV</p>')
  9. local address, size = file.fscfg()
  10. connection:send('<p><b>File System Address:</b> '..address..'</p>')
  11. connection:send('<p><b>File System Size:</b> '..size..' bytes</p>')
  12. local remaining, used, total = file.fsinfo()
  13. connection:send('<p><b>File System Usage:</b> '..used..' / '..total..' bytes</p>')
  14. connection:send('<p><b>Wifi MAC Address:</b> '..wifi.sta.getmac()..'</p>')
  15. connection:send('<p><b>WiFi Channel:</b> '..wifi.getchannel()..'</p>')
  16. local wifimode = wifi.getmode()
  17. if wifimode == wifi.STATION then
  18. connection:send('<p><b>WiFi Mode:</b> STATION</p>')
  19. elseif wifimode == wifi.SOFTAP then
  20. connection:send('<p><b>WiFi Mode:</b> SOFTAP</p>')
  21. elseif wifimode == wifi.STATIONAP then
  22. connection:send('<p><b>WiFi Mode:</b> STATIONAP</p>')
  23. elseif wifimode == wifi.NULLMODE then
  24. connection:send('<p><b>WiFi Mode:</b> NULLMODE</p>')
  25. end
  26. local wifiphymode = wifi.getphymode()
  27. if wifiphymode == wifi.PHYMODE_B then
  28. connection:send('<p><b>WiFi Physical Mode:</b> B</p>')
  29. elseif wifiphymode == wifi.PHYMODE_G then
  30. connection:send('<p><b>WiFi Physical Mode:</b> G</p>')
  31. elseif wifiphymode == wifi.PHYMODE_N then
  32. connection:send('<p><b>WiFi Physical Mode:</b> N</p>')
  33. end
  34. local status = wifi.sta.status()
  35. if status == 0 then
  36. connection:send('<p><b>wifi.sta.status:</b> STA_IDLE</p>')
  37. elseif status == 1 then
  38. connection:send('<p><b>wifi.sta.status:</b> STA_CONNECTING</p>')
  39. elseif status == 2 then
  40. connection:send('<p><b>wifi.sta.status:</b> STA_WRONGPWD</p>')
  41. elseif status == 3 then
  42. connection:send('<p><b>wifi.sta.status:</b> STA_APNOTFOUND</p>')
  43. elseif status == 4 then
  44. connection:send('<p><b>wifi.sta.status:</b> STA_FAIL</p>')
  45. elseif status == 5 then
  46. connection:send('<p><b>wifi.sta.status:</b> STA_GOTIP</p>')
  47. connection:send('<p><b>IP:</b> '..wifi.sta.getip())
  48. connection:send('<p><b>RSSI:</b> '..wifi.sta.getrssi()..' dB</p>')
  49. end
  50. connection:send('</body></html>')
  51. end