index.html 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <!DOCTYPE html>
  2. <html>
  3. <header>
  4. <meta charset="utf-8" />
  5. <title>Http Server Get-Start</title>
  6. <!-- fetch api-->
  7. <!-- <script type="text/javascript" src="/petite-vue.js"></script> -->
  8. <script type="text/javascript">
  9. function led(key) {
  10. fetch("/led/" + key)
  11. }
  12. function wifi_get_aplist() {
  13. var resp = fetch("/scan/list").then(function (resp) {
  14. console.log(resp, resp.status)
  15. if (resp.status != 200) {
  16. return
  17. }
  18. resp.json().then(function (data) {
  19. console.log("data", data)
  20. var tmp = ""
  21. for (let index = 0; index < data.data.length; index++) {
  22. const apname = data.data[index];
  23. if (index == 0) {
  24. tmp += "<option vaule='" + index + "' selected>" + apname+"</option>\n"
  25. }
  26. else {
  27. tmp += "<option vaule='" + index + "'>" + apname+"</option>\n"
  28. }
  29. }
  30. document.getElementById("aplist").innerHTML = tmp
  31. })
  32. })
  33. }
  34. function wifi_scan() {
  35. fetch("/scan/go")
  36. setTimeout(wifi_get_aplist, 3000)
  37. }
  38. function wifi_connect() {
  39. var ssid = document.getElementById("ssid").value
  40. var passwd = document.getElementById("passwd").value
  41. console.log(ssid, passwd)
  42. fetch("/connect", {
  43. method : "POST",
  44. body : JSON.stringify({ssid:ssid, passwd:passwd})
  45. }).then(function(resp) {
  46. if (resp.status == 200) {
  47. alert("正在尝试连接")
  48. }
  49. else {
  50. alert("出了点问题")
  51. }
  52. })
  53. }
  54. function wifi_ipstat() {
  55. fetch("/connok").then(function(resp){
  56. if (resp.status != 200)
  57. return
  58. resp.json().then(function(data){
  59. console.log(data)
  60. if (data && data.ip != "0.0.0.0") {
  61. document.getElementById("ipstat").innerHTML = "已联网"
  62. }
  63. })
  64. })
  65. }
  66. function select_changed(event) {
  67. var apselect = document.getElementById("aplist")
  68. var ssid = document.getElementById("ssid")
  69. ssid.value = apselect.options[apselect.selectedIndex].text
  70. }
  71. setTimeout(wifi_get_aplist, 3000)
  72. // setInterval(wifi_ipstat, 3000)
  73. </script>
  74. </header>
  75. <body>
  76. <h2>点击按钮, led灯会亮起或熄灭</h2>
  77. <div>
  78. <div>
  79. <button onclick="led(1)">LED亮</button>
  80. </div>
  81. <div>
  82. <button onclick="led(0)">LED灭</button>
  83. </div>
  84. </div>
  85. <h2>AP WEB 配网</h2>
  86. <div v-scope="{aps:[]}">
  87. <div>
  88. <button onclick="wifi_scan()">扫描wifi</button>
  89. </div>
  90. <div>
  91. <h4>wifi列表</h4>
  92. <select id="aplist" onchange="select_changed()">
  93. <option vaule="">luatos1234</option>
  94. </select>
  95. <p></p>
  96. wifi名称: <input id="ssid">
  97. <p></p>
  98. 密码: <input id="passwd">
  99. <p></p>
  100. <button onclick="wifi_connect()">连接</button>
  101. </div>
  102. <div>
  103. <h4>联网状态:</h4><span id="ipstat">未联网</span>
  104. <p></p>
  105. <button onclick="wifi_ipstat()">检查状态</button>
  106. </div>
  107. </div>
  108. <div>
  109. <h4>Power by <a href="https://wiki.luatos.com">LuatOS</a></h4>
  110. </div>
  111. </body>
  112. </html>