index.html 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8"/>
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
  6. <meta name="apple-mobile-web-app-capable" content="yes" />
  7. <script src="/jquery.js"></script>
  8. <link rel="stylesheet" href="/style.css">
  9. <script src="/code.js"></script>
  10. <title>esp32-wifi-manager</title>
  11. </head>
  12. <script>
  13. var ws, sel, host, old, once = 0, jso, m;
  14. var to = 0, set_int = 0;
  15. function get_radio(name)
  16. {
  17. var s = document.getElementsByName(name), sel;
  18. for ( var i = 0; i < s.length; i++)
  19. if (s[i].checked) {
  20. sel = s[i].value;
  21. break;
  22. }
  23. return sel;
  24. }
  25. function get_radio_index(name)
  26. {
  27. var s = document.getElementsByName(name), i;
  28. for (i = 0; i < s.length; i++)
  29. if (s[i].checked)
  30. return i;
  31. return -1;
  32. }
  33. function do_reset()
  34. {
  35. var s = "{\"reset\":\"1\"}";
  36. try {
  37. ws.send(s);
  38. } catch(exception) {
  39. alert('Sorry, there was a problem' + exception);
  40. }
  41. ws.close();
  42. alert("Rebooting...");
  43. }
  44. function file_change()
  45. {
  46. document.getElementById('update').disabled = 0;
  47. }
  48. function do_upload(f)
  49. {
  50. var xhr = new XMLHttpRequest();
  51. document.getElementById('update').disabled = 1;
  52. //ws.close();
  53. document.getElementById("progr").class = "progr-ok";
  54. xhr.upload.addEventListener("progress", function(e) {
  55. document.getElementById("progr").value = parseInt(e.loaded / e.total * 100);
  56. if (e.loaded == e.total) {
  57. // document.getElementById("realpage").style.display = "none";
  58. // document.getElementById("waiting").style.display = "block";
  59. }
  60. }, false);
  61. xhr.onreadystatechange = function(e) {
  62. console.log("rs" + xhr.readyState + " status " + xhr.status);
  63. if (xhr.readyState == 4) {
  64. /* it completed, for good or for ill */
  65. // document.getElementById("realpage").style.display = "none";
  66. // document.getElementById("waiting").style.display = "block";
  67. document.getElementById("progr").class = "progr-ok";
  68. console.log("upload reached state 4: xhr status " + xhr.status);
  69. setTimeout(function() { window.location.href = location.origin + "/"; }, 9000 );
  70. }
  71. };
  72. /* kill the heart timer */
  73. clearInterval(set_int);
  74. xhr.open("POST", f.action, true);
  75. xhr.send(new FormData(f));
  76. return false;
  77. }
  78. function do_settings(f)
  79. {
  80. var xhr = new XMLHttpRequest();
  81. xhr.onreadystatechange = function(e) {
  82. console.log("do_settings" + xhr.readyState + " status " + xhr.status);
  83. if (xhr.readyState == 4) {
  84. document.getElementById("updsettings").style.opacity = "1.0";
  85. document.getElementById("updsettings").disabled = 0;
  86. }
  87. };
  88. xhr.open("POST", f.action, true);
  89. document.getElementById("updsettings").style.opacity = "0.3";
  90. document.getElementById("updsettings").disabled = 1;
  91. xhr.send(new FormData(f));
  92. return false;
  93. }
  94. function get_latest(n)
  95. {
  96. if (n == 0)
  97. ws.send("update-ota");
  98. else
  99. ws.send("update-factory");
  100. }
  101. function heart_timer() {
  102. var s;
  103. s = Math.round((95 * to) / (40 * 10)) / 100;
  104. if (s < 0) {
  105. clearInterval(set_int);
  106. set_int = 0;
  107. ws.close();
  108. document.getElementById("realpage").style.opacity = "0.3";
  109. }
  110. to--;
  111. document.getElementById("heart").style.opacity = s;
  112. }
  113. function heartbeat()
  114. {
  115. to = 40 * 10;
  116. if (!set_int) {
  117. set_int = setInterval(heart_timer, 100);
  118. }
  119. }
  120. function handleClick(cb) {
  121. if (cb.checked) {
  122. $("#autoexec-command").show(200);
  123. } else {
  124. $("#autoexec-command").hide(200);
  125. }
  126. }
  127. </script>
  128. <body>
  129. <div id="app">
  130. <div id="app-wrap">
  131. <div id="command_line">
  132. <header>
  133. <h1>Startup command</h1>
  134. </header>
  135. <h2>
  136. <div id="autoexec" class="toggle">
  137. <label>Run automatically at boot
  138. <input id="autoexec-cb" type="checkbox" checked="checked" onclick='handleClick(this);'/><span class="slider"></span>
  139. </label>
  140. </div>
  141. </h2>
  142. <div id="autoexec-command">
  143. <h2>Command to run</h2>
  144. <section id="command-list">
  145. <textarea id="autoexec1" maxlength="120">squeezelite -o I2S -b 500:2000 -d all=info -M esp32</textarea>
  146. </section>
  147. </div>
  148. <div class="buttons">
  149. <input id="update-command" type="button" value="Update" />
  150. </div>
  151. </div>
  152. <div id="otadiv">
  153. <header><h1>Firmware upgrade</h1></header>
  154. <form name="multipart" action="otaform" method="post" enctype="multipart/form-data" onsubmit="do_upload(this); return false;">
  155. <progress id="progr" value="0" max="100" >Upload Progress</progress>
  156. <input type="file" name="ota" id="ota" size="20" accept=".bin" onchange="file_change();" style="font-size: 12pt">
  157. <span id="file_info" style="font-size:12pt;"></span>
  158. <input type="submit" id="update" disabled="" value="upload">
  159. <input type="submit" id="factory" disabled="" value="factory">
  160. </form>
  161. </div>
  162. <div id="wifi">
  163. <header>
  164. <h1>Wi-Fi</h1>
  165. </header>
  166. <div id="wifi-status">
  167. <h2>Connected to:</h2>
  168. <section id="connected-to">
  169. <div class="ape"><div class="w0"><div class="pw"><span></span></div></div></div>
  170. </section>
  171. </div>
  172. <h2>Manual connect</h2>
  173. <section id="manual_add">
  174. <div class="ape">ADD (HIDDEN) SSID<div>
  175. </section>
  176. <h2>or choose a network...</h2>
  177. <section id="wifi-list">
  178. </section>
  179. <div id="pwrdby"><em>Powered by </em><a id="acredits" href="#"><strong>esp32-wifi-manager</strong></a>.</div>
  180. </div>
  181. <div id="connect_manual">
  182. <header>
  183. <h1>Enter Details</h1>
  184. </header>
  185. <h2>Manual Connection</h2>
  186. <section>
  187. <input id="manual_ssid" type="text" placeholder="SSID" value="">
  188. <input id="manual_pwd" type="password" placeholder="Password" value="">
  189. </section>
  190. <div class="buttons">
  191. <input id="manual_join" type="button" value="Join" data-connect="manual" />
  192. <input id="manual_cancel" type="button" value="Cancel"/>
  193. </div>
  194. </div>
  195. <div id="connect">
  196. <header>
  197. <h1>Enter Password</h1>
  198. </header>
  199. <h2>Password for <span id="ssid-pwd"></span></h2>
  200. <section>
  201. <input id="pwd" type="password" placeholder="Password" value="">
  202. </section>
  203. <div class="buttons">
  204. <input id="join" type="button" value="Join" />
  205. <input id="cancel" type="button" value="Cancel"/>
  206. </div>
  207. </div>
  208. <div id="connect-wait">
  209. <header>
  210. <h1>Please wait...</h1>
  211. </header>
  212. <h2>Connecting to <span id="ssid-wait"></span></h2>
  213. <section>
  214. <div id="loading">
  215. <div class="spinner"><div class="double-bounce1"></div><div class="double-bounce2"></div></div>
  216. <p class="tctr">You may lose wifi access while the esp32 recalibrates its radio. Please wait until your device automatically reconnects. This can take up to 30s.</p>
  217. </div>
  218. <div id="connect-success">
  219. <h3 class="gr">Success!</h3>
  220. </div>
  221. <div id="connect-fail">
  222. <h3 class="rd">Connection failed</h3>
  223. <p class="tctr">Please double-check wifi password if any and make sure the access point has good signal.</p>
  224. </div>
  225. </section>
  226. <div class="buttons">
  227. <input id="ok-connect" type="button" value="OK" class="ctr" />
  228. </div>
  229. </div>
  230. <div id="connect-details">
  231. <div id="connect-details-wrap">
  232. <header>
  233. <h1></h1>
  234. </header>
  235. <h2></h2>
  236. <section>
  237. <div class="buttons">
  238. <input id="disconnect" type="button" value="Disconnect" class="ctr"/>
  239. </div>
  240. </section>
  241. <h2>IP Address</h2>
  242. <section>
  243. <div class="ape brdb">IP Address:<div id="ip" class="fr"></div></div>
  244. <div class="ape brdb">Subnet Mask:<div id="netmask" class="fr"></div></div>
  245. <div class="ape">Default Gateway:<div id="gw" class="fr"></div></div>
  246. </section>
  247. <div class="buttons">
  248. <input id="ok-details" type="button" value="OK" class="ctr" />
  249. </div>
  250. </div>
  251. <div id="diag-disconnect" class="diag-box">
  252. <div class="diag-box-win">
  253. <p>Are you sure you would like to disconnect from this wifi?</p>
  254. <div class="buttons">
  255. <input id="no-disconnect" type="button" value="No" />
  256. <input id="yes-disconnect" type="button" value="Yes" />
  257. </div>
  258. </div>
  259. </div>
  260. </div>
  261. </div>
  262. </div>
  263. <div id="credits">
  264. <header>
  265. <h1>About this app...</h1>
  266. </header>
  267. <h2></h2>
  268. <section>
  269. <p><strong>esp32-wifi-manager</strong>, &copy; 2017-2019, Tony Pottier<br />Licender under the MIT License.</p>
  270. <p>
  271. This app would not be possible without the following libraries:
  272. </p>
  273. <ul>
  274. <li>SpinKit, &copy; 2015, Tobias Ahlin. Licensed under the MIT License.</li>
  275. <li>jQuery, The jQuery Foundation. Licensed under the MIT License.</li>
  276. <li>cJSON, &copy; 2009-2017, Dave Gamble and cJSON contributors. Licensed under the MIT License.</li>
  277. </ul>
  278. </section>
  279. <div class="buttons">
  280. <input id="ok-credits" type="button" value="OK" class="ctr" />
  281. </div>
  282. </div>
  283. </body>
  284. <html>