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
-
... ... @@ -501,142 +501,134 @@ 501 501 -- Meta class 502 502 --main 503 503 function mq.main() 504 - 505 - 504 + if not mq.m then 505 + 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 - ) 521 - mq.m:on("offline", function (cause) -- Register for lost connection callbacks 522 - -- addr_setstring("@xxx", "cause"..(cause or " got nil")) 523 - end) 524 - mq.m:on("arrived", function() -- Registration for sending messages to callbacks 525 - print("msg arrived") 526 - end) 527 - else 528 - print("mqtt create failed:", err) -- Create object failed 529 - end 530 - else 531 - if mq.m:isconnected() then -- If online, post a message 532 - local phaseStatus ="unknow" 533 - if addr_getbit("@Standby")== 1 then 534 - phaseStatus = "Standby" 535 - elseif addr_getbit("@Pre-Freeze")==1 then 536 - phaseStatus= "Pre-Freeze" 537 - elseif addr_getbit("@Prepare")==1 then 538 - phaseStatus ="Prepare" 539 - elseif addr_getbit("@Primary Dry")==1 then 540 - phaseStatus = "Primary dry" 541 - elseif addr_getbit("@Secondary Dry")==1 then 542 - phaseStatus = "Secondary Dry" 543 - end 544 --- 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")) 545 545 ------------------------------------------------------------------------------------------------------------------------- 546 - local activating ="unknow" 547 - if addr_getbit("@Compressor")==1 then 548 - activating = ",".."Compressor" 549 - end 550 - if addr_getbit("@Silicone Pump")==1 then 551 - activating = activating..",".."Silicone Pump" 552 - end 553 - if addr_getbit("@Vacuum Pump")==1 then 554 - activating = activating..",".."Vacuum Pump" 555 - end 556 - if addr_getbit("@Root Pump")==1 then 557 - activating = activating..",".."Root Pump" 558 - end 559 - if addr_getbit("@Heater")==1 then 560 - activating = activating..",".."Heater" 561 - end 562 - if addr_getbit("@Valve Silicone")==1 then 563 - activating = activating..",".."Valve Silicone" 564 - end 565 - if addr_getbit("@Valve Ice Condenser")==1 then 566 - activating = activating..",".."Valve Ice Condenser" 567 - end 568 - if addr_getbit("@Valve Vacuum Pump")==1 then 569 - activating = activating..",".."Valve Vacuum Pump" 570 - end 571 - local pr_activating =string.sub(activating,2) 572 - -- 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, 573 573 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 574 574 575 - 576 - local status_text ="unknow" 577 - if addr_getbit("@Status Run")==1 then 578 - status_text = "RUNNING" 579 - else 580 - status_text = "STOP" 581 - end 582 -------------------------------------------------------------------------------------------------------------------------- 583 - 584 - local js = {type="status", 585 - mc_name ="FD300", 586 - status=status_text, 587 - elapsed_time={ 588 - hour=addr_getword("@Elapsed Time (Hour)"), 589 - min=addr_getword("@Elapsed Time (Minute)"), 590 - sec=addr_getword("@Elapsed Time (Second)") 591 - }, 592 - phase = phaseStatus, 593 - step = addr_getword("@Step"), 594 - activating_output = pr_activating, 595 - sv=addr_getshort("@SV Silicone")/10, 596 - pv=addr_getshort("@PV Silicone")/10, 597 - product1=addr_getshort("@Product 1")/10, 598 - 599 - product2=addr_getshort("@Product 2")/10, 600 - product3=addr_getshort("@Product 3")/10, 601 - product4=addr_getshort("@Product 4")/10, 602 - ice1=addr_getshort("@Ice condenser 1")/10, 603 - ice2=addr_getshort("@Ice condenser 2")/10, 604 - vacuum=addr_getfloat("@Vacuum") 605 - 606 - } 607 - local jsAlarm = { HPC = addr_getbit("@B_25395#W0.00"), 608 - ODPC = addr_getbit("@B_25395#W0.01"), 609 - MTPC=addr_getbit("@B_25395#W0.02"), 610 - HTT = addr_getbit("@B_25395#W1.03"), 611 - CPC = addr_getbit("@B_25395#W0.08"), 612 - CPSP =addr_getbit("@B_25395#W1.00"), 613 - CPVP =addr_getbit("@B_25395#W0.10"), 614 - CPRP =addr_getbit("@B_25395#W0.11"), 615 - HP =addr_getbit("@B_25395#W1.01"), 616 - PP= addr_getbit("@B_25395#W1.02"), 617 - PO=addr_getbit("@B_25395#W0.07"), 618 - FSE=addr_getbit("@B_25395#W2.04"), 619 - AVVSVV=addr_getbit("@B_25395#W1.12"), 620 - ICHT=addr_getbit("@B_25395#W3.06") 621 - 622 - } 623 - 624 - -- ("@B_25395#CIO1.02") 625 - mq.m:publish("mqtt-v-box-epsilon-fd300", json.encode(js) , 0, 0) 626 - mq.m:publish("mqtt-v-box-epsilon-alarm-fd300", json.encode(jsAlarm) , 0, 0) 627 - else 628 - local stat, err = mq.m:connect(mq.config) -- connection 629 - if stat == nil then --Determine whether to connect 630 - print("mqtt connect failed:", err) 631 - return -- Connection failed, return directly 632 - end 633 - mq.m:subscribe("mqtt-v-box-epsilon", 0)-- Subscribe to topics 634 - 635 - end 636 - -- mq.m:unsubscribe("stc/test") 637 - -- mq.m:disconnect() -- close matt 638 - -- mq.m:close() -- close clase 639 - end 627 + end 628 + -- mq.m:unsubscribe("stc/test") 629 + -- mq.m:disconnect() -- close matt 630 + -- mq.m:close() -- close clase 631 + end 640 640 end 641 641 {{/code}} 642 642