Changes for page 05 Lua Script

Last modified by Hunter on 2026/10/21 11:55

From version 28.8
edited by Hunter
on 2026/10/21 10:32
Change comment: There is no comment for this version
To version 2.1
edited by Joe
on 2025/10/24 15:58
Change comment: There is no comment for this version

Summary

Details

Page properties
Author
... ... @@ -1,1 +1,1 @@
1 -XWiki.Hunter
1 +XWiki.joe
Content
... ... @@ -48,32 +48,29 @@
48 48  (% style="text-align:center" %)
49 49  [[image:dZyxVCtWDz.png]]
50 50  
51 -(% class="box infomessage" %)
52 -(((
53 -Note:About how to set up the FTP server in Windows PC: **[[How to set up and manage an FTP server on Windows 10>>https://www.windowscentral.com/how-set-and-manage-ftp-server-windows-10]]**
54 -)))
51 +~1. About how to set up the FTP server in Windows PC: **[[Build an FTP Site on IIS>>https://docs.microsoft.com/en-us/iis/publish/using-the-ftp-service/scenario-build-an-ftp-site-on-iis]] **,** [[How to set up and manage an FTP server on Windows 10>>https://www.windowscentral.com/how-set-and-manage-ftp-server-windows-10]]**
55 55  
56 -1.Enter PC (FTP Server) IP address and port number (Default 21).
53 +2. Enter PC (FTP Server) IP address and port number (Default 21).
57 57  
58 58  (% style="text-align:center" %)
59 59  [[image:LuaFTPDemoIP&Port.png]]
60 60  
61 -2.Change the filename of the file that needs to be uploaded. If run on as Offline Simulator, the simulate upload path of "udisk:1.png" will be "C:\WECON\USB\1.png" on the PC.
58 +3. Change the filename of the file that needs to be uploaded. If run on as Offline Simulator, the simulate upload path of "udisk:1.png" will be "C:\WECON\USB\1.png" on the PC.
62 62  
63 63  (% style="text-align:center" %)
64 64  [[image:LuaFTPDemoUpload.png]]
65 65  
66 -3.Change drive letter of file save path according to drop-down list (There are three option available: Flash, UDisk and SDCard).
63 +4. Change drive letter of file save path according to drop-down list (There are three option available: Flash, UDisk and SDCard).
67 67  
68 68  (% style="text-align:center" %)
69 69  [[image:LuaFTPDemoDropBox.png]]
70 70  
71 -4.Change the filename of the file that needs to be downloaded from PC(Server).
68 +5. Change the filename of the file that needs to be downloaded from PC(Server).
72 72  
73 73  (% style="text-align:center" %)
74 74  [[image:LuaFTPDemoDownload.png]]
75 75  
76 -5.Set the default configuration in file "Script_BG.lua"
73 +6. Set the default configuration in file "Script_BG.lua"
77 77  
78 78  (% style="text-align:center" %)
79 79  [[image:LuaFTPDemoInitial.png]]
... ... @@ -126,9 +126,6 @@
126 126  
127 127  [[Download link>>https://ftp.we-con.com.cn/Download/WIKI/PI%20HMI/Demo/Lua%20Script/Telegram.zip]]
128 128  
129 -
130 -[[URL Encode Table for Special Characters>>https://docs.we-con.com.cn/bin/view/PIStudio/FAQ/Why%20can't%20I%20receive%20HMI%20messages%20on%20Telegram]]
131 -
132 132  = 9** LINE Notify(Not available now)** =
133 133  
134 134  This example shows how to use the LINE Notify to send message into LINE group. When monitoring bit "@B_HDX0.0" changes, it will trigger and send the message. Please replace with your own Token.
... ... @@ -702,198 +702,6 @@
702 702  (% style="text-align:center" %)
703 703  [[image:xT8f08pfY0.png]]
704 704  
705 -= 26 Send attachment picture with SMTP by Gmail =
699 += [[26. Send attachment picture with SMTP by Gmail>>https://ftp.we-con.com.cn/Download/WIKI/PI%20HMI/Demo/Lua%20Script/SMTP%20for%20Gmail%28with%20Attachment%20picture%20%29.zip]] =
706 706  
707 707  The project is to send mail message with text and attachment picture called test.png.
708 -
709 -[[Download link>>https://ftp.we-con.com.cn/Download/WIKI/PI%20HMI/Demo/Lua%20Script/SMTP%20for%20Gmail%28with%20Attachment%20picture%20%29.zip]]
710 -
711 -= 27 TTS function =
712 -
713 -The project is to show a Music Player and alarm sound with TTS function in Lua script. Please note that  use PI version 10.4 or higher to open the project.
714 -
715 -[[Download link>>https://ftp.we-con.com.cn/Download/WIKI/PI%20HMI/Demo/Lua%20Script/Music%20player.pi2]]
716 -
717 -= 28 Google Sheets API =
718 -
719 -The example shows how to send the data into the Google sheets API via Lua script. [[Jump to Video>>https://youtu.be/VKjr3_MVNzc]]
720 -
721 -{{warning}}
722 -since the HMI lacks a built-in library for cryptographic signatures (RS256/JWT), user can automate this by sending the token to the HMI via external communication. Token need to be manual input in this project.
723 -{{/warning}}
724 -
725 -[[Download link>>https://ftp.we-con.com.cn/Download/WIKI/PI%20HMI/Demo/Lua%20Script/GoogleSheet.zip]]
726 -
727 -= 29 Graphics Drawing =
728 -
729 -The example shows drawing a snow and a star on the HMI screen with drawing function from Lua Script.Please note that  use PI version 10.6 or higher to open the project.
730 -[[Download link>>https://ftp.we-con.com.cn/Download/WIKI/PI%20HMI/Demo/Lua%20Script/Graphics%20Drawing.pi2]]
731 -
732 -
733 -= 30 Timestamp =
734 -
735 -This example shows how to obtain second-level and millisecond-level timestamps.
736 -[[Download link>>https://ftp.we-con.com.cn/Download/WIKI/PI%20HMI/Demo/Lua%20Script/Timestamp.zip]]
737 -
738 -
739 -= 31 Sending CSV file with Gmail =
740 -
741 -This example shows how to send CSV file transferred by DB file with Gmail. Please note that  use PI version 10.6 or higher to open the project.
742 -[[Download link>>https://ftp.we-con.com.cn/Download/WIKI/PI%20HMI/Demo/Lua%20Script/Sending%20CSV%20file%20with%20Gmail.zip]]
743 -
744 -
745 -= 32 GPS Function =
746 -
747 -This example shows how to get the GPS data from device (Support RH-AG). Please note that  use PI version 11.4.64.26081301 or higher to open the project.
748 -
749 -[[Download link>>https://ftp.we-con.com.cn/Download/WIKI/PI%20HMI/Demo/Lua%20Script/GPS%20function.zip]]
750 -
751 -
752 -= **33 Data record query** =
753 -
754 -This example shows how to obtain data records for a certain time period and display them at an address. Please note that  use PI version 10.6.45.26070101 or higher to open the project.
755 -[[Download link>>https://ftp.we-con.com.cn/Download/WIKI/PI%20HMI/Demo/Lua%20Script/Data%20record%20query.zip]]
756 -
757 -
758 -= 34 Ethernet A4 Printer =
759 -
760 -This example shows how to print A4 report paper directly from an HMI via TCP/IP, which is not required any PC software tool. [[Jump to Video>>https://youtu.be/IZoOoRefJc8]]
761 -
762 -{{warning}}
763 -Please prioritize printers that support **PCL5**.
764 -{{/warning}}
765 -
766 -**Common PCL5 Commands**
767 -
768 -{{code language="lua"}}
769 ---Set text position and content
770 -local sample = "\x1B*p1000x1000YHelloWorld"
771 -{{/code}}
772 -
773 -{{code language="lua"}}
774 --- Set font size to 12 pt
775 -local fontSize = "\x1B(s12V"
776 -{{/code}}
777 -
778 -{{code language="lua"}}
779 --- Set print direction to 0 degrees
780 -local direction = "\x1B&a0P"
781 -{{/code}}
782 -
783 -{{code language="lua"}}
784 ---Restore default drawing logic
785 -local defaultLogic = "\x1B*l252O"
786 -{{/code}}
787 -
788 -{{code language="lua"}}
789 ---New page feed output
790 -local formFeed = "\x0C"
791 -{{/code}}
792 -
793 -[[Download link>>https://ftp.we-con.com.cn/Download/WIKI/PI%20HMI/Demo/Lua%20Script/PrinterTCPSocket.zip]]
794 -
795 -= 35 SFTP Client(PI 11.4) =
796 -
797 -This example shows how to set up the SSH connection between HMI and server, and upload or download the file. **This function only works on PIStudio version 11.4 or above and PI8000ig or PI9000ig HMI.**
798 -
799 -{{info}}
800 -Refer to the Microsoft official guide for installing and enabling OpenSSH Server on Windows using PowerShell: [[Get started with OpenSSH Server for Windows ~| Microsoft Learn>>https://learn.microsoft.com/en-us/windows-server/administration/openssh/openssh_install_firstuse?tabs=gui&pivots=windows-server-2025]]
801 -
802 -**Make sure TCP port 22 is not occupied by another SSH server, such as Bitvise SSH Server.**
803 -{{/info}}
804 -
805 -~1. Run PowerShell as administrator. Enter Get-Service sshd in the PowerShell window. If the status is Stopped, enter Start-Service sshd to start the service.
806 -
807 -{{code language="powershell"}}
808 -Get-Service sshd
809 -Start-Service sshd
810 -{{/code}}
811 -
812 -(% style="text-align:center" %)
813 -[[image:checkstatusSSH.png]]
814 -
815 -{{info}}
816 -If the SSH connection cannot be established, check and adjust the firewall’s inbound and outbound rules. Enter following command in powershell
817 -{{/info}}
818 -
819 -{{code language="powershell"}}
820 -netsh advfirewall set allprofiles state off
821 -{{/code}}
822 -
823 -2. Change the server IP, username and password.
824 -
825 -(% style="text-align:center" %)
826 -[[image:SSH1.png]]
827 -
828 -2. Change the server file path and HMI file path as user wanted.
829 -
830 -(% style="text-align:center" %)
831 -[[image:E2.png]]
832 -
833 -3. Click the Copy to copy the file into flash(user:) path from the pen drive path, then click SFTP connect, click Upload or Download button.
834 -
835 -{{warning}}
836 -File operations are only supported under the "user:" path for the moment.
837 -{{/warning}}
838 -
839 -(% style="text-align:center" %)
840 -[[image:sf.png]]
841 -
842 -4. Check the file whether download or upload successfully.
843 -
844 -(% style="text-align:center" %)
845 -[[image:8217Wc3rju.png]]
846 -
847 -[[Download link>>https://ftp.we-con.com.cn/Download/WIKI/PI%20HMI/Demo/Lua%20Script/SFTP%20Client.zip]]
848 -
849 -= 36 Wechat Official Account Notification Push =
850 -
851 -This example shows how to set up the Wechat official account sandbox to test the alarm push.
852 -
853 -[[Wechat Official Platform Sandbox>>https://mp.weixin.qq.com/debug/cgi-bin/sandboxinfo?action=showinfo&t=sandbox/index]]
854 -
855 -To register a formal WeChat Official Account, please forward to:
856 -
857 -[[Weixin Official Accounts Platform>>url:https://mp.weixin.qq.com/]]
858 -
859 -~1. Login into the platform, and user can see the appID and appSecret, copy them for the further use.
860 -
861 -(% style="text-align:center" %)
862 -[[image:wechataccount.png]]
863 -
864 -2. User can scan the QR code on the left side to subscribe push notifications. And copy the Wechat ID.
865 -
866 -(% style="text-align:center" %)
867 -[[image:wechatID.png]]
868 -
869 -3. Click [Add test template] to create a new notification template.
870 -
871 -(% style="text-align:center" %)
872 -[[image:wechatTempalte.png]]
873 -
874 -4. Enter the title and content, then click submission, the content must follow this format: text: ~{~{text.DATA}}
875 -
876 -For example, use Alarm: ~{~{Alarm.DATA}}. For multiple lines, format the content as follows:
877 -
878 -{{code language="lua"}}
879 -Device: {{Device.DATA}}
880 -Alarm: {{Alarm.DATA}}
881 -Time: {{Time.DATA}}
882 -{{/code}}
883 -
884 -(% style="text-align:center" %)
885 -[[image:wechatTempalteConten2.png]]
886 -
887 -5. After the template is created, copy the template ID.
888 -
889 -(% style="text-align:center" %)
890 -[[image:wechatCopyTempalte.png]]
891 -
892 -6. Paste all these IDs(appID, appSecret, wechatID and templateID) into the lua script.
893 -
894 -(% style="text-align:center" %)
895 -[[image:wechatscriptcopyID.png]]
896 -
897 -7. The demo script is
898 -
899 -[[Download link>>https://ftp.we-con.com.cn/Download/WIKI/PI%20HMI/Demo/Lua%20Script/WechatOfficialAccount.zip]]
1792547572135-677.png
Author
... ... @@ -1,1 +1,0 @@
1 -XWiki.Hunter
Size
... ... @@ -1,1 +1,0 @@
1 -41.0 KB
Content
8217Wc3rju.png
Author
... ... @@ -1,1 +1,0 @@
1 -XWiki.Hunter
Size
... ... @@ -1,1 +1,0 @@
1 -50.8 KB
Content
E2.png
Author
... ... @@ -1,1 +1,0 @@
1 -XWiki.Hunter
Size
... ... @@ -1,1 +1,0 @@
1 -154.6 KB
Content
EYGRzMYrhy.png
Author
... ... @@ -1,1 +1,0 @@
1 -XWiki.Hunter
Size
... ... @@ -1,1 +1,0 @@
1 -171.9 KB
Content
SSH1.png
Author
... ... @@ -1,1 +1,0 @@
1 -XWiki.Hunter
Size
... ... @@ -1,1 +1,0 @@
1 -190.6 KB
Content
checkstatusSSH.png
Author
... ... @@ -1,1 +1,0 @@
1 -XWiki.Hunter
Size
... ... @@ -1,1 +1,0 @@
1 -15.5 KB
Content
sf.png
Author
... ... @@ -1,1 +1,0 @@
1 -XWiki.Hunter
Size
... ... @@ -1,1 +1,0 @@
1 -298.4 KB
Content
wechatCopyTempalte.png
Author
... ... @@ -1,1 +1,0 @@
1 -XWiki.Hunter
Size
... ... @@ -1,1 +1,0 @@
1 -22.9 KB
Content
wechatID.png
Author
... ... @@ -1,1 +1,0 @@
1 -XWiki.Hunter
Size
... ... @@ -1,1 +1,0 @@
1 -41.0 KB
Content
wechatTempalte.png
Author
... ... @@ -1,1 +1,0 @@
1 -XWiki.Hunter
Size
... ... @@ -1,1 +1,0 @@
1 -23.1 KB
Content
wechatTempalteConten.png
Author
... ... @@ -1,1 +1,0 @@
1 -XWiki.Hunter
Size
... ... @@ -1,1 +1,0 @@
1 -46.9 KB
Content
wechatTempalteConten2.png
Author
... ... @@ -1,1 +1,0 @@
1 -XWiki.Hunter
Size
... ... @@ -1,1 +1,0 @@
1 -48.4 KB
Content
wechataccount.png
Author
... ... @@ -1,1 +1,0 @@
1 -XWiki.Hunter
Size
... ... @@ -1,1 +1,0 @@
1 -70.4 KB
Content
wechatscriptcopyID.png
Author
... ... @@ -1,1 +1,0 @@
1 -XWiki.Hunter
Size
... ... @@ -1,1 +1,0 @@
1 -245.5 KB
Content