Fork of the espurna firmware for `mhsw` switches
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

374 lines
18 KiB

8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>ESPurna</title>
  5. <meta charset="utf-8" />
  6. <link rel="stylesheet" href="spectre.min.css" />
  7. <script src="jquery-1.12.3.min.js"></script>
  8. <style>
  9. html, body {
  10. font-size: 12px;
  11. margin: 0;
  12. padding: 0;
  13. width: 100%;
  14. height: 100%;
  15. }
  16. div.page {
  17. display: none;
  18. }
  19. .bg-grey {
  20. background-color: #efefef;
  21. padding: 1rem;
  22. border-radius: .3rem;
  23. }
  24. div.hint {
  25. background-color: #efefef;
  26. padding: 2rem;
  27. margin: 20px 0;
  28. border-left: 2px solid blue;
  29. }
  30. </style>
  31. <script>
  32. $(function() {
  33. var timer = null;
  34. $("form").submit(function(event) {
  35. button = $(":submit", this);
  36. button.addClass("loading");
  37. $.ajax({
  38. 'method': 'POST',
  39. 'url': '/save',
  40. 'dataType': 'json',
  41. 'data': $(this).serializeArray()
  42. }).done(function(data) {
  43. button.removeClass("loading");
  44. }).fail(function() {
  45. button.removeClass("loading");
  46. });
  47. event.preventDefault();
  48. setTimeout(update, 200);
  49. });
  50. function init() {
  51. $.ajax({
  52. 'method': 'GET',
  53. 'url': '/init',
  54. 'dataType': 'json'
  55. }).done(function(data) {
  56. keys = Object.keys(data);
  57. for (index in keys) {
  58. key = "#" + keys[index];
  59. value = data[keys[index]];
  60. try {
  61. if ($(key).prop('tagName') == 'INPUT') {
  62. $(key).val(value);
  63. } else {
  64. $(key).html(value);
  65. }
  66. } catch(err) {
  67. // nope
  68. };
  69. };
  70. timer = setInterval(update, data.updateInterval);
  71. document.title = data.hostname;
  72. $("[name='pwMainsVoltage']").val(data.pwMainsVoltage);
  73. $("[name='rfDevice']").val(data.rfDevice);
  74. });
  75. }
  76. function update() {
  77. $.ajax({
  78. 'method': 'GET',
  79. 'url': '/status',
  80. 'dataType': 'json'
  81. }).done(function(data) {
  82. $("#mqtt").val(data.mqtt ? "CONNECTED" : "NOT CONNECTED");
  83. $("#power").val((data.power | 0) + "W");
  84. if (data.relay) {
  85. $("#relay").addClass('btn-primary').html("ON");
  86. $("#status").val(1);
  87. } else {
  88. $("#relay").removeClass('btn-primary').html("OFF");
  89. $("#status").val(0);
  90. }
  91. });
  92. }
  93. $("#btn-admin").click(function() {
  94. $("#panel-status").hide();
  95. $("#panel-admin").show();
  96. $("#btn-admin").addClass('btn-primary');
  97. $("#btn-status").removeClass('btn-primary');
  98. });
  99. $("#btn-status").click(function() {
  100. $("#panel-admin").hide();
  101. $("#panel-status").show();
  102. $("#btn-admin").removeClass('btn-primary');
  103. $("#btn-status").addClass('btn-primary');
  104. });
  105. $("#relay").click(function(event) {
  106. var status = parseInt($("#status").val());
  107. if (status == 1) {
  108. $.ajax({'method': 'GET', 'url': '/relay/off'});
  109. } else {
  110. $.ajax({'method': 'GET', 'url': '/relay/on'});
  111. }
  112. setTimeout(update, 200);
  113. event.preventDefault();
  114. })
  115. init();
  116. update();
  117. });
  118. </script>
  119. </head>
  120. <body>
  121. <div class="container">
  122. <header class="navbar bg-grey">
  123. <section class="navbar-section">
  124. <a href="#" class="navbar-brand"><span id="appname"></span></a>
  125. </section>
  126. <section class="navbar-section">
  127. <button class="btn" id="btn-admin">Administration</button>
  128. <button class="btn btn-primary" id="btn-status">Status</button>
  129. </section>
  130. </header>
  131. <div class="page" id="panel-status" style="display: block;">
  132. <div class="columns">
  133. <div class="column col-12">
  134. <form class="form-horizontal">
  135. <div class="form-group">
  136. <div class="col-xs-3">
  137. <label class="form-label" for="manufacturer">Manufacturer</label>
  138. </div>
  139. <div class="col-xs-9">
  140. <input type="text" class="form-input" id="manufacturer" value="" disabled>
  141. </div>
  142. </div>
  143. <div class="form-group">
  144. <div class="col-xs-3">
  145. <label class="form-label" for="model">Model</label>
  146. </div>
  147. <div class="col-xs-9">
  148. <input type="text" class="form-input" id="model" value="" disabled>
  149. </div>
  150. </div>
  151. <div class="form-group">
  152. <div class="col-xs-3">
  153. <label class="form-label" for="hostname">Hostname</label>
  154. </div>
  155. <div class="col-xs-9">
  156. <input type="text" class="form-input" id="hostname" value="" disabled>
  157. </div>
  158. </div>
  159. <div class="form-group">
  160. <div class="col-xs-3">
  161. <label class="form-label" for="network">Network</label>
  162. </div>
  163. <div class="col-xs-9">
  164. <input type="text" class="form-input" id="network" value="" disabled>
  165. </div>
  166. </div>
  167. <div class="form-group">
  168. <div class="col-xs-3">
  169. <label class="form-label" for="ip">IP</label>
  170. </div>
  171. <div class="col-xs-9">
  172. <input type="text" class="form-input" id="ip" value="" disabled>
  173. </div>
  174. </div>
  175. <div class="form-group">
  176. <div class="col-xs-3">
  177. <label class="form-label" for="mqtt">MQTT Status</label>
  178. </div>
  179. <div class="col-xs-9">
  180. <input type="text" class="form-input" id="mqtt" disabled>
  181. </div>
  182. </div>
  183. <div class="form-group">
  184. <div class="col-xs-3">
  185. <label class="form-label" for="power">Power</label>
  186. </div>
  187. <div class="col-xs-6">
  188. <input type="text" class="form-input" id="power" disabled>
  189. </div>
  190. </div>
  191. <div class="form-group">
  192. <div class="col-xs-3">
  193. <label class="form-label" for="relay">Relay Status</label>
  194. </div>
  195. <div class="col-xs-6">
  196. <input type="hidden" class="form-input" name="status" id="status" value="0" />
  197. <a class="btn" data="0" id="relay">OFF</a>
  198. </div>
  199. </div>
  200. </form>
  201. </div>
  202. </div>
  203. </div>
  204. <div class="page" id="panel-admin">
  205. <form action="/" method="post">
  206. <div class="hint">
  207. You can configure up to 3 different WiFi networks. The device will try to connect to any of them starting with the first one.
  208. </div>
  209. <div class="columns">
  210. <div class="column col-4">
  211. <h5>Network 1</h5>
  212. <div class="form-group">
  213. <label class="form-label" for="ssid0">Network SSID</label>
  214. <input name="ssid0" id="ssid0" type="text" class="form-input" size="8" tabindex="1" placeholder="Network SSID">
  215. </div>
  216. <div>
  217. <label class="form-label" for="pass0">Network Password</label>
  218. <input name="pass0" id="pass0" type="text" class="form-input" maxlength="255" tabindex="2" placeholder="Network password">
  219. </div>
  220. </div>
  221. <div class="column col-4">
  222. <h5>Network 2</h5>
  223. <div class="form-group">
  224. <label class="form-label" for="ssid1">Network SSID</label>
  225. <input name="ssid1" id="ssid1" type="text" class="form-input" size="8" tabindex="3" placeholder="Network SSID">
  226. </div>
  227. <div>
  228. <label class="form-label" for="pass1">Network Password</label>
  229. <input name="pass1" id="pass1" type="text" class="form-input" maxlength="255" tabindex="4" placeholder="Network password">
  230. </div>
  231. </div>
  232. <div class="column col-4">
  233. <h5>Network 3</h5>
  234. <div class="form-group">
  235. <label class="form-label" for="ssid2">Network SSID</label>
  236. <input name="ssid2" id="ssid2" type="text" class="form-input" size="8" tabindex="5" placeholder="Network SSID">
  237. </div>
  238. <div>
  239. <label class="form-label" for="pass2">Network Password</label>
  240. <input name="pass2" id="pass2" type="text" class="form-input" maxlength="255" tabindex="6" placeholder="Network password">
  241. </div>
  242. </div>
  243. </div>
  244. <div class="clearfix"></div>
  245. <div class="hint">
  246. Configure an <strong>MQTT broker</strong> in your network and you will be able to change the switch status via an MQTT message. Just send a 0 or a 1 as a payload to the provided topic below.
  247. The switch will also report its current open/close status to the same topic and its IP address to the topic you define plus "<code>/ip</code>". Leave the server field empty to disable MQTT.
  248. </div>
  249. <div class="columns">
  250. <div class="column col-4">
  251. <div class="form-group">
  252. <label class="form-label" for="mqttServer">MQTT Server</label>
  253. <input name="mqttServer" id="mqttServer" type="text" class="form-input" size="8" tabindex="8" placeholder="MQTT Server">
  254. </div>
  255. </div>
  256. <div class="column col-2">
  257. <div class="form-group">
  258. <label class="form-label" for="mqttPort">MQTT Port</label>
  259. <input name="mqttPort" id="mqttPort" type="text" class="form-input" size="8" tabindex="9" placeholder="1883">
  260. </div>
  261. </div>
  262. </div>
  263. <div class="columns">
  264. <div class="column col-4">
  265. <div class="form-group">
  266. <label class="form-label" for="mqttUser">MQTT User</label>
  267. <input name="mqttUser" id="mqttUser" type="text" class="form-input" size="8" tabindex="10" placeholder="Leave blank if no user/pass">
  268. </div>
  269. </div>
  270. <div class="column col-4">
  271. <div class="form-group">
  272. <label class="form-label" for="mqttPassword">MQTT Password</label>
  273. <input name="mqttPassword" id="mqttPassword" type="text" class="form-input" size="8" tabindex="11" placeholder="Leave blank if no user/pass">
  274. </div>
  275. </div>
  276. </div>
  277. <div class="columns">
  278. <div class="column col-4">
  279. <div class="form-group">
  280. <label class="form-label" for="mqttTopic">MQTT Topic</label>
  281. <input name="mqttTopic" id="mqttTopic" type="text" class="form-input" size="8" tabindex="12" maxlength="35" placeholder="MQTT Topic">
  282. </div>
  283. </div>
  284. </div>
  285. <div class="clearfix"></div>
  286. <div class="hint">
  287. If your device supports RF switching you can configure here the channel and device ID.
  288. </div>
  289. <div class="columns">
  290. <div class="column col-2">
  291. <div class="form-group">
  292. <label class="form-label" for="rfChannel">RF Channel</label>
  293. <input name="rfChannel" id="rfChannel" type="number" min="0" max="31" step="1" class="form-input" tabindex="13"/>
  294. </div>
  295. </div>
  296. <div class="column col-2">
  297. <div class="form-group">
  298. <label class="form-label" for="rfDevice">RF Device</label>
  299. <select name="rfDevice" class="form-input" tabindex="14">
  300. <option value="0">A</a>
  301. <option value="1">B</a>
  302. <option value="2">C</a>
  303. <option value="3">D</a>
  304. <option value="4">E</a>
  305. </select>
  306. </div>
  307. </div>
  308. </div>
  309. <div class="clearfix"></div>
  310. <div class="hint">
  311. If your device supports power measurement, here you can configure line potential and current ratio.
  312. </div>
  313. <div class="columns">
  314. <div class="column col-2">
  315. <div class="form-group">
  316. <label class="form-label" for="pwMainsVoltage">AC RMS Voltage</label>
  317. <select name="pwMainsVoltage" class="form-input" tabindex="15">
  318. <option value="125">125</a>
  319. <option value="220">220</a>
  320. <option value="230">230</a>
  321. <option value="240">240</a>
  322. </select>
  323. </div>
  324. </div>
  325. <div class="column col-2">
  326. <div class="form-group">
  327. <label class="form-label" for="pwCurrentRatio">Current ratio</label>
  328. <input name="pwCurrentRatio" id="pwCurrentRatio" type="text" class="form-input" size="8" tabindex="16" placeholder="30">
  329. </div>
  330. </div>
  331. </div>
  332. <div>
  333. <div>
  334. <button class="btn btn-primary float-right">Update</button>
  335. </div>
  336. </div>
  337. </form>
  338. </div>
  339. </div>
  340. </body>
  341. </html>