dry_function.js 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095
  1. // '/mqtt/' + tank_num 取代成 '/mqtt/' + tank_num
  2. function inputVacuum() {
  3. var status = "off";
  4. var check = $("input[name=input_vacuum_status]:checked"); // 這裡面是 jQuery 撈取資料的方法, jQuery 常使用到 $ 錢字號
  5. console.log('check:', check);
  6. //大於0代表有被選中, 如果有多個可以呈現勾取的項目數量
  7. if (check.length > 0) {
  8. status = "on";
  9. $("#cmn-toggle-02").prop('checked', false); // 設定為不要勾選
  10. if (!confirm("你確定要開啟入料儲豆槽真空吸料機嗎?")) {
  11. return false;
  12. };
  13. } else {
  14. $("#cmn-toggle-02").prop('checked', true); // 設定為勾選
  15. if (!confirm("你確定要關閉入料儲豆槽真空吸料機嗎?")) {
  16. return false;
  17. };
  18. };
  19. var data = { "tank_num": "DI" + tank_num, "command": "input_vacuum_status", "value": status };
  20. // jquery 請求 '/mqtt/{{tid}}' 頁面
  21. $.post('/mqtt/' + tank_num, data, function (res) { //res:HTTP response argument to the middleware function
  22. console.log('data:', data)
  23. if (res == 'on') {
  24. $("#cmn-toggle-02").prop('checked', true);
  25. setTimeout("alert('入料儲豆槽真空吸料機_開啟成功!')", 500);
  26. } else if (res == 'off') {
  27. $("#cmn-toggle-02").prop('checked', false);
  28. setTimeout("alert('入料儲豆槽真空吸料機_關閉成功!')", 500);
  29. } else {
  30. alert(res);
  31. };
  32. }, 'text')
  33. };
  34. function inputVacuum_ON() {
  35. var data = { "tank_num": "DI" + tank_num, "command": "input_vacuum_status", "value": "on" };
  36. $.post('/mqtt/' + tank_num, data, function (res) {
  37. console.log('data:', data)
  38. if (res == 'on') {
  39. $("#cmn-toggle-02").prop('checked', true);
  40. } else if (res == 'off') {
  41. $("#cmn-toggle-02").prop('checked', false);
  42. } else {
  43. console.log('res error')
  44. };
  45. }, 'text')
  46. }
  47. function inputVacuum_OFF() {
  48. var data = { "tank_num": "DI" + tank_num, "command": "input_vacuum_status", "value": "off" };
  49. $.post('/mqtt/' + tank_num, data, function (res) {
  50. console.log('data:', data)
  51. if (res == 'on') {
  52. $("#cmn-toggle-02").prop('checked', true);
  53. } else if (res == 'off') {
  54. $("#cmn-toggle-02").prop('checked', false);
  55. } else {
  56. console.log('res error')
  57. };
  58. }, 'text')
  59. }
  60. // Benson 真空吸料機 (END)入料儲豆槽
  61. // Benson 真空吸料機 (START)
  62. function tankVacuum() {
  63. var status = "off";
  64. var check = $("input[name=tank_vacuum_status]:checked");
  65. console.log('check:', check);
  66. //大於0代表有被選中
  67. if (check.length > 0) {
  68. status = "on";
  69. $("#cmn-toggle-05").prop('checked', false);
  70. if (!confirm("你確定要開啟真空吸料機嗎?")) {
  71. return false;
  72. };
  73. } else {
  74. $("#cmn-toggle-05").prop('checked', true);
  75. if (!confirm("你確定要關閉真空吸料機嗎?")) {
  76. return false;
  77. };
  78. };
  79. var data = { "tank_num": "D" + tank_num, "command": "tank_vacuum_status", "value": status };
  80. $.post('/mqtt/' + tank_num, data, function (res) {
  81. console.log('data:', data)
  82. if (res == 'on') {
  83. $("#cmn-toggle-05").prop('checked', true);
  84. setTimeout("alert('真空吸料機_開啟成功!')", 500);
  85. } else if (res == 'off') {
  86. $("#cmn-toggle-05").prop('checked', false);
  87. setTimeout("alert('真空吸料機_關閉成功!')", 500);
  88. } else {
  89. alert(res);
  90. };
  91. }, 'text')
  92. $.get('/loading/D' + tank_num, '', function (res) {
  93. if (res.tank_vacuum == 0) {
  94. $("#cmn-toggle-05").prop('checked', false);
  95. } else if (res.tank_vacuum == 1) {
  96. $("#cmn-toggle-05").prop('checked', true);
  97. }
  98. }, 'json');
  99. // window.location.reload();
  100. };
  101. function tankVacuum_ON() {
  102. var data = { "tank_num": "D" + tank_num, "command": "tank_vacuum_status", "value": "on" };
  103. $.post('/mqtt/' + tank_num, data, function (res) {
  104. console.log('data:', data)
  105. if (res == 'on') {
  106. $("#cmn-toggle-05").prop('checked', true);
  107. } else if (res == 'off') {
  108. $("#cmn-toggle-05").prop('checked', false);
  109. } else {
  110. console.log('res error')
  111. };
  112. }, 'text')
  113. // window.location.reload();
  114. }
  115. function tankVacuum_OFF() {
  116. var data = { "tank_num": "D" + tank_num, "command": "tank_vacuum_status", "value": "off" };
  117. $.post('/mqtt/' + tank_num, data, function (res) {
  118. console.log('data:', data)
  119. if (res == 'on') {
  120. $("#cmn-toggle-05").prop('checked', true);
  121. } else if (res == 'off') {
  122. $("#cmn-toggle-05").prop('checked', false);
  123. } else {
  124. console.log('res error')
  125. };
  126. }, 'text')
  127. // window.location.reload();
  128. }
  129. // Benson 真空吸料機 (END)
  130. function tankThreeWayValve() {
  131. //<!--setInterval(Relay,10000);-->
  132. var status = "off";
  133. var check = $("input[name=tank_threewayvalve_status]:checked");
  134. //大於0代表有被選中
  135. if (check.length > 0) {
  136. status = "on";
  137. $("#cmn-toggle-08").prop('checked', false);
  138. if (!confirm("你確定要開啟三通閥嗎?")) {
  139. return false;
  140. };
  141. } else {
  142. $("#cmn-toggle-08").prop('checked', true);
  143. if (!confirm("你確定要關閉三通閥嗎?")) {
  144. return false;
  145. };
  146. };
  147. var data = { "tank_num": "D" + tank_num, "command": "tank_threewayvalve_status", "value": status };
  148. $.post('/mqtt/' + tank_num, data, function (res) {
  149. console.log('data:', data)
  150. if (res == 'on') {
  151. $("#cmn-toggle-08").prop('checked', true);
  152. setTimeout("alert('三通閥入料_開啟成功!')", 500);
  153. } else if (res == 'off') {
  154. $("#cmn-toggle-08").prop('checked', false);
  155. setTimeout("alert('三通閥排氣_關閉成功!')", 500);
  156. } else {
  157. alert(res);
  158. };
  159. }, 'text')
  160. $.get('/loading/D' + tank_num, '', function (res) {
  161. if (res.tank_threewayvalve == 0) {
  162. $("#cmn-toggle-08").prop('checked', false);
  163. } else if (res.tank_threewayvalve == 1) {
  164. $("#cmn-toggle-08").prop('checked', true);
  165. }
  166. }, 'json');
  167. // window.location.reload();
  168. };
  169. function tankThreeWayValve_ON() {
  170. var data = { "tank_num": "D" + tank_num, "command": "tank_threewayvalve_status", "value": "on" };
  171. $.post('/mqtt/' + tank_num, data, function (res) {
  172. console.log('data:', data)
  173. if (res == 'on') {
  174. $("#cmn-toggle-08").prop('checked', true);
  175. } else if (res == 'off') {
  176. $("#cmn-toggle-08").prop('checked', false);
  177. } else {
  178. console.log('res error')
  179. };
  180. }, 'text')
  181. // window.location.reload();
  182. }
  183. function tankThreeWayValve_OFF() {
  184. var data = { "tank_num": "D" + tank_num, "command": "tank_threewayvalve_status", "value": "off" };
  185. $.post('/mqtt/' + tank_num, data, function (res) {
  186. console.log('data:', data)
  187. if (res == 'on') {
  188. $("#cmn-toggle-08").prop('checked', true);
  189. } else if (res == 'off') {
  190. $("#cmn-toggle-08").prop('checked', false);
  191. } else {
  192. console.log('res error')
  193. };
  194. }, 'text')
  195. // window.location.reload();
  196. }
  197. function tankThreeWayValveInput(params) {
  198. if (params == '1') {
  199. var data = { "tank_num": "D" + tank_num, "command": "tank_threewayvalve_input_status", "value": "on" };
  200. } else if (params == '0') {
  201. var data = { "tank_num": "D" + tank_num, "command": "tank_threewayvalve_input_status", "value": "off" };
  202. } else {
  203. var status = "off";
  204. var check = $("input[name=tank_threewayvalve_input_status]:checked");
  205. if (check.length > 0) {
  206. status = "on";
  207. $("#cmn-toggle-08").prop('checked', false);
  208. if (!confirm("你確定要開啟入料三通閥嗎?")) {
  209. return false;
  210. };
  211. } else {
  212. $("#cmn-toggle-08").prop('checked', true);
  213. if (!confirm("你確定要關閉入料三通閥嗎?")) {
  214. return false;
  215. };
  216. };
  217. var data = { "tank_num": "D" + tank_num, "command": "tank_threewayvalve_input_status", "value": status };
  218. }
  219. $.post('/mqtt/{{tid}}', data, function (res) {
  220. console.log('data:', data)
  221. if (res == 'on') {
  222. $("#cmn-toggle-08").prop('checked', true);
  223. } else if (res == 'off') {
  224. $("#cmn-toggle-08").prop('checked', false);
  225. } else {
  226. console.log('res error')
  227. };
  228. }, 'text')
  229. }
  230. function tankThreeWayValveBean(params) {
  231. if (params == '1') {
  232. var data = { "tank_num": "D" + tank_num, "command": "tank_threewayvalve_bean_status", "value": "on" };
  233. } else if (params == '0') {
  234. var data = { "tank_num": "D" + tank_num, "command": "tank_threewayvalve_bean_status", "value": "off" };
  235. } else {
  236. var status = "off";
  237. var check = $("input[name=tank_threewayvalve_bean_status]:checked");
  238. if (check.length > 0) {
  239. status = "on";
  240. $("#cmn-toggle-38").prop('checked', false);
  241. if (!confirm("你確定要開啟測豆三通閥嗎?")) {
  242. return false;
  243. };
  244. } else {
  245. $("#cmn-toggle-38").prop('checked', true);
  246. if (!confirm("你確定要關閉測豆三通閥嗎?")) {
  247. return false;
  248. };
  249. };
  250. var data = { "tank_num": "D" + tank_num, "command": "tank_threewayvalve_bean_status", "value": status };
  251. }
  252. $.post('/mqtt/{{tid}}', data, function (res) {
  253. console.log('data:', data)
  254. if (res == 'on') {
  255. $("#cmn-toggle-38").prop('checked', true);
  256. } else if (res == 'off') {
  257. $("#cmn-toggle-38").prop('checked', false);
  258. } else {
  259. console.log('res error')
  260. };
  261. }, 'text')
  262. }
  263. // Benson cargo2_actuator.html 控制蝴蝶閥函數 (START)
  264. function tankDiskValve() {
  265. //<!--setInterval(Relay,10000);-->
  266. var status = "off";
  267. var check = $("input[name=tank_diskvalve_status]:checked");
  268. //大於0代表有被選中
  269. if (check.length > 0) {
  270. status = "on";
  271. $("#cmn-toggle-11").prop('checked', false);
  272. if (!confirm("你確定要開啟蝴蝶閥嗎?")) {
  273. return false;
  274. };
  275. } else {
  276. $("#cmn-toggle-11").prop('checked', true);
  277. if (!confirm("你確定要關閉蝴蝶閥嗎?")) {
  278. return false;
  279. };
  280. };
  281. var data = { "tank_num": "D" + tank_num, "command": "tank_diskvalve_status", "value": status };
  282. $.post('/mqtt/' + tank_num, data, function (res) {
  283. console.log('data:', data)
  284. if (res == 'on') {
  285. $("#cmn-toggle-11").prop('checked', true);
  286. setTimeout("alert('蝴蝶閥_開啟成功!')", 500);
  287. } else if (res == 'off') {
  288. $("#cmn-toggle-11").prop('checked', false);
  289. setTimeout("alert('蝴蝶閥_關閉成功!')", 500);
  290. } else {
  291. alert(res);
  292. };
  293. }, 'text')
  294. $.get('/loading/D' + tank_num, '', function (res) {
  295. if (res.tank_diskvalve == 0) {
  296. $("#cmn-toggle-11").prop('checked', false);
  297. } else if (res.tank_diskvalve == 1) {
  298. $("#cmn-toggle-11").prop('checked', true);
  299. }
  300. }, 'json');
  301. // window.location.reload();
  302. };
  303. function tankDiskValve_ON() {
  304. var data = { "tank_num": "D" + tank_num, "command": "tank_diskvalve_status", "value": "on" };
  305. $.post('/mqtt/' + tank_num, data, function (res) {
  306. console.log('data:', data)
  307. if (res == 'on') {
  308. $("#cmn-toggle-11").prop('checked', true);
  309. } else if (res == 'off') {
  310. $("#cmn-toggle-11").prop('checked', false);
  311. } else {
  312. console.log('res error')
  313. };
  314. }, 'text')
  315. // window.location.reload();
  316. }
  317. function tankDiskValve_OFF() {
  318. var data = { "tank_num": "D" + tank_num, "command": "tank_diskvalve_status", "value": "off" };
  319. $.post('/mqtt/' + tank_num, data, function (res) {
  320. console.log('data:', data)
  321. if (res == 'on') {
  322. $("#cmn-toggle-11").prop('checked', true);
  323. } else if (res == 'off') {
  324. $("#cmn-toggle-11").prop('checked', false);
  325. } else {
  326. console.log('res error')
  327. };
  328. }, 'text')
  329. // window.location.reload();
  330. }
  331. // Benson cargo2_actuator.html 控制蝴蝶閥函數 (END)
  332. // Benson cargo2_actuator.html 閥 (START) 電磁閥消毒
  333. function tankSolenoidDisinfect() {
  334. var status = "off";
  335. var check = $("input[name=tank_solenoid_disinfect_status]:checked");
  336. //大於0代表有被選中
  337. if (check.length > 0) {
  338. status = "on";
  339. $("#cmn-toggle-14").prop('checked', false);
  340. if (!confirm("你確定要開啟電磁閥消毒嗎?")) {
  341. return false;
  342. };
  343. } else {
  344. $("#cmn-toggle-14").prop('checked', true);
  345. if (!confirm("你確定要關閉消毒電磁閥嗎?")) {
  346. return false;
  347. };
  348. };
  349. var data = { "tank_num": "D" + tank_num, "command": "tank_solenoid_disinfect_status", "value": status };
  350. $.post('/mqtt/' + tank_num, data, function (res) {
  351. console.log('data:', data)
  352. if (res == 'on') {
  353. $("#cmn-toggle-14").prop('checked', true);
  354. setTimeout("alert('電磁閥消毒_開啟成功!')", 500);
  355. } else if (res == 'off') {
  356. $("#cmn-toggle-14").prop('checked', false);
  357. setTimeout("alert('電磁閥消毒_關閉成功!')", 500);
  358. } else {
  359. alert(res);
  360. };
  361. }, 'text')
  362. $.get('/loading/D' + tank_num, '', function (res) {
  363. if (res.tank_solenoid_disinfect == 0) {
  364. $("#cmn-toggle-14").prop('checked', false);
  365. } else if (res.tank_solenoid_disinfect == 1) {
  366. $("#cmn-toggle-14").prop('checked', true);
  367. }
  368. }, 'json');
  369. // window.location.reload();
  370. };
  371. function tankSolenoidDisinfect_ON() {
  372. var data = { "tank_num": "D" + tank_num, "command": "tank_solenoid_disinfect_status", "value": "on" };
  373. $.post('/mqtt/' + tank_num, data, function (res) {
  374. console.log('data:', data)
  375. if (res == 'on') {
  376. $("#cmn-toggle-14").prop('checked', true);
  377. } else if (res == 'off') {
  378. $("#cmn-toggle-14").prop('checked', false);
  379. } else {
  380. console.log('res error')
  381. };
  382. }, 'text')
  383. // window.location.reload();
  384. }
  385. function tankSolenoidDisinfect_OFF() {
  386. var data = { "tank_num": "D" + tank_num, "command": "tank_solenoid_disinfect_status", "value": "off" };
  387. $.post('/mqtt/' + tank_num, data, function (res) {
  388. console.log('data:', data)
  389. if (res == 'on') {
  390. $("#cmn-toggle-14").prop('checked', true);
  391. } else if (res == 'off') {
  392. $("#cmn-toggle-14").prop('checked', false);
  393. } else {
  394. console.log('res error')
  395. };
  396. }, 'text')
  397. // window.location.reload();
  398. }
  399. // Benson cargo2_actuator.html 閥 (END) 電磁閥消毒
  400. // Benson cargo2_actuator.html 閥 (START) 電磁閥排水
  401. function tankSolenoidWater() {
  402. var status = "off";
  403. var check = $("input[name=tank_solenoid_water_status]:checked");
  404. //大於0代表有被選中
  405. if (check.length > 0) {
  406. status = "on";
  407. $("#cmn-toggle-17").prop('checked', false);
  408. if (!confirm("你確定要開啟電磁閥排水嗎?")) {
  409. return false;
  410. };
  411. } else {
  412. $("#cmn-toggle-17").prop('checked', true);
  413. if (!confirm("你確定要關閉排水電磁閥嗎?")) {
  414. return false;
  415. };
  416. };
  417. var data = { "tank_num": "D" + tank_num, "command": "tank_solenoid_water_status", "value": status };
  418. $.post('/mqtt/' + tank_num, data, function (res) {
  419. console.log('data:', data)
  420. if (res == 'on') {
  421. $("#cmn-toggle-17").prop('checked', true);
  422. setTimeout("alert('電磁閥排水_開啟成功!')", 500);
  423. } else if (res == 'off') {
  424. $("#cmn-toggle-17").prop('checked', false);
  425. setTimeout("alert('電磁閥排水_關閉成功!')", 500);
  426. } else {
  427. alert(res);
  428. };
  429. }, 'text')
  430. $.get('/loading/D' + tank_num, '', function (res) {
  431. if (res.tank_solenoid_water == 0) {
  432. $("#cmn-toggle-17").prop('checked', false);
  433. } else if (res.tank_solenoid_water == 1) {
  434. $("#cmn-toggle-17").prop('checked', true);
  435. }
  436. }, 'json');
  437. // window.location.reload();
  438. };
  439. function tankSolenoidWater_ON() {
  440. var data = { "tank_num": "D" + tank_num, "command": "tank_solenoid_water_status", "value": "on" };
  441. $.post('/mqtt/' + tank_num, data, function (res) {
  442. console.log('data:', data)
  443. if (res == 'on') {
  444. $("#cmn-toggle-17").prop('checked', true);
  445. } else if (res == 'off') {
  446. $("#cmn-toggle-17").prop('checked', false);
  447. } else {
  448. console.log('res error')
  449. };
  450. }, 'text')
  451. // window.location.reload();
  452. }
  453. function tankSolenoidWater_OFF() {
  454. var data = { "tank_num": "D" + tank_num, "command": "tank_solenoid_water_status", "value": "off" };
  455. $.post('/mqtt/' + tank_num, data, function (res) {
  456. console.log('data:', data)
  457. if (res == 'on') {
  458. $("#cmn-toggle-17").prop('checked', true);
  459. } else if (res == 'off') {
  460. $("#cmn-toggle-17").prop('checked', false);
  461. } else {
  462. console.log('res error')
  463. };
  464. }, 'text')
  465. // window.location.reload();
  466. }
  467. // Benson cargo2_actuator.html 閥 (END) 電磁閥排水
  468. /*
  469. function Motor() {
  470. $.get('/peeling', '', function (res) {
  471. //console.log(res.peeling);
  472. $("#motor_rpm_status").text(res.peeling + ' rpm(每1分鐘更新一次)');
  473. }, 'json');
  474. };
  475. function ChangeMotor() {
  476. var motor_data = $("input[name=tank_motor_status]").val();
  477. if (!confirm("你確定要更改轉速為" + motor_data + "嗎?")) {
  478. return false;
  479. };
  480. var data = { "tank_num": "D" + tank_num, "command": "tank_motor_status", "value": motor_data };
  481. console.log('data:', data)
  482. $.post('/mqtt/' + tank_num, data, function (res) {
  483. if (res == 'on') {
  484. alert('更改成功');
  485. } else {
  486. alert(res);
  487. };
  488. }, 'text');
  489. setTimeout(function(){ location.reload(); }, 500);
  490. };
  491. */
  492. // Benson cargo2_actuator.html 脫皮機馬達 (START) 馬達攪拌棒
  493. function ChangeMotor() {
  494. var motor_data = $("input[id=motor_rpm_data]").val();
  495. if (motor_data == '') {
  496. //$("#cmn-toggle-20").prop('checked', false);
  497. alert("請先輸入要運轉的值!");
  498. return false;
  499. } else if (motor_data == 0) {
  500. alert("轉速 0 為關閉馬達");
  501. } else if (Number(motor_data) < -50 || Number(motor_data) > 50 || !Number(motor_data)) {
  502. //
  503. //$("#cmn-toggle-20").prop('checked', false);
  504. alert("您輸入的值已超過範圍,請重新輸入!" + !Number(motor_data));
  505. return false;
  506. };
  507. var value = "off";
  508. //var check = $("input[name=peeling-machine-on]:checked");
  509. if (motor_data != 0) {
  510. value = motor_data;
  511. //$("#cmn-toggle-20").prop('checked', false);
  512. if (!confirm("你確定要開啟攪拌馬達,運轉速度為 " + motor_data + " RPM 嗎?")) {
  513. return false;
  514. };
  515. } else {
  516. //$("#cmn-toggle-20").prop('checked', true);
  517. if (!confirm("你確定要關閉攪拌馬達嗎?")) {
  518. return false;
  519. };
  520. };
  521. var data = { "tank_num": "D" + tank_num, "command": "tank_motor_status", "value": motor_data };
  522. $.post('/mqtt/' + tank_num, data, function (res) {
  523. console.log('data:', data)
  524. if (res == 'on') {
  525. //$("#cmn-toggle-14").prop('checked', true); // prop 設置元素屬型與元素值, 設定 checked 屬性為 true
  526. setTimeout("alert('攪拌馬達_開啟成功!')", 500); // 設定時間執行函式 delay(500), 只執行一次
  527. var timer = setInterval(Rotate, 60000); // 啟動後會在 60000 毫秒(更新時間一分鐘)內不斷執行 (原因須配合更新時間?)
  528. } else if (res == 'off') {
  529. //$("#cmn-toggle-14").prop('checked', false);
  530. setTimeout("alert('攪拌馬達_關閉成功!')", 500);
  531. clearInterval(timer); // 取消 timer 的不斷執行
  532. $("#motor_rpm_status").text(''); // 設置 #motor_rpm_status 的文字為空, #井字號
  533. } else {
  534. alert(res);
  535. };
  536. }, 'text')
  537. $.get('/loading/D' + tank_num, '', function (res) {
  538. $("#motor_rpm_data").attr("placeholder", res.tank_motor)
  539. }, 'json');
  540. // window.location.reload();
  541. };
  542. function setMotor(RPMData) {
  543. var data = { "tank_num": "D" + tank_num, "command": "tank_motor_status", "value": RPMData };
  544. $.post('/mqtt/' + tank_num, data, function (res) {
  545. console.log('data:', data)
  546. if (res == 'on') {
  547. //$("#cmn-toggle-14").prop('checked', true); // prop 設置元素屬型與元素值, 設定 checked 屬性為 true
  548. var timer = setInterval(Rotate, 60000); // 啟動後會在 60000 毫秒(更新時間一分鐘)內不斷執行 (原因須配合更新時間?)
  549. } else if (res == 'off') {
  550. //$("#cmn-toggle-14").prop('checked', false);
  551. $("#motor_rpm_status").text(''); // 設置 #motor_rpm_status 的文字為空, #井字號
  552. } else {
  553. console.log(res)
  554. };
  555. }, 'text')
  556. $.get('/loading/D' + tank_num, '', function (res) {
  557. $("#motor_rpm_data").attr("placeholder", res.tank_motor)
  558. }, 'json');
  559. // window.location.reload();
  560. };
  561. function ChangeMotor_ON() {
  562. var data = { "tank_num": "D" + tank_num, "command": "tank_motor_status", "value": "20" };
  563. $.post('/mqtt/' + tank_num, data, function (res) {
  564. console.log('data:', data)
  565. if (res == 'on') {
  566. var timer = setInterval(Rotate, 60000);
  567. } else if (res == 'off') {
  568. clearInterval(timer);
  569. $("#motor_rpm_status").text('');
  570. } else {
  571. console.log('res error')
  572. };
  573. }, 'text')
  574. // window.location.reload();
  575. }
  576. function ChangeMotor_OFF() {
  577. var data = { "tank_num": "D" + tank_num, "command": "tank_motor_status", "value": "0" };
  578. $.post('/mqtt/' + tank_num, data, function (res) {
  579. console.log('data:', data)
  580. if (res == 'on') {
  581. var timer = setInterval(Rotate, 60000);
  582. } else if (res == 'off') {
  583. clearInterval(timer);
  584. $("#motor_rpm_status").text('');
  585. } else {
  586. console.log('res error')
  587. };
  588. }, 'text')
  589. // window.location.reload();
  590. }
  591. function Rotate() {
  592. $.get('/peeling', '', function (res) {
  593. //console.log(res.peeling);
  594. $("#motor_rpm_status-status").text(res.peeling + ' rpm(每1分鐘更新一次)');
  595. }, 'json');
  596. setTimeout(function () { location.reload(); }, 500);
  597. };
  598. // Benson cargo2_actuator.html 脫皮機馬達 (END) 馬達攪拌棒
  599. // Benson cargo2_actuator.html 鼓風機機 (START)
  600. // 鼓風機函數
  601. function tankBlower() {
  602. var status = "off";
  603. var check = $("input[name=tank_blower_status]:checked");
  604. //大於0代表有被選中
  605. if (check.length > 0) {
  606. status = "on";
  607. $("#cmn-toggle-23").prop('checked', false);
  608. if (!confirm("你確定要開啟鼓風機嗎?")) {
  609. return false;
  610. };
  611. } else {
  612. $("#cmn-toggle-23").prop('checked', true);
  613. if (!confirm("你確定要關閉鼓風機嗎?")) {
  614. return false;
  615. };
  616. };
  617. var data = { "tank_num": "D" + tank_num, "command": "tank_blower_status", "value": status };
  618. $.post('/mqtt/' + tank_num, data, function (res) {
  619. console.log('data:', data)
  620. if (res == 'on') {
  621. $("#cmn-toggle-23").prop('checked', true);
  622. setTimeout("alert('鼓風機_開啟成功!')", 500);
  623. } else if (res == 'off') {
  624. $("#cmn-toggle-23").prop('checked', false);
  625. setTimeout("alert('鼓風機_關閉成功!')", 500);
  626. } else {
  627. alert(res);
  628. };
  629. }, 'text')
  630. $.get('/loading/D' + tank_num, '', function (res) {
  631. if (res.tank_blower == 0) {
  632. $("#cmn-toggle-23").prop('checked', false);
  633. } else if (res.tank_blower == 1) {
  634. $("#cmn-toggle-23").prop('checked', true);
  635. }
  636. }, 'json');
  637. // window.location.reload();
  638. };
  639. function tankBlower_ON() {
  640. var data = { "tank_num": "D" + tank_num, "command": "tank_blower_status", "value": "on" };
  641. $.post('/mqtt/' + tank_num, data, function (res) {
  642. console.log('data:', data)
  643. if (res == 'on') {
  644. $("#cmn-toggle-23").prop('checked', true);
  645. } else if (res == 'off') {
  646. $("#cmn-toggle-23").prop('checked', false);
  647. } else {
  648. console.log('res error')
  649. };
  650. }, 'text')
  651. // window.location.reload();
  652. }
  653. function tankBlower_OFF() {
  654. var data = { "tank_num": "D" + tank_num, "command": "tank_blower_status", "value": "off" };
  655. $.post('/mqtt/' + tank_num, data, function (res) {
  656. console.log('data:', data)
  657. if (res == 'on') {
  658. $("#cmn-toggle-23").prop('checked', true);
  659. } else if (res == 'off') {
  660. $("#cmn-toggle-23").prop('checked', false);
  661. } else {
  662. console.log('res error')
  663. };
  664. }, 'text')
  665. // window.location.reload();
  666. }
  667. // Benson cargo2_actuator.html 鼓風機 (START)
  668. //電熱管1函數
  669. function tankHeater1() {
  670. var status = "off";
  671. var check = $("input[name=tank_heater1_status]:checked");
  672. //大於0代表有被選中
  673. if (check.length > 0) {
  674. status = "on";
  675. $("#cmn-toggle-26").prop('checked', false);
  676. if (!confirm("你確定要開啟電熱管1嗎?")) {
  677. return false;
  678. };
  679. } else {
  680. $("#cmn-toggle-26").prop('checked', true);
  681. if (!confirm("你確定要關閉電熱管1嗎?")) {
  682. return false;
  683. };
  684. };
  685. var data = { "tank_num": "D" + tank_num, "command": "tank_heater1_status", "value": status };
  686. $.post('/mqtt/' + tank_num, data, function (res) {
  687. console.log('data:', data)
  688. if (res == 'on') {
  689. $("#cmn-toggle-26").prop('checked', true);
  690. setTimeout("alert('電熱管1_開啟成功!')", 500);
  691. } else if (res == 'off') {
  692. $("#cmn-toggle-26").prop('checked', false);
  693. setTimeout("alert('電熱管1_關閉成功!')", 500);
  694. } else {
  695. alert(res);
  696. };
  697. }, 'text')
  698. $.get('/loading/D' + tank_num, '', function (res) {
  699. if (res.tank_heater1 == 0) {
  700. $("#cmn-toggle-26").prop('checked', false);
  701. } else if (res.tank_heater1 == 1) {
  702. $("#cmn-toggle-26").prop('checked', true);
  703. }
  704. }, 'json');
  705. // window.location.reload();
  706. };
  707. function tankHeater1_ON() {
  708. var data = { "tank_num": "D" + tank_num, "command": "tank_heater1_status", "value": "on" };
  709. $.post('/mqtt/' + tank_num, data, function (res) {
  710. console.log('data:', data)
  711. if (res == 'on') {
  712. $("#cmn-toggle-26").prop('checked', true);
  713. } else if (res == 'off') {
  714. $("#cmn-toggle-26").prop('checked', false);
  715. } else {
  716. console.log('res error')
  717. };
  718. }, 'text')
  719. // window.location.reload();
  720. }
  721. function tankHeater1_OFF() {
  722. var data = { "tank_num": "D" + tank_num, "command": "tank_heater1_status", "value": "off" };
  723. $.post('/mqtt/' + tank_num, data, function (res) {
  724. console.log('data:', data)
  725. if (res == 'on') {
  726. $("#cmn-toggle-26").prop('checked', true);
  727. } else if (res == 'off') {
  728. $("#cmn-toggle-26").prop('checked', false);
  729. } else {
  730. console.log('res error')
  731. };
  732. }, 'text')
  733. // window.location.reload();
  734. }
  735. //電熱管2函數
  736. function tankHeater2() {
  737. var status = "off";
  738. var check = $("input[name=tank_heater2_status]:checked");
  739. //大於0代表有被選中
  740. if (check.length > 0) {
  741. status = "on";
  742. $("#cmn-toggle-29").prop('checked', false);
  743. if (!confirm("你確定要開啟電熱管2嗎?")) {
  744. return false;
  745. };
  746. } else {
  747. $("#cmn-toggle-29").prop('checked', true);
  748. if (!confirm("你確定要關閉電熱管2嗎?")) {
  749. return false;
  750. };
  751. };
  752. var data = { "tank_num": "D" + tank_num, "command": "tank_heater2_status", "value": status };
  753. $.post('/mqtt/' + tank_num, data, function (res) {
  754. console.log('data:', data)
  755. if (res == 'on') {
  756. $("#cmn-toggle-29").prop('checked', true);
  757. setTimeout("alert('電熱管2_開啟成功!')", 500);
  758. } else if (res == 'off') {
  759. $("#cmn-toggle-29").prop('checked', false);
  760. setTimeout("alert('電熱管2_關閉成功!')", 500);
  761. } else {
  762. alert(res);
  763. };
  764. }, 'text')
  765. $.get('/loading/D' + tank_num, '', function (res) {
  766. if (res.tank_heater2 == 0) {
  767. $("#cmn-toggle-29").prop('checked', false);
  768. } else if (res.tank_heater2 == 1) {
  769. $("#cmn-toggle-29").prop('checked', true);
  770. }
  771. }, 'json');
  772. // window.location.reload();
  773. };
  774. function tankHeater2_ON() {
  775. var data = { "tank_num": "D" + tank_num, "command": "tank_heater2_status", "value": "on" };
  776. $.post('/mqtt/' + tank_num, data, function (res) {
  777. console.log('data:', data)
  778. if (res == 'on') {
  779. $("#cmn-toggle-29").prop('checked', true);
  780. } else if (res == 'off') {
  781. $("#cmn-toggle-29").prop('checked', false);
  782. } else {
  783. console.log('res error')
  784. };
  785. }, 'text')
  786. // window.location.reload();
  787. }
  788. function tankHeater2_OFF() {
  789. var data = { "tank_num": "D" + tank_num, "command": "tank_heater2_status", "value": "off" };
  790. $.post('/mqtt/' + tank_num, data, function (res) {
  791. console.log('data:', data)
  792. if (res == 'on') {
  793. $("#cmn-toggle-29").prop('checked', true);
  794. } else if (res == 'off') {
  795. $("#cmn-toggle-29").prop('checked', false);
  796. } else {
  797. console.log('res error')
  798. };
  799. }, 'text')
  800. // window.location.reload();
  801. }
  802. // 溫度控制
  803. function tankTemp1Enable() {
  804. var status = "off";
  805. var check = $("input[name=tank_temp1_enable_status]:checked");
  806. //大於0代表有被選中
  807. if (check.length > 0) {
  808. status = "on";
  809. $("#cmn-toggle-35").prop('checked', false);
  810. if (!confirm("你確定要開啟溫度控制嗎?")) {
  811. return false;
  812. };
  813. } else {
  814. $("#cmn-toggle-35").prop('checked', true);
  815. if (!confirm("你確定要關閉溫度控制嗎?")) {
  816. return false;
  817. };
  818. };
  819. var data = { "tank_num": "D" + tank_num, "command": "temp1_enable", "value": status };
  820. $.post('/mqtt/' + tank_num, data, function (res) {
  821. console.log('data:', data)
  822. if (res == 'on') {
  823. $("#cmn-toggle-35").prop('checked', true);
  824. setTimeout("alert('溫度控制_開啟成功!')", 500);
  825. } else if (res == 'off') {
  826. $("#cmn-toggle-35").prop('checked', false);
  827. setTimeout("alert('溫度控制_關閉成功!')", 500);
  828. } else {
  829. alert(res);
  830. };
  831. }, 'text')
  832. $.get('/loading/D' + tank_num, '', function (res) {
  833. if (res.tank_temp1_enable == 0) {
  834. $("#cmn-toggle-35").prop('checked', false);
  835. } else if (res.tank_temp1_enable == 1) {
  836. $("#cmn-toggle-35").prop('checked', true);
  837. }
  838. }, 'json');
  839. // window.location.reload();
  840. };
  841. function tankTemp1Enable_ON() {
  842. var data = { "tank_num": "D" + tank_num, "command": "tank_temp_enable", "value": "on" };
  843. $.post('/mqtt/' + tank_num, data, function (res) {
  844. console.log('data:', data)
  845. if (res == 'on') {
  846. $("#cmn-toggle-35").prop('checked', true);
  847. } else if (res == 'off') {
  848. $("#cmn-toggle-35").prop('checked', false);
  849. } else {
  850. console.log('res error')
  851. };
  852. }, 'text')
  853. // window.location.reload();
  854. }
  855. function tankTemp1Enable_OFF() {
  856. var data = { "tank_num": "D" + tank_num, "command": "temp1_enable", "value": "off" };
  857. $.post('/mqtt/' + tank_num, data, function (res) {
  858. console.log('data:', data)
  859. if (res == 'on') {
  860. $("#cmn-toggle-35").prop('checked', true);
  861. } else if (res == 'off') {
  862. $("#cmn-toggle-35").prop('checked', false);
  863. } else {
  864. console.log('res error')
  865. };
  866. }, 'text')
  867. // window.location.reload();
  868. }
  869. /* 判斷是否整數
  870. function isInteger(obj) {
  871. return obj % 1 === 0
  872. }
  873. isInteger(3) // true
  874. */
  875. // 設定溫度
  876. /*
  877. <h2>溫度控制設定(單位 ℃):(目前設定溫度) {{tank_temp1}}</h2>
  878. <input name="tank_temp1_data" type="text" placeholder="{{tank_temp1}}" style="width: 40px;">℃ (限整數數值)
  879. <span id="tank_temp1_status" style="color:red;"></span>
  880. <input type="button" value="送出(設定溫度時請點擊)" name="tank_temp1_status" onclick="ChangeTemp1()">
  881. */
  882. function ChangeTemp1() {
  883. var temp_data = $("input[id=tank_temp1_data]").val();
  884. if (temp_data == '') {
  885. //$("#cmn-toggle-20").prop('checked', false);
  886. alert("請先輸入設定溫度!");
  887. return false;
  888. }
  889. var value = "0";
  890. //var check = $("input[name=peeling-machine-on]:checked");
  891. if ($("#cmn-toggle-35").prop('checked')) {
  892. value = temp_data;
  893. //$("#cmn-toggle-20").prop('checked', false);
  894. if (!confirm("你確定要設定內桶溫度為 " + temp_data + " ℃ 嗎?")) {
  895. return false;
  896. };
  897. } else {
  898. //$("#cmn-toggle-20").prop('checked', true);
  899. //你確定要停止桶內溫度設定嗎
  900. if (!confirm("請先開啟溫控開關, 再設定桶內溫度")) {
  901. return false;
  902. };
  903. };
  904. var data = { "tank_num": "D" + tank_num, "command": "temp1", "value": temp_data };
  905. $.post('/mqtt/' + tank_num, data, function (res) {
  906. console.log('data:', data)
  907. if (res == 'on') {
  908. //$("#cmn-toggle-14").prop('checked', true); // prop 設置元素屬型與元素值, 設定 checked 屬性為 true
  909. setTimeout("alert('溫度設定_開啟成功!')", 500); // 設定時間執行函式 delay(500), 只執行一次
  910. } else if (res == 'off') {
  911. //$("#cmn-toggle-14").prop('checked', false);
  912. setTimeout("alert('溫度設定_關閉成功!')", 500);
  913. clearInterval(timer); // 取消 timer 的不斷執行
  914. $("#motor_rpm_status").text(''); // 設置 #motor_rpm_status 的文字為空, #井字號
  915. } else {
  916. alert(res);
  917. };
  918. }, 'text')
  919. $.get('/loading/D' + tank_num, '', function (res) {
  920. $("#tank_temp1_data").attr("placeholder", res.tank_temp1);
  921. }, 'json');
  922. // window.location.reload();
  923. };
  924. // Rita 設定溫度時直接開啟溫控開關
  925. function setTemp1(temp_data, temp_duration) {
  926. // var temp_data = $("input[id=tank_temp1_data]").val();
  927. if (temp_data == '') {
  928. alert("請先輸入設定溫度!");
  929. return false;
  930. } else if (temp_duration == '') {
  931. alert("請先輸入持溫時間!");
  932. return false;
  933. }
  934. // var value = "0";
  935. // var value = temp_data;
  936. // if (!confirm("你確定要設定內桶溫度為 " + temp_data + " ℃ 嗎?")) {
  937. // return false;
  938. // };
  939. tankTemp1Enable_ON()
  940. var data = { "tank_num": "D" + tank_num, "command": "temp1", "value": temp_data, "duration": temp_duration };
  941. $.post('/mqtt/' + tank_num, data, function (res) {
  942. console.log('data:', data)
  943. if (res == 'on') {
  944. //$("#cmn-toggle-14").prop('checked', true); // prop 設置元素屬型與元素值, 設定 checked 屬性為 true
  945. setTimeout("alert('溫度設定_開啟成功!')", 500); // 設定時間執行函式 delay(500), 只執行一次
  946. } else if (res == 'off') {
  947. //$("#cmn-toggle-14").prop('checked', false);
  948. setTimeout("alert('溫度設定_關閉成功!')", 500);
  949. clearInterval(timer); // 取消 timer 的不斷執行
  950. $("#motor_rpm_status").text(''); // 設置 #motor_rpm_status 的文字為空, #井字號
  951. } else {
  952. alert(res);
  953. };
  954. }, 'text')
  955. $.get('/loading/D' + tank_num, '', function (res) {
  956. $("#tank_temp1_data").attr("placeholder", res.tank_temp1);
  957. }, 'json');
  958. // window.location.reload();
  959. };
  960. function ChangeTemp1_ON() {
  961. var data = { "tank_num": "D" + tank_num, "command": "temp1", "value": "30" };
  962. $.post('/mqtt/' + tank_num, data, function (res) {
  963. console.log('data:', data)
  964. }, 'text')
  965. // window.location.reload();
  966. }
  967. function ChangeTemp1_OFF() {
  968. var data = { "tank_num": "D" + tank_num, "command": "temp1", "value": "25" };
  969. $.post('/mqtt/' + tank_num, data, function (res) {
  970. console.log('data:', data)
  971. }, 'text')
  972. // window.location.reload();
  973. }
  974. // Benson 真空吸料機 (START) 出料儲豆槽
  975. function outputVacuum() {
  976. var status = "off";
  977. var check = $("input[name=output_vacuum_status]:checked");
  978. //大於0代表有被選中
  979. if (check.length > 0) {
  980. status = "on";
  981. $("#cmn-toggle-32").prop('checked', false);
  982. if (!confirm("你確定要開啟出料儲豆槽真空吸料機嗎?")) {
  983. return false;
  984. };
  985. } else {
  986. $("#cmn-toggle-32").prop('checked', true);
  987. if (!confirm("你確定要關閉出料儲豆槽真空吸料機嗎?")) {
  988. return false;
  989. };
  990. };
  991. var data = { "tank_num": "DO" + tank_num, "command": "output_vacuum_status", "value": status };
  992. console.log('data:', data)
  993. $.post('/mqtt/' + tank_num, data, function (res) {
  994. if (res == 'on') {
  995. $("#cmn-toggle-32").prop('checked', true);
  996. setTimeout("alert('出料儲豆槽真空吸料機_開啟成功!')", 500);
  997. } else if (res == 'off') {
  998. $("#cmn-toggle-32").prop('checked', false);
  999. setTimeout("alert('出料儲豆槽真空吸料機_關閉成功!')", 500);
  1000. } else {
  1001. alert(res);
  1002. };
  1003. }, 'text')
  1004. };
  1005. function outputVacuum_ON() {
  1006. var data = { "tank_num": "DO" + tank_num, "command": "output_vacuum_status", "value": "on" };
  1007. console.log('data:', data)
  1008. $.post('/mqtt/' + tank_num, data, function (res) {
  1009. if (res == 'on') {
  1010. $("#cmn-toggle-32").prop('checked', true);
  1011. } else if (res == 'off') {
  1012. $("#cmn-toggle-32").prop('checked', false);
  1013. } else {
  1014. console.log('res error')
  1015. };
  1016. }, 'text')
  1017. }
  1018. function outputVacuum_OFF() {
  1019. var data = { "tank_num": "DO" + tank_num, "command": "output_vacuum_status", "value": "off" };
  1020. console.log('data:', data)
  1021. $.post('/mqtt/' + tank_num, data, function (res) {
  1022. if (res == 'on') {
  1023. $("#cmn-toggle-32").prop('checked', true);
  1024. } else if (res == 'off') {
  1025. $("#cmn-toggle-32").prop('checked', false);
  1026. } else {
  1027. console.log('res error')
  1028. };
  1029. }, 'text')
  1030. }
  1031. // Benson 真空吸料機 (END) 出料儲豆槽