2
0

index.html 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  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. <div id="audioout" class="toggle-buttons">
  144. <h2>Audio output</h2>
  145. <input type="radio" id="i2s" name="audio" />
  146. <label for="i2s">I2S</label>
  147. <input type="radio" id="bt" name="audio" />
  148. <label for="bt">Bluetooth</label>
  149. </div>
  150. <div id="btsinkdiv">
  151. <input id="btsink" type="text" value="BT sink name" />
  152. </div>
  153. <div>
  154. <h2>Player name</h2>
  155. <input id="player" type="text" value="squeezelite" />
  156. </div>
  157. <div>
  158. <h2>Optional setting (e.g. for LMS IP address)</h2>
  159. <input id="optional" type="text" value="" placeholder="-s 192.168.0.1" />
  160. </div>
  161. <div class="buttons">
  162. <input id="generate-command" type="button" value="Generate" />
  163. </div>
  164. <h2>Command to run</h2>
  165. <section id="command-list">
  166. <textarea id="autoexec1" maxlength="120">squeezelite -o I2S -b 500:2000 -d all=info -M esp32</textarea>
  167. </section>
  168. </div>
  169. <div class="buttons">
  170. <input id="update-command" type="button" value="Update" />
  171. </div>
  172. </div>
  173. <div id="otadiv">
  174. <header><h1>Firmware upgrade</h1></header>
  175. <form name="multipart" action="otaform" method="post" enctype="multipart/form-data" onsubmit="do_upload(this); return false;">
  176. <progress id="progr" value="0" max="100" >Upload Progress</progress>
  177. <input type="file" name="ota" id="ota" size="20" accept=".bin" onchange="file_change();" style="font-size: 12pt">
  178. <span id="file_info" style="font-size:12pt;"></span>
  179. <input type="submit" id="update" disabled="" value="upload">
  180. <input type="submit" id="factory" disabled="" value="factory">
  181. </form>
  182. </div>
  183. <div id="wifi">
  184. <header>
  185. <h1>Wi-Fi</h1>
  186. </header>
  187. <div id="wifi-status">
  188. <h2>Connected to:</h2>
  189. <section id="connected-to">
  190. <div class="ape"><div class="w0"><div class="pw"><span></span></div></div></div>
  191. </section>
  192. </div>
  193. <h2>Manual connect</h2>
  194. <section id="manual_add">
  195. <div class="ape">ADD (HIDDEN) SSID<div>
  196. </section>
  197. <h2>or choose a network...</h2>
  198. <section id="wifi-list">
  199. </section>
  200. <div id="pwrdby"><em>Powered by </em><a id="acredits" href="#"><strong>esp32-wifi-manager</strong></a>.</div>
  201. </div>
  202. <div id="connect_manual">
  203. <header>
  204. <h1>Enter Details</h1>
  205. </header>
  206. <h2>Manual Connection</h2>
  207. <section>
  208. <input id="manual_ssid" type="text" placeholder="SSID" value="">
  209. <input id="manual_pwd" type="password" placeholder="Password" value="">
  210. </section>
  211. <div class="buttons">
  212. <input id="manual_join" type="button" value="Join" data-connect="manual" />
  213. <input id="manual_cancel" type="button" value="Cancel"/>
  214. </div>
  215. </div>
  216. <div id="connect">
  217. <header>
  218. <h1>Enter Password</h1>
  219. </header>
  220. <h2>Password for <span id="ssid-pwd"></span></h2>
  221. <section>
  222. <input id="pwd" type="password" placeholder="Password" value="">
  223. </section>
  224. <div class="buttons">
  225. <input id="join" type="button" value="Join" />
  226. <input id="cancel" type="button" value="Cancel"/>
  227. </div>
  228. </div>
  229. <div id="connect-wait">
  230. <header>
  231. <h1>Please wait...</h1>
  232. </header>
  233. <h2>Connecting to <span id="ssid-wait"></span></h2>
  234. <section>
  235. <div id="loading">
  236. <div class="spinner"><div class="double-bounce1"></div><div class="double-bounce2"></div></div>
  237. <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>
  238. </div>
  239. <div id="connect-success">
  240. <h3 class="gr">Success!</h3>
  241. </div>
  242. <div id="connect-fail">
  243. <h3 class="rd">Connection failed</h3>
  244. <p class="tctr">Please double-check wifi password if any and make sure the access point has good signal.</p>
  245. </div>
  246. </section>
  247. <div class="buttons">
  248. <input id="ok-connect" type="button" value="OK" class="ctr" />
  249. </div>
  250. </div>
  251. <div id="connect-details">
  252. <div id="connect-details-wrap">
  253. <header>
  254. <h1></h1>
  255. </header>
  256. <h2></h2>
  257. <section>
  258. <div class="buttons">
  259. <input id="disconnect" type="button" value="Disconnect" class="ctr"/>
  260. </div>
  261. </section>
  262. <h2>IP Address</h2>
  263. <section>
  264. <div class="ape brdb">IP Address:<div id="ip" class="fr"></div></div>
  265. <div class="ape brdb">Subnet Mask:<div id="netmask" class="fr"></div></div>
  266. <div class="ape">Default Gateway:<div id="gw" class="fr"></div></div>
  267. </section>
  268. <div class="buttons">
  269. <input id="ok-details" type="button" value="OK" class="ctr" />
  270. </div>
  271. </div>
  272. <div id="diag-disconnect" class="diag-box">
  273. <div class="diag-box-win">
  274. <p>Are you sure you would like to disconnect from this wifi?</p>
  275. <div class="buttons">
  276. <input id="no-disconnect" type="button" value="No" />
  277. <input id="yes-disconnect" type="button" value="Yes" />
  278. </div>
  279. </div>
  280. </div>
  281. </div>
  282. </div>
  283. </div>
  284. <div id="credits">
  285. <header>
  286. <h1>About this app...</h1>
  287. </header>
  288. <h2></h2>
  289. <section>
  290. <p><strong>esp32-wifi-manager</strong>, &copy; 2017-2019, Tony Pottier<br />Licender under the MIT License.</p>
  291. <p>
  292. This app would not be possible without the following libraries:
  293. </p>
  294. <ul>
  295. <li>SpinKit, &copy; 2015, Tobias Ahlin. Licensed under the MIT License.</li>
  296. <li>jQuery, The jQuery Foundation. Licensed under the MIT License.</li>
  297. <li>cJSON, &copy; 2009-2017, Dave Gamble and cJSON contributors. Licensed under the MIT License.</li>
  298. </ul>
  299. </section>
  300. <div class="buttons">
  301. <input id="ok-credits" type="button" value="OK" class="ctr" />
  302. </div>
  303. </div>
  304. </body>
  305. <html>