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.

304 lines
14 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>{appname}</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 update() {
  51. $.ajax({
  52. 'method': 'GET',
  53. 'url': '/status',
  54. 'dataType': 'json'
  55. }).done(function(data) {
  56. $("#device").val(data.device);
  57. $("#network").val(data.network.toUpperCase());
  58. $("#ip").val(data.ip);
  59. $("#mqtt").val(data.mqtt ? "CONNECTED" : "NOT CONNECTED");
  60. if (data.relay) {
  61. $("#relay").addClass('btn-primary').html("ON");
  62. $("#status").val(1);
  63. } else {
  64. $("#relay").removeClass('btn-primary').html("OFF");
  65. $("#status").val(0);
  66. }
  67. });
  68. }
  69. $("#btn-admin").click(function() {
  70. $("#panel-admin").show();
  71. $("#panel-status").hide();
  72. $("#btn-admin").addClass('btn-primary');
  73. $("#btn-status").removeClass('btn-primary');
  74. });
  75. $("#btn-status").click(function() {
  76. $("#panel-admin").hide();
  77. $("#panel-status").show();
  78. $("#btn-admin").removeClass('btn-primary');
  79. $("#btn-status").addClass('btn-primary');
  80. });
  81. $("#relay").click(function(event) {
  82. var status = parseInt($("#status").val());
  83. if (status == 1) {
  84. $.ajax({'method': 'GET', 'url': '/relay/off'});
  85. } else {
  86. $.ajax({'method': 'GET', 'url': '/relay/on'});
  87. }
  88. setTimeout(update, 200);
  89. event.preventDefault();
  90. })
  91. function init() {
  92. update();
  93. timer = setInterval(update, {updateInterval});
  94. $("[name='rfDevice']").val({rfDevice});
  95. }
  96. init();
  97. });
  98. </script>
  99. </head>
  100. <body>
  101. <div class="container">
  102. <header class="navbar bg-grey">
  103. <section class="navbar-section">
  104. <a href="#" class="navbar-brand">{appname}</a>
  105. </section>
  106. <section class="navbar-section">
  107. <button class="btn" id="btn-admin">Administration</button>
  108. <button class="btn btn-primary" id="btn-status">Status</button>
  109. </section>
  110. </header>
  111. <div class="page" id="panel-status" style="display: block;">
  112. <div class="columns">
  113. <div class="column col-12">
  114. <form class="form-horizontal">
  115. <div class="form-group">
  116. <div class="col-xs-3">
  117. <label class="form-label" for="device">Device</label>
  118. </div>
  119. <div class="col-xs-9">
  120. <input type="text" class="form-input" id="device" disabled>
  121. </div>
  122. </div>
  123. <div class="form-group">
  124. <div class="col-xs-3">
  125. <label class="form-label" for="network">Network</label>
  126. </div>
  127. <div class="col-xs-9">
  128. <input type="text" class="form-input" id="network" disabled>
  129. </div>
  130. </div>
  131. <div class="form-group">
  132. <div class="col-xs-3">
  133. <label class="form-label" for="ip">IP</label>
  134. </div>
  135. <div class="col-xs-9">
  136. <input type="text" class="form-input" id="ip" disabled>
  137. </div>
  138. </div>
  139. <div class="form-group">
  140. <div class="col-xs-3">
  141. <label class="form-label" for="mqtt">MQTT Status</label>
  142. </div>
  143. <div class="col-xs-9">
  144. <input type="text" class="form-input" id="mqtt" disabled>
  145. </div>
  146. </div>
  147. <div class="form-group">
  148. <div class="col-xs-3">
  149. <label class="form-label" for="relay">Relay Status</label>
  150. </div>
  151. <div class="col-xs-6">
  152. <input type="hidden" class="form-input" name="status" id="status" value="0" />
  153. <a class="btn" data="0" id="relay">OFF</a>
  154. </div>
  155. </div>
  156. </form>
  157. </div>
  158. </div>
  159. </div>
  160. <div class="page" id="panel-admin">
  161. <form action="/" method="post">
  162. <div class="hint">
  163. You can configure up to 3 different WiFi networks. The device will try to connect to any of them starting with the first one.
  164. </div>
  165. <div class="columns">
  166. <div class="column col-4">
  167. <h5>Network 1</h5>
  168. <div class="form-group">
  169. <label class="form-label" for="ssid0">Network SSID</label>
  170. <input name="ssid0" type="text" class="form-input" value="{ssid0}" size="8" tabindex="1" placeholder="Network SSID">
  171. </div>
  172. <div>
  173. <label class="form-label" for="pass0">Network Password</label>
  174. <input name="pass0" type="text" class="form-input" value="{pass0}" maxlength="255" tabindex="2" placeholder="Network password">
  175. </div>
  176. </div>
  177. <div class="column col-4">
  178. <h5>Network 2</h5>
  179. <div class="form-group">
  180. <label class="form-label" for="ssid1">Network SSID</label>
  181. <input name="ssid1" type="text" class="form-input" value="{ssid1}" size="8" tabindex="3" placeholder="Network SSID">
  182. </div>
  183. <div>
  184. <label class="form-label" for="pass1">Network Password</label>
  185. <input name="pass1" type="text" class="form-input" value="{pass1}" maxlength="255" tabindex="4" placeholder="Network password">
  186. </div>
  187. </div>
  188. <div class="column col-4">
  189. <h5>Network 3</h5>
  190. <div class="form-group">
  191. <label class="form-label" for="ssid2">Network SSID</label>
  192. <input name="ssid2" type="text" class="form-input" value="{ssid2}" size="8" tabindex="5" placeholder="Network SSID">
  193. </div>
  194. <div>
  195. <label class="form-label" for="pass2">Network Password</label>
  196. <input name="pass2" type="text" class="form-input" value="{pass2}" maxlength="255" tabindex="6" placeholder="Network password">
  197. </div>
  198. </div>
  199. </div>
  200. <div class="clearfix"></div>
  201. <div class="hint">
  202. 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.
  203. 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.
  204. </div>
  205. <div class="columns">
  206. <div class="column col-4">
  207. <div class="form-group">
  208. <label class="form-label" for="mqttServer">MQTT Server</label>
  209. <input name="mqttServer" type="text" class="form-input" value="{mqttServer}" size="8" tabindex="8" placeholder="MQTT Server">
  210. </div>
  211. </div>
  212. <div class="column col-2">
  213. <div class="form-group">
  214. <label class="form-label" for="mqttPort">MQTT Port</label>
  215. <input name="mqttPort" type="text" class="form-input" value="{mqttPort}" size="8" tabindex="9" placeholder="1883">
  216. </div>
  217. </div>
  218. </div>
  219. <div class="columns">
  220. <div class="column col-4">
  221. <div class="form-group">
  222. <label class="form-label" for="mqttUser">MQTT User</label>
  223. <input name="mqttUser" type="text" class="form-input" value="{mqttUser}" size="8" tabindex="10" placeholder="Leave blank if no user/pass">
  224. </div>
  225. </div>
  226. <div class="column col-4">
  227. <div class="form-group">
  228. <label class="form-label" for="mqttPassword">MQTT Password</label>
  229. <input name="mqttPassword" type="text" class="form-input" value="{mqttPassword}" size="8" tabindex="11" placeholder="Leave blank if no user/pass">
  230. </div>
  231. </div>
  232. </div>
  233. <div class="columns">
  234. <div class="column col-4">
  235. <div class="form-group">
  236. <label class="form-label" for="mqttTopic">MQTT Topic</label>
  237. <input name="mqttTopic" type="text" class="form-input" value="{mqttTopic}" size="8" tabindex="12" placeholder="MQTT Topic">
  238. </div>
  239. </div>
  240. </div>
  241. <div class="clearfix"></div>
  242. <div class="hint">
  243. If your device supports RF switching you can configure here the channel and device ID.
  244. </div>
  245. <div class="columns">
  246. <div class="column col-2">
  247. <div class="form-group">
  248. <label class="form-label" for="rfChannel">RF Channel</label>
  249. <input name="rfChannel" type="number" min="0" max="31" step="1" class="form-input" value="{rfChannel}" tabindex="13"/>
  250. </div>
  251. </div>
  252. <div class="column col-2">
  253. <div class="form-group">
  254. <label class="form-label" for="rfDevice">RF Device</label>
  255. <select name="rfDevice" class="form-input" tabindex="14">
  256. <option value="0">A</a>
  257. <option value="1">B</a>
  258. <option value="2">C</a>
  259. <option value="3">D</a>
  260. <option value="4">E</a>
  261. </select>
  262. </div>
  263. </div>
  264. </div>
  265. <div>
  266. <div>
  267. <button class="btn btn-primary float-right">Update</button>
  268. </div>
  269. </div>
  270. </form>
  271. </div>
  272. </div>
  273. </body>
  274. </html>