index.html 12 KB

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