Changes for page 2 Script
Last modified by Devin Chen on 2025/06/06 14:03
Summary
-
Page properties (1 modified, 0 added, 0 removed)
Details
- Page properties
-
- Content
-
... ... @@ -70,12 +70,6 @@ 70 70 71 71 This example shows how to use the Bot API to send message into Telegram group or channel. When monitoring bit "@HDX" changes, it will trigger and send the message. Please replace with your own Token and chat id. 72 72 73 -As for How to get the botToken and chatID, please check the followig videos: 74 - 75 -[[https:~~/~~/www.youtube.com/watch?v=zh6yYlnjX7k>>https://www.youtube.com/watch?v=zh6yYlnjX7k]] 76 - 77 -[[https:~~/~~/www.youtube.com/watch?v=Pj8mwuMZZvg>>https://www.youtube.com/watch?v=Pj8mwuMZZvg]] 78 - 79 79 {{code language="Lua"}} 80 80 local tempBit = 0 81 81 local tempWord = 0 ... ... @@ -224,10 +224,6 @@ 224 224 225 225 This example shows how to use the Twilio API to send WhatsApp message to private number. When monitoring bit "@testBit" changes, it will trigger and send the message. Please replace with your own SID, Token, twilioPhoneNumber and receiverPhoneNumber. 226 226 227 -About how to register the Twilio API, please check the following video: 228 - 229 -[[https:~~/~~/www.youtube.com/watch?v=Id4lKichauU>>https://www.youtube.com/watch?v=Id4lKichauU]] 230 - 231 231 {{code language="Lua"}} 232 232 local tempBit = 0 233 233 local tempWord = 0 ... ... @@ -236,8 +236,8 @@ 236 236 local json = require("json") 237 237 local ltn12 = require("ltn12") 238 238 239 -local SID = 'AC1703bd710ffa98006d2bcc0b ********'240 -local Token = 'd3c11897623c39e538b20263ec19 ****'229 +local SID = 'AC1703bd710ffa98006d2bcc0b8d6ca63a' 230 +local Token = 'd3c11897623c39e538b20263ec190ae0' 241 241 242 242 local twilioPhoneNumber = '+14155238886' 243 243 local receiverPhoneNumber = '+8615880018277' ... ... @@ -501,134 +501,142 @@ 501 501 -- Meta class 502 502 --main 503 503 function mq.main() 504 - 505 - 494 + if not mq.m then 495 + local err = "" 506 506 507 - mq.m, err = mqtt.create("tcp://grouprobotinfo.com:1883", "ClienID") -- create connection 508 - if mq.m then 509 - mq.config = { 510 - username = "",-- ID 511 - password = "",-- password 512 - netway = 1, -- Ethernet connection, WIFI=1 513 - -- keepalive = 100, -- Optional, set the connection heartbeat interval for 100 seconds. 514 - -- cleansession = 0, -- Optional, keep session 515 - } 516 - mq.m:on("message", function(topic, msg) -- Register for receiving message callbacks 517 - local str = string.format("%s:%s", topic, msg) 518 - -- print("mqtt msg:", str) -- Print out the received topics and content 519 - end) 520 - mq.m:on("offline", function (cause) -- Register for lost connection callbacks 521 - -- addr_setstring("@xxx", "cause"..(cause or " got nil")) 522 - end) 523 - mq.m:on("arrived", function() -- Registration for sending messages to callbacks 524 - print("msg arrived") 525 - end) 526 - else 527 - print("mqtt create failed:", err) -- Create object failed 528 - end 529 - else 530 - if mq.m:isconnected() then -- If online, post a message 531 - local phaseStatus ="unknow" 532 - if addr_getbit("@Standby")== 1 then 533 - phaseStatus = "Standby" 534 - elseif addr_getbit("@Pre-Freeze")==1 then 535 - phaseStatus= "Pre-Freeze" 536 - elseif addr_getbit("@Prepare")==1 then 537 - phaseStatus ="Prepare" 538 - elseif addr_getbit("@Primary Dry")==1 then 539 - phaseStatus = "Primary dry" 540 - elseif addr_getbit("@Secondary Dry")==1 then 541 - phaseStatus = "Secondary Dry" 542 - end 543 - --print(addr_getbit("@Primary Dry")) 497 + mq.m, err = mqtt.create("tcp://grouprobotinfo.com:1883", "ClienID") -- create connection 498 + if mq.m then 499 + mq.config = { 500 + username = "",-- ID 501 + password = "",-- password 502 + netway = 1, -- Ethernet connection, WIFI=1 503 + -- keepalive = 100, -- Optional, set the connection heartbeat interval for 100 seconds. 504 + -- cleansession = 0, -- Optional, keep session 505 + } 506 + mq.m:on("message", function(topic, msg) -- Register for receiving message callbacks 507 + local str = string.format("%s:%s", topic, msg) 508 + -- print("mqtt msg:", str) -- Print out the received topics and content 509 + end 510 + ) 511 + mq.m:on("offline", function (cause) -- Register for lost connection callbacks 512 + -- addr_setstring("@xxx", "cause"..(cause or " got nil")) 513 + end) 514 + mq.m:on("arrived", function() -- Registration for sending messages to callbacks 515 + print("msg arrived") 516 + end) 517 + else 518 + print("mqtt create failed:", err) -- Create object failed 519 + end 520 + else 521 + if mq.m:isconnected() then -- If online, post a message 522 + local phaseStatus ="unknow" 523 + if addr_getbit("@Standby")== 1 then 524 + phaseStatus = "Standby" 525 + elseif addr_getbit("@Pre-Freeze")==1 then 526 + phaseStatus= "Pre-Freeze" 527 + elseif addr_getbit("@Prepare")==1 then 528 + phaseStatus ="Prepare" 529 + elseif addr_getbit("@Primary Dry")==1 then 530 + phaseStatus = "Primary dry" 531 + elseif addr_getbit("@Secondary Dry")==1 then 532 + phaseStatus = "Secondary Dry" 533 + end 534 +-- print(addr_getbit("@Primary Dry")) 544 544 ------------------------------------------------------------------------------------------------------------------------- 545 - local activating ="unknow" 546 - if addr_getbit("@Compressor")==1 then 547 - activating = ",".."Compressor" 548 - end 549 - if addr_getbit("@Silicone Pump")==1 then 550 - activating = activating..",".."Silicone Pump" 551 - end 552 - if addr_getbit("@Vacuum Pump")==1 then 553 - activating = activating..",".."Vacuum Pump" 554 - end 555 - if addr_getbit("@Root Pump")==1 then 556 - activating = activating..",".."Root Pump" 557 - end 558 - if addr_getbit("@Heater")==1 then 559 - activating = activating..",".."Heater" 560 - end 561 - if addr_getbit("@Valve Silicone")==1 then 562 - activating = activating..",".."Valve Silicone" 563 - end 564 - if addr_getbit("@Valve Ice Condenser")==1 then 565 - activating = activating..",".."Valve Ice Condenser" 566 - end 567 - if addr_getbit("@Valve Vacuum Pump")==1 then 568 - activating = activating..",".."Valve Vacuum Pump" 569 - end 570 - local pr_activating =string.sub(activating,2) 571 - -- print(pr_activating) 572 - local status_text ="unknow" 573 - if addr_getbit("@Status Run")==1 then 574 - status_text = "RUNNING" 575 - else 576 - status_text = "STOP" 577 - end 578 -------------------------------------------------------------------------------------------------------------------------- 579 - local js = {type="status", 580 - mc_name ="FD300", 581 - status=status_text, 582 - elapsed_time={ 583 - hour=addr_getword("@Elapsed Time (Hour)"), 584 - min=addr_getword("@Elapsed Time (Minute)"), 585 - sec=addr_getword("@Elapsed Time (Second)") 586 - }, 587 - phase = phaseStatus, 588 - step = addr_getword("@Step"), 589 - activating_output = pr_activating, 590 - sv=addr_getshort("@SV Silicone")/10, 591 - pv=addr_getshort("@PV Silicone")/10, 592 - product1=addr_getshort("@Product 1")/10, 536 + local activating ="unknow" 537 + if addr_getbit("@Compressor")==1 then 538 + activating = ",".."Compressor" 539 + end 540 + if addr_getbit("@Silicone Pump")==1 then 541 + activating = activating..",".."Silicone Pump" 542 + end 543 + if addr_getbit("@Vacuum Pump")==1 then 544 + activating = activating..",".."Vacuum Pump" 545 + end 546 + if addr_getbit("@Root Pump")==1 then 547 + activating = activating..",".."Root Pump" 548 + end 549 + if addr_getbit("@Heater")==1 then 550 + activating = activating..",".."Heater" 551 + end 552 + if addr_getbit("@Valve Silicone")==1 then 553 + activating = activating..",".."Valve Silicone" 554 + end 555 + if addr_getbit("@Valve Ice Condenser")==1 then 556 + activating = activating..",".."Valve Ice Condenser" 557 + end 558 + if addr_getbit("@Valve Vacuum Pump")==1 then 559 + activating = activating..",".."Valve Vacuum Pump" 560 + end 561 + local pr_activating =string.sub(activating,2) 562 + -- print(pr_activating) 593 593 594 - product2=addr_getshort("@Product 2")/10, 595 - product3=addr_getshort("@Product 3")/10, 596 - product4=addr_getshort("@Product 4")/10, 597 - ice1=addr_getshort("@Ice condenser 1")/10, 598 - ice2=addr_getshort("@Ice condenser 2")/10, 599 - vacuum=addr_getfloat("@Vacuum") 600 - } 601 - local jsAlarm = { HPC = addr_getbit("@B_25395#W0.00"), 602 - ODPC = addr_getbit("@B_25395#W0.01"), 603 - MTPC=addr_getbit("@B_25395#W0.02"), 604 - HTT = addr_getbit("@B_25395#W1.03"), 605 - CPC = addr_getbit("@B_25395#W0.08"), 606 - CPSP =addr_getbit("@B_25395#W1.00"), 607 - CPVP =addr_getbit("@B_25395#W0.10"), 608 - CPRP =addr_getbit("@B_25395#W0.11"), 609 - HP =addr_getbit("@B_25395#W1.01"), 610 - PP= addr_getbit("@B_25395#W1.02"), 611 - PO=addr_getbit("@B_25395#W0.07"), 612 - FSE=addr_getbit("@B_25395#W2.04"), 613 - AVVSVV=addr_getbit("@B_25395#W1.12"), 614 - ICHT=addr_getbit("@B_25395#W3.06") 615 - } 616 - -- ("@B_25395#CIO1.02") 617 - mq.m:publish("mqtt-v-box-epsilon-fd300", json.encode(js) , 0, 0) 618 - mq.m:publish("mqtt-v-box-epsilon-alarm-fd300", json.encode(jsAlarm) , 0, 0) 619 - else 620 - local stat, err = mq.m:connect(mq.config) -- connection 621 - if stat == nil then --Determine whether to connect 622 - print("mqtt connect failed:", err) 623 - return -- Connection failed, return directly 624 - end 625 - mq.m:subscribe("mqtt-v-box-epsilon", 0)-- Subscribe to topics 626 626 627 - end 628 - -- mq.m:unsubscribe("stc/test") 629 - -- mq.m:disconnect() -- close matt 630 - -- mq.m:close() -- close clase 631 - end 565 + 566 + local status_text ="unknow" 567 + if addr_getbit("@Status Run")==1 then 568 + status_text = "RUNNING" 569 + else 570 + status_text = "STOP" 571 + end 572 +------------------------------------------------------------------------------------------------------------------------- 573 + 574 + local js = {type="status", 575 + mc_name ="FD300", 576 + status=status_text, 577 + elapsed_time={ 578 + hour=addr_getword("@Elapsed Time (Hour)"), 579 + min=addr_getword("@Elapsed Time (Minute)"), 580 + sec=addr_getword("@Elapsed Time (Second)") 581 + }, 582 + phase = phaseStatus, 583 + step = addr_getword("@Step"), 584 + activating_output = pr_activating, 585 + sv=addr_getshort("@SV Silicone")/10, 586 + pv=addr_getshort("@PV Silicone")/10, 587 + product1=addr_getshort("@Product 1")/10, 588 + 589 + product2=addr_getshort("@Product 2")/10, 590 + product3=addr_getshort("@Product 3")/10, 591 + product4=addr_getshort("@Product 4")/10, 592 + ice1=addr_getshort("@Ice condenser 1")/10, 593 + ice2=addr_getshort("@Ice condenser 2")/10, 594 + vacuum=addr_getfloat("@Vacuum") 595 + 596 + } 597 + local jsAlarm = { HPC = addr_getbit("@B_25395#W0.00"), 598 + ODPC = addr_getbit("@B_25395#W0.01"), 599 + MTPC=addr_getbit("@B_25395#W0.02"), 600 + HTT = addr_getbit("@B_25395#W1.03"), 601 + CPC = addr_getbit("@B_25395#W0.08"), 602 + CPSP =addr_getbit("@B_25395#W1.00"), 603 + CPVP =addr_getbit("@B_25395#W0.10"), 604 + CPRP =addr_getbit("@B_25395#W0.11"), 605 + HP =addr_getbit("@B_25395#W1.01"), 606 + PP= addr_getbit("@B_25395#W1.02"), 607 + PO=addr_getbit("@B_25395#W0.07"), 608 + FSE=addr_getbit("@B_25395#W2.04"), 609 + AVVSVV=addr_getbit("@B_25395#W1.12"), 610 + ICHT=addr_getbit("@B_25395#W3.06") 611 + 612 + } 613 + 614 + -- ("@B_25395#CIO1.02") 615 + mq.m:publish("mqtt-v-box-epsilon-fd300", json.encode(js) , 0, 0) 616 + mq.m:publish("mqtt-v-box-epsilon-alarm-fd300", json.encode(jsAlarm) , 0, 0) 617 + else 618 + local stat, err = mq.m:connect(mq.config) -- connection 619 + if stat == nil then --Determine whether to connect 620 + print("mqtt connect failed:", err) 621 + return -- Connection failed, return directly 622 + end 623 + mq.m:subscribe("mqtt-v-box-epsilon", 0)-- Subscribe to topics 624 + 625 + end 626 + -- mq.m:unsubscribe("stc/test") 627 + -- mq.m:disconnect() -- close matt 628 + -- mq.m:close() -- close clase 629 + end 632 632 end 633 633 {{/code}} 634 634