Changes for page 2 Script

Last modified by Devin Chen on 2025/06/06 14:03

From version 26.1
edited by Hunter
on 2022/10/25 09:36
Change comment: There is no comment for this version
To version 28.1
edited by Hunter
on 2022/11/21 17:01
Change comment: There is no comment for this version

Summary

Details

Page properties
Content
... ... @@ -224,6 +224,10 @@
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 +
227 227  {{code language="Lua"}}
228 228  local tempBit = 0
229 229  local tempWord = 0
... ... @@ -497,142 +497,134 @@
497 497  -- Meta class
498 498  --main
499 499  function mq.main()
500 - if not mq.m then
501 -  local err = ""
504 + if not mq.m then
505 + local err = ""
502 502  
503 -  mq.m, err = mqtt.create("tcp://grouprobotinfo.com:1883", "ClienID")  -- create connection
504 -  if mq.m then
505 -   mq.config = {
506 -    username = "",-- ID
507 -    password = "",-- password
508 -    netway = 1, -- Ethernet connection, WIFI=1
509 -    -- keepalive = 100, -- Optional, set the connection heartbeat interval for 100 seconds.
510 -    -- cleansession = 0, -- Optional, keep session
511 -   }
512 -   mq.m:on("message", function(topic, msg) -- Register for receiving message callbacks
513 -    local str = string.format("%s:%s", topic, msg)
514 -    -- print("mqtt msg:", str) -- Print out the received topics and content
515 -   end
516 -   )
517 -   mq.m:on("offline", function (cause) -- Register for lost connection callbacks
518 -    -- addr_setstring("@xxx", "cause"..(cause or " got nil"))
519 -   end)
520 -   mq.m:on("arrived", function() -- Registration for sending messages to callbacks 
521 -    print("msg arrived")
522 -   end)
523 -  else
524 -   print("mqtt create failed:", err) -- Create object failed
525 -  end
526 - else
527 -  if mq.m:isconnected() then -- If online, post a message
528 -     local phaseStatus ="unknow"
529 -     if addr_getbit("@Standby")== 1 then
530 -         phaseStatus = "Standby"
531 -     elseif addr_getbit("@Pre-Freeze")==1 then
532 -         phaseStatus= "Pre-Freeze"
533 -     elseif addr_getbit("@Prepare")==1 then
534 -         phaseStatus ="Prepare"
535 -     elseif addr_getbit("@Primary Dry")==1 then
536 -         phaseStatus = "Primary dry"
537 -     elseif addr_getbit("@Secondary Dry")==1 then
538 -         phaseStatus = "Secondary Dry"
539 -     end
540 ---   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"))
541 541  -------------------------------------------------------------------------------------------------------------------------
542 -     local activating ="unknow"
543 -     if addr_getbit("@Compressor")==1 then
544 -         activating = ",".."Compressor"
545 -     end
546 -     if addr_getbit("@Silicone Pump")==1 then
547 -         activating = activating..",".."Silicone Pump"
548 -     end
549 -     if addr_getbit("@Vacuum Pump")==1 then
550 -         activating = activating..",".."Vacuum Pump"
551 -     end
552 -     if addr_getbit("@Root Pump")==1 then
553 -         activating = activating..",".."Root Pump"
554 -     end
555 -     if addr_getbit("@Heater")==1 then
556 -         activating = activating..",".."Heater"
557 -     end
558 -     if addr_getbit("@Valve Silicone")==1 then
559 -         activating = activating..",".."Valve Silicone"
560 -     end
561 -     if addr_getbit("@Valve Ice Condenser")==1 then
562 -         activating = activating..",".."Valve Ice Condenser"
563 -     end
564 -     if addr_getbit("@Valve Vacuum Pump")==1 then
565 -         activating = activating..",".."Valve Vacuum Pump"
566 -     end
567 -     local pr_activating =string.sub(activating,2)
568 -    --  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,
569 569  
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
570 570  
571 -
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 -
580 -     local js =  {type="status",
581 -                  mc_name ="FD300",
582 -                  status=status_text,
583 -                  elapsed_time={
584 -                                hour=addr_getword("@Elapsed Time (Hour)"),
585 -                                min=addr_getword("@Elapsed Time (Minute)"),
586 -                                sec=addr_getword("@Elapsed Time (Second)")
587 -                                },
588 -                   phase = phaseStatus,
589 -                   step = addr_getword("@Step"),
590 -                   activating_output = pr_activating,
591 -                   sv=addr_getshort("@SV Silicone")/10,
592 -                   pv=addr_getshort("@PV Silicone")/10,
593 -                   product1=addr_getshort("@Product 1")/10,
594 -
595 -                   product2=addr_getshort("@Product 2")/10,
596 -                   product3=addr_getshort("@Product 3")/10,
597 -                   product4=addr_getshort("@Product 4")/10,
598 -                   ice1=addr_getshort("@Ice condenser 1")/10,
599 -                   ice2=addr_getshort("@Ice condenser 2")/10,
600 -                   vacuum=addr_getfloat("@Vacuum")
601 -
602 -                }
603 -     local jsAlarm = {  HPC = addr_getbit("@B_25395#W0.00"),
604 -                        ODPC = addr_getbit("@B_25395#W0.01"),
605 -                        MTPC=addr_getbit("@B_25395#W0.02"),
606 -                        HTT = addr_getbit("@B_25395#W1.03"),
607 -                        CPC = addr_getbit("@B_25395#W0.08"),
608 -                        CPSP =addr_getbit("@B_25395#W1.00"),
609 -                        CPVP =addr_getbit("@B_25395#W0.10"),
610 -                        CPRP =addr_getbit("@B_25395#W0.11"),
611 -                        HP =addr_getbit("@B_25395#W1.01"),
612 -                        PP= addr_getbit("@B_25395#W1.02"),
613 -                        PO=addr_getbit("@B_25395#W0.07"),
614 -                        FSE=addr_getbit("@B_25395#W2.04"),
615 -                        AVVSVV=addr_getbit("@B_25395#W1.12"),
616 -                        ICHT=addr_getbit("@B_25395#W3.06")
617 -
618 -                }
619 -
620 -    -- ("@B_25395#CIO1.02")
621 -     mq.m:publish("mqtt-v-box-epsilon-fd300", json.encode(js) , 0, 0)
622 -     mq.m:publish("mqtt-v-box-epsilon-alarm-fd300", json.encode(jsAlarm) , 0, 0)
623 -  else
624 -   local stat, err = mq.m:connect(mq.config) -- connection
625 -   if stat == nil then --Determine whether to connect
626 -    print("mqtt connect failed:", err)
627 -    return -- Connection failed, return directly
628 -   end
629 -   mq.m:subscribe("mqtt-v-box-epsilon", 0)-- Subscribe to topics
630 -
631 -  end
632 -  -- mq.m:unsubscribe("stc/test")
633 -  -- mq.m:disconnect() -- close matt
634 -  -- mq.m:close() -- close clase
635 - end
627 + end
628 + -- mq.m:unsubscribe("stc/test")
629 + -- mq.m:disconnect() -- close matt
630 + -- mq.m:close() -- close clase
631 + end
636 636  end
637 637  {{/code}}
638 638