system-info.lua 4.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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>System 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 tm = rtctime.epoch2cal(rtctime.get())
  13. connection:send('<p><b>RTC Time:</b> '..string.format("%04d/%02d/%02d %02d:%02d:%02d", tm["year"], tm["mon"], tm["day"], tm["hour"], tm["min"], tm["sec"])..'</p>')
  14. local remaining, used, total = file.fsinfo()
  15. connection:send('<p><b>File System Usage:</b> '..used..' / '..total..' bytes</p>')
  16. connection:send('<p><b>Wifi STA MAC Address:</b> '..wifi.sta.getmac()..'</p>')
  17. connection:send('<p><b>Wifi AP MAC Address:</b> '..wifi.ap.getmac()..'</p>')
  18. connection:send('<p><b>WiFi Channel:</b> '..wifi.getchannel()..'</p>')
  19. local wifimode = wifi.getmode()
  20. if wifimode == wifi.STATION then
  21. connection:send('<p><b>WiFi Mode:</b> STATION</p>')
  22. elseif wifimode == wifi.SOFTAP then
  23. connection:send('<p><b>WiFi Mode:</b> SOFTAP</p>')
  24. elseif wifimode == wifi.STATIONAP then
  25. connection:send('<p><b>WiFi Mode:</b> STATIONAP</p>')
  26. elseif wifimode == wifi.NULLMODE then
  27. connection:send('<p><b>WiFi Mode:</b> NULLMODE</p>')
  28. end
  29. if (wifimode == wifi.STATIONAP) or (wifimode == wifi.SOFTAP) then
  30. local ip, netmask, gateway = wifi.ap.getip()
  31. connection:send('<p><b>AP IP:</b> '..ip..'</p>')
  32. connection:send('<p><b>AP netmask:</b> '..netmask..'</p>')
  33. connection:send('<p><b>AP gateway:</b> '..gateway..'</p>')
  34. connection:send('<p><b>AP client list:</b> ')
  35. local clients = wifi.ap.getclient()
  36. for mac, ip in pairs(clients) do
  37. connection:send('<p><b>'..mac..':</b> '..ip..'</p>')
  38. end
  39. connection:send('</p>')
  40. end
  41. local wifiphymode = wifi.getphymode()
  42. if wifiphymode == wifi.PHYMODE_B then
  43. connection:send('<p><b>WiFi Physical Mode:</b> B</p>')
  44. elseif wifiphymode == wifi.PHYMODE_G then
  45. connection:send('<p><b>WiFi Physical Mode:</b> G</p>')
  46. elseif wifiphymode == wifi.PHYMODE_N then
  47. connection:send('<p><b>WiFi Physical Mode:</b> N</p>')
  48. end
  49. local status = wifi.sta.status()
  50. if status == wifi.STA_IDLE then
  51. connection:send('<p><b>wifi.sta.status:</b> STA_IDLE</p>')
  52. elseif status == wifi.STA_CONNECTING then
  53. connection:send('<p><b>wifi.sta.status:</b> STA_CONNECTING</p>')
  54. elseif status == wifi.STA_WRONGPWD then
  55. connection:send('<p><b>wifi.sta.status:</b> STA_WRONGPWD</p>')
  56. elseif status == wifi.STA_APNOTFOUND then
  57. connection:send('<p><b>wifi.sta.status:</b> STA_APNOTFOUND</p>')
  58. elseif status == wifi.STA_FAIL then
  59. connection:send('<p><b>wifi.sta.status:</b> STA_FAIL</p>')
  60. elseif status == wifi.STA_GOTIP then
  61. connection:send('<p><b>wifi.sta.status:</b> STA_GOTIP</p>')
  62. connection:send('<p><b>Hostname:</b> '..wifi.sta.gethostname()..'</p>')
  63. local ip, netmask, gateway = wifi.sta.getip()
  64. connection:send('<p><b>STA IP:</b> '..ip..'</p>')
  65. connection:send('<p><b>STA netmask:</b> '..netmask..'</p>')
  66. connection:send('<p><b>STA gateway:</b> '..gateway..'</p>')
  67. local ssid, password, bssid_set, bssid = wifi.sta.getconfig()
  68. connection:send('<p><b>SSID:</b> '..ssid..'</p>')
  69. -- connection:send('<p><b>password:</b> '..password..'</p>') -- not sure if it should be shown.
  70. connection:send('<p><b>BSSID set:</b> '..bssid_set..'</p>')
  71. connection:send('<p><b>BSSID:</b> '..bssid..'</p>')
  72. connection:send('<p><b>STA Broadcast IP:</b> '..wifi.sta.getbroadcast()..'</p>')
  73. connection:send('<p><b>RSSI:</b> '..wifi.sta.getrssi()..' dB</p>')
  74. end
  75. connection:send('</body></html>')
  76. end