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.

240 lines
8.7 KiB

  1. <!doctype html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.8.0.js"></script>
  6. <script src="../js/zcmd.js"></script>
  7. <meta name="viewport" content="width=device-width,initial-scale=1">
  8. <title>日志配置</title>
  9. <style>
  10. </style>
  11. <script>
  12. </script>
  13. </head>
  14. <body>
  15. <script>
  16. var zcmd = new ZCommand();
  17. zcmd.set_onSendraw(function (data) {
  18. console.log("zcmd send:" + JSON.stringify(data, null, 0));
  19. });
  20. zcmd.set_onReceipt(function (tx, rx) {
  21. console.log("zcmd receipt:" + JSON.stringify(rx, null, 0));
  22. });
  23. </script>
  24. <!--
  25. /*******************************************************************************************************************
  26. * =================================================deviceStates================================================== *
  27. *******************************************************************************************************************/
  28. -->
  29. <div>
  30. <h1>deviceStates</h1>
  31. <select id="RefreshPeriod">
  32. <option value=1000>1s</option>
  33. <option value=2000>2s</option>
  34. <option value=3000>3s</option>
  35. <option value=4000>4s</option>
  36. <option value=5000>5s</option>
  37. </select>
  38. <!-- 开始刷新 -->
  39. <button id="startRefresh">Start Refresh</button>
  40. <!-- 停止刷新 -->
  41. <button id="stopRefresh">Stop Refresh</button>
  42. <table id="deviceStates">
  43. <tr>
  44. <td>Key</td>
  45. <td>Value</td>
  46. <td>单位</td>
  47. </tr>
  48. <tr>
  49. <td>----</td>
  50. <td>----</td>
  51. <td>----</td>
  52. </tr>
  53. </table>
  54. <script>
  55. zcmd.set_onConnect(function () {
  56. alert("connect to server");
  57. });
  58. var refreshId;
  59. $("#startRefresh").click(function () {
  60. if (refreshId)
  61. clearInterval(refreshId);
  62. refreshId = setInterval(function () {
  63. zcmd.send_message({
  64. "command": "getDeviceState",
  65. "need_receipt": true,
  66. }, 4000).then((data) => {
  67. console.log(data);
  68. var html = "";
  69. html += "<tr>";
  70. html += "<td>Key</td>";
  71. html += "<td>Value</td>";
  72. html += "<td>单位</td>";
  73. html += "</tr>";
  74. for (var i = 0; i < data.deviceState.length; i++) {
  75. html += "<tr>";
  76. html += "<td>" + data.deviceState[i].id + "</td>";
  77. html += "<td>" + data.deviceState[i].value + "</td>";
  78. html += "<td>" + data.deviceState[i].unit + "</td>";
  79. html += "</tr>";
  80. }
  81. $("#deviceStates").html(html);
  82. });
  83. }, $("#RefreshPeriod").val());
  84. });
  85. $("#stopRefresh").click(function () {
  86. clearInterval(refreshId);
  87. });
  88. </script>
  89. </div>
  90. <!--
  91. /*******************************************************************************************************************
  92. * ==================================================测试按键=================================================== *
  93. *******************************************************************************************************************/
  94. -->
  95. <!--
  96. type(option),value(false,true),relayControl
  97. type->option:
  98. 0,kRouterPower,
  99. 1,kTouchScreenPower,
  100. 2,kUsbChargerPower,
  101. 3,kCameraPower,
  102. 4,kLightPower,
  103. -->
  104. <div>
  105. <h1>测试</h1>
  106. <table>
  107. <tr>
  108. <td>relayControl type value</td>
  109. <td>
  110. <select id="relayControl_type">
  111. <option value=0>kRouterPower</option>
  112. <option value=1>kTouchScreenPower</option>
  113. <option value=2>kUsbChargerPower</option>
  114. <option value=3>kCameraPower</option>
  115. <option value=4>kLightPower</option>
  116. </select>
  117. <select id="relayControl_value">
  118. <option value=0>false</option>
  119. <option value=1>true</option>
  120. </select>
  121. </td>
  122. <td> <button id="relayControl">Trigger</button> </td>
  123. <script>
  124. $("#relayControl").click(function () {
  125. zcmd.send_message({
  126. "command": "relayControl",
  127. "need_receipt": true,
  128. "type": Number($("#relayControl_type").val()),
  129. "value": ($("#relayControl_value").val() == 'true'),
  130. }, 4000);
  131. });
  132. </script>
  133. </tr>
  134. <tr>
  135. <td>fanSetState id value</td>
  136. <td>
  137. <select id="fanSetState_id">
  138. <option value=0>0</option>
  139. <option value=1>1</option>
  140. </select>
  141. <select id="fanSetState_power">
  142. <option value=0>0</option>
  143. <option value=10>10</option>
  144. <option value=20>20</option>
  145. <option value=30>30</option>
  146. <option value=40>40</option>
  147. <option value=50>50</option>
  148. <option value=60>60</option>
  149. <option value=70>70</option>
  150. <option value=80>80</option>
  151. <option value=90>90</option>
  152. <option value=100>100</option>
  153. </select>
  154. </td>
  155. <td> <button id="fanSetState">Trigger</button> </td>
  156. <script>
  157. $("#fanSetState").click(function () {
  158. zcmd.send_message({
  159. "command": "fanSetState",
  160. "need_receipt": true,
  161. "id": Number($("#fanSetState_id").val()),
  162. "power": Number($("#fanSetState_power").val()),
  163. }, 4000).then((data) => {
  164. // console.log(data);
  165. });
  166. });
  167. </script>
  168. </tr>
  169. <tr>
  170. <td>relayStateGet</td>
  171. <td>-</td>
  172. <td><button
  173. onclick='zcmd.send_message({"command": "relayStateGet"},1000).then((data) => {alert(JSON.stringify(data,null,2))})'>Trigger</button>
  174. </td>
  175. </tr>
  176. <tr>
  177. <td>inputStateGet</td>
  178. <td>-</td>
  179. <td><button
  180. onclick='zcmd.send_message({"command": "inputStateGet"},1000).then((data) => {alert(JSON.stringify(data,null,2))})'>Trigger</button>
  181. </td>
  182. </tr>
  183. <tr>
  184. <td>idcardread</td>
  185. <td>-</td>
  186. <td><button
  187. onclick='zcmd.send_message({"command": "idcardread"},1000).then((data) => {alert(JSON.stringify(data,null,2))})'>Trigger</button>
  188. </td>
  189. </tr>
  190. <tr>
  191. <td>getInterTemperature</td>
  192. <td>-</td>
  193. <td><button
  194. onclick='zcmd.send_message({"command": "getInterTemperature"},1000).then((data) => {alert(JSON.stringify(data,null,2))})'>Trigger</button>
  195. </td>
  196. </tr>
  197. <tr>
  198. <td>getExterTemperature</td>
  199. <td>-</td>
  200. <td><button
  201. onclick='zcmd.send_message({"command": "getExterTemperature"},1000).then((data) => {alert(JSON.stringify(data,null,2))})'>Trigger</button>
  202. </td>
  203. </tr>
  204. <tr>
  205. <td>fanGetState</td>
  206. <td>-</td>
  207. <td><button
  208. onclick='zcmd.send_message({"command": "fanGetState"},1000).then((data) => {alert(JSON.stringify(data,null,2))})'>Trigger</button>
  209. </td>
  210. </tr>
  211. </table>
  212. </div>
  213. <script>
  214. $(function () {
  215. ZWSURL = "ws://127.0.0.1:19000";
  216. zcmd.start_auto_connect(ZWSURL);
  217. });
  218. </script>
  219. </body>
  220. </html>