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,6 +70,12 @@ 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 + 73 73 {{code language="Lua"}} 74 74 local tempBit = 0 75 75 local tempWord = 0 ... ... @@ -218,6 +218,10 @@ 218 218 219 219 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. 220 220 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 + 221 221 {{code language="Lua"}} 222 222 local tempBit = 0 223 223 local tempWord = 0 ... ... @@ -491,142 +491,134 @@ 491 491 -- Meta class 492 492 --main 493 493 function mq.main() 494 - 495 - 504 + if not mq.m then 505 + local err = "" 496 496 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")) 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")) 535 535 ------------------------------------------------------------------------------------------------------------------------- 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) 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, 563 563 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 564 564 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 627 + end 628 + -- mq.m:unsubscribe("stc/test") 629 + -- mq.m:disconnect() -- close matt 630 + -- mq.m:close() -- close clase 631 + end 630 630 end 631 631 {{/code}} 632 632