Wiki source code of 05 Lua Script

Last modified by Joe on 2026/05/21 13:49

Show last authors
1 = **1 **Arithmetic operations =
2
3 The example shows how to do the Addition, Subtraction, Multiplication and Division for HMI internal address.
4
5 [[Download link>>https://ftp.we-con.com.cn/Download/WIKI/PI%20HMI/Demo/Lua%20Script/Arithmetic%20operations%20by%20Lua%20V1.0.zip]]
6
7 = **2 MQTT Client** =
8
9 The example shows how to connect to the MQTT server.(Test on MaQiaTTo)
10
11 [[Download link>>https://ftp.we-con.com.cn/Download/WIKI/PI%20HMI/Demo/Lua%20Script/Lua%20MQTT%20Client.zip]]
12
13 = **3 Timer** =
14
15 The example shows how to use the Lua Timer function.
16
17 [[Download link>>https://ftp.we-con.com.cn/Download/WIKI/PI%20HMI/Demo/Lua%20Script/LuaTimer.zip]]
18
19 = **4 Trigger** =
20
21 The example shows how to use the Lua Trigger function.
22
23 [[Download link>>https://ftp.we-con.com.cn/Download/WIKI/PI%20HMI/Demo/Lua%20Script/LuaTrigger.zip]]
24
25 = **5 User Free Protocol** =
26
27 The example shows the simple write and read of User Free protocol
28
29 [[Download link>>https://ftp.we-con.com.cn/Download/WIKI/PI%20HMI/Demo/Lua%20Script/Lua%20User%20Free%20Protocol.zip]]
30
31 = **6 Arabic Keypad** =
32
33 The example shows how to use the Lua to achieve the Arabic keypad. Also available for other non-English language like Cyrillic.
34
35 [[Download link>>https://ftp.we-con.com.cn/Download/WIKI/PI%20HMI/Demo/Lua%20Script/ArabicKeyboard.zip]]
36
37 = **7 FTP Client** =
38
39 The example shows how  to establish the FTP server at WIN10 OS and make V2.0 HMI as FTP client.
40
41 [[Download link>>https://ftp.we-con.com.cn/Download/WIKI/PI%20HMI/Demo/Lua%20Script/FTP%20ClientV2.zip]]
42
43 (% class="box infomessage" %)
44 (((
45 Note: The above demo can work normal in OS V2.0. But if HMI OS  is V3.0, please change "r+" to "r" in the script.
46 )))
47
48 (% style="text-align:center" %)
49 [[image:dZyxVCtWDz.png]]
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 )))
55
56 1.Enter PC (FTP Server) IP address and port number (Default 21).
57
58 (% style="text-align:center" %)
59 [[image:LuaFTPDemoIP&Port.png]]
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.
62
63 (% style="text-align:center" %)
64 [[image:LuaFTPDemoUpload.png]]
65
66 3.Change drive letter of file save path according to drop-down list (There are three option available: Flash, UDisk and SDCard).
67
68 (% style="text-align:center" %)
69 [[image:LuaFTPDemoDropBox.png]]
70
71 4.Change the filename of the file that needs to be downloaded from PC(Server).
72
73 (% style="text-align:center" %)
74 [[image:LuaFTPDemoDownload.png]]
75
76 5.Set the default configuration in file "Script_BG.lua"
77
78 (% style="text-align:center" %)
79 [[image:LuaFTPDemoInitial.png]]
80
81 (% class="box infomessage" %)
82 (((
83 ✎Note: If want to confirm whether it is downloaded successfully, please add a File list object to check in HMI project. If saved path is root path (same to the all three drive), please set the folder as "~/~/".
84 )))
85
86 (% style="text-align:center" %)
87 [[image:LuaFTPDemoFilelist.png]]
88
89 **Common error:**
90
91 In the demo project, if there are some errors in HMI for testing, please check the following steps.
92
93 Error 1: 550 Access is denied
94
95 Open Windows Settings → Update & Security→ Windows Security→ Firewall & network protection→ Advanced setting→ Inbound Rules→ New Rules→ Next → choose "This program path"→ input "C:\Windows\System32\svchost.exe"→ Click "NEXT" continuously
96
97 (% style="text-align:center" %)
98 [[image:qCzqnKTUhp.png]]
99
100 (% style="text-align:center" %)
101 [[image:vfrt3NElMX.png]]
102
103 (% style="text-align:center" %)
104 [[image:dAuz25bdvM.png]]
105
106 (% style="text-align:center" %)
107 [[image:rxQIJkX8ll.png]]
108
109 (% style="text-align:center" %)
110 [[image:vmG8WGu5P2.png]]
111
112
113 Error 2: No route to host
114
115 The previous steps are the same as Error 1 → Port → specific local ports→ input port number "21"→ Click "NEXT" continuously
116
117 (% style="text-align:center" %)
118 [[image:fdsxie8WHc.png]]
119
120 (% style="text-align:center" %)
121 [[image:4ALQq7niTV.png]]
122
123 = **8 Telegram Notification** =
124
125 The example shows how to use Bot API to push the notification to channel or group of Telegram. Please change the Token and Chat id to users' own one.
126
127 [[Download link>>https://ftp.we-con.com.cn/Download/WIKI/PI%20HMI/Demo/Lua%20Script/Telegram.zip]]
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 = 9** LINE Notify(Not available now)** =
133
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.
135
136 [[Download link>>https://ftp.we-con.com.cn/Download/WIKI/PI%20HMI/Demo/Lua%20Script/line.zip]]
137
138
139 = 10** How to parse value from subscribing MQTT topic** =
140
141 (% class="box infomessage" %)
142 (((
143 **Only ig series can use this function.**
144 )))
145
146 This example shows how to parse value from subscribing MQTT topic. Get the value and calculate the average value for group F1, F2, F3 and F4. The testing topic name is "testtopic/test/no1/123456".
147
148 [[Download link>>https://ftp.we-con.com.cn/Download/WIKI/PI%20HMI/Demo/Lua%20Script/MQTT%20JSON%20parse.zip]]
149
150 And the subscribed content is like following:
151
152 {{code language="json"}}
153 {
154 "Cluster_ID": "2",
155 "timestamp": "07:01:45-18.02.2022",
156 "Cust_id": "TAM-1",
157 "Platform_id": "Pro44ead8a8dc3345ACC",
158 "version": "1.5",
159 "Line_active": "true",
160 "Total_sensor": "5",
161 "F1": [
162 {
163 "Counter": "0",
164 "Value": "11"
165 },
166 {
167 "Counter": "1",
168 "Value": "21.1"
169 },
170 {
171 "Counter": "2",
172 "Value": "9"
173 },
174 {
175 "Counter": "3",
176 "Value": "0.06"
177 },
178 {
179 "Counter": "4",
180 "Value": "9"
181 },
182 {
183 "Counter": "5",
184 "Value": "19"
185 },
186 {
187 "Counter": "6",
188 "Value": "9"
189 },
190 {
191 "Counter": "7",
192 "Value": "19"
193 },
194 {
195 "Counter": "8",
196 "Value": "22.89"
197 }
198 ],
199 "F2": [
200 {
201 "Counter": "0",
202 "Value": "1.1"
203 },
204 {
205 "Counter": "1",
206 "Value": "21.21"
207 },
208 {
209 "Counter": "2",
210 "Value": "19"
211 },
212 {
213 "Counter": "3",
214 "Value": "0.6"
215 },
216 {
217 "Counter": "4",
218 "Value": "8"
219 },
220 {
221 "Counter": "5",
222 "Value": "19.1"
223 },
224 {
225 "Counter": "6",
226 "Value": "5.1"
227 }
228 ],
229 "F4": [
230 {
231 "Counter": "0",
232 "Value": "11"
233 },
234 {
235 "Counter": "1",
236 "Value": "21.1"
237 },
238 {
239 "Counter": "2",
240 "Value": "9"
241 },
242 {
243 "Counter": "3",
244 "Value": "0.06"
245 },
246 {
247 "Counter": "4",
248 "Value": "9"
249 },
250 {
251 "Counter": "5",
252 "Value": "19"
253 },
254 {
255 "Counter": "6",
256 "Value": "9"
257 },
258 {
259 "Counter": "7",
260 "Value": "12.1"
261 },
262 {
263 "Counter": "8",
264 "Value": "18.1"
265 }
266 ]
267 }
268 {{/code}}
269
270 So we decode this json into lua object, and then assign the values from "Value" field into table (addresses HDW1~~HDW101, HDW112~~HDW202, HDW213~~HDW313, HDW324~~HDW424).
271
272 (% style="text-align:center" %)
273 [[image:MQTTScreen.png]]
274
275 Due to the MQTT code is not able to running on the simulator from PC, following picture is the testing result from actual HMI screen:
276
277 (% style="text-align:center" %)
278 [[image:MQTTactualtestingresult.png]]
279
280 The JSON parser function is located on mqttAction.lua, called mqtt_msg_callback.
281
282 (% style="text-align:center" %)
283 [[image:MQTTJSONparsefunction.png]]
284
285 = **11 High-Low Byte Switch** =
286
287 The example shows how to convert high bytes and low bytes for one 16bit address. Main function is like following:
288
289 {{code language="lua"}}
290 local lowByte = val & 0x00ff
291 local shiftHigh = lowByte << 8
292 local highByte = val & 0xff00
293 local shiftLow = highByte >> 8
294 local newVal = shiftHigh|shiftLow
295 {{/code}}
296
297 [[Download link>>https://ftp.we-con.com.cn/Download/WIKI/PI%20HMI/Demo/Lua%20Script/byteswitch.zip]]
298
299 = **12 Week time setting** =
300
301 The example shows how to use day time to control functions:
302
303 [[Download link>>https://ftp.we-con.com.cn/Download/WIKI/PI%20HMI/Demo/Lua%20Script/week%20time.zip]]
304
305 = **13 MQTT Multi-link** =
306
307 (% class="box infomessage" %)
308 (((
309 **Only ig series can support this function.**
310 )))
311
312 The example shows use mqtt realize multi-machine function:
313
314 [[Download link>>https://ftp.we-con.com.cn/Download/WIKI/PI%20HMI/Demo/Lua%20Script/MQTT%20Multi-link.zip]]
315
316 = **14 CSV File Generation** =
317
318 The example shows convert the custom lua table data into csv string, then output as a file:
319
320 [[Download link>>https://ftp.we-con.com.cn/Download/WIKI/PI%20HMI/Demo/Lua%20Script/csvGenerate.zip]]
321
322 The following steps take HMI simulator as example:
323
324 ~1. Click button "Create Table" to draw lua table in screen.
325
326 (% style="text-align:center" %)
327 [[image:csvGenerateSteps.png]]
328
329 2. Click button "Save as csv" to save the file into HMI storage path. On the HMI simulator, user can enter the simulation path of U disk to check the file whether create successfully.
330
331 (% style="text-align:center" %)
332 [[image:csvGenerateSimulationPath.png]]
333
334 3. Click button "upload" to upload csv file into server side. In this case, we can check the upload path for PC.
335
336 (% style="text-align:center" %)
337 [[image:csvGenerateServerPath.png]]
338
339 The csv file generation is mainly using the following function to implement, the customized data is argument tab, and csv file storage path in HMI is "udisk:weather1.csv":
340
341 (% style="text-align:center" %)
342 [[image:csvGenerateLuaCode.png]]
343
344 The table drawing is mainly using the following function to implement:
345
346 (% style="text-align:center" %)
347 [[image:csvLuaTableDrawing.png]]
348
349 = 15 **String customized length word-wrapped** =
350
351 The example shows automatically line break for long string content according to user input length.
352
353 [[Download link>>https://ftp.we-con.com.cn/Download/WIKI/PI%20HMI/Demo/Lua%20Script/CRLF.zip]]
354
355 The following are some demonstrated strings from offline simulator:
356
357 (% style="text-align:center" %)
358 [[image:WordWrapDisplayResult.png]]
359
360 = 16 Weather forecast HTTP API request =
361
362 The example shows how to parse value from HTTP response body, and display into HMI internal address. The test forecast official website is [[https:~~/~~/www.weatherapi.com/>>url:https://www.weatherapi.com/]]
363
364 [[Download link>>https://ftp.we-con.com.cn/Download/WIKI/PI%20HMI/Demo/Lua%20Script/luahttp.zip]]
365
366 From the API explorer of weatherapi, the one day forecast response would be like the follows(Because the original data of JSON is very long, there we just show the part of it):
367
368 {{code language="JSON"}}
369 {
370 "location": {
371 "name": "London",
372 "region": "City of London, Greater London",
373 "country": "United Kingdom",
374 "lat": 51.52,
375 "lon": -0.11,
376 "tz_id": "Europe/London",
377 "localtime_epoch": 1688961236,
378 "localtime": "2023-07-10 4:53"
379 },
380 "current": {
381 "last_updated_epoch": 1688960700,
382 "last_updated": "2023-07-10 04:45",
383 "temp_c": 14.0,
384 "temp_f": 57.2,
385 "is_day": 0,
386 "condition": {
387 "text": "Partly cloudy",
388 "icon": "//cdn.weatherapi.com/weather/64x64/night/116.png",
389 "code": 1003
390 },
391 "wind_mph": 4.3,
392 "wind_kph": 6.8,
393 "wind_degree": 220,
394 "wind_dir": "SW",
395 "pressure_mb": 1020.0,
396 "pressure_in": 30.12,
397 "precip_mm": 0.0,
398 "precip_in": 0.0,
399 "humidity": 88,
400 "cloud": 50,
401 "feelslike_c": 13.3,
402 "feelslike_f": 56.0,
403 "vis_km": 10.0,
404 "vis_miles": 6.0,
405 "uv": 1.0,
406 "gust_mph": 10.5,
407 "gust_kph": 16.9
408 },
409 "forecast": {
410 "forecastday": [
411 {
412 "date": "2023-07-10",
413 "date_epoch": 1688947200,
414 "day": {
415 "maxtemp_c": 24.4,
416 "maxtemp_f": 75.9,
417 "mintemp_c": 14.1,
418 "mintemp_f": 57.4,
419 "avgtemp_c": 19.6,
420 "avgtemp_f": 67.2,
421 "maxwind_mph": 15.4,
422 "maxwind_kph": 24.8,
423 "totalprecip_mm": 0.0,
424 "totalprecip_in": 0.0,
425 "totalsnow_cm": 0.0,
426 "avgvis_km": 10.0,
427 "avgvis_miles": 6.0,
428 "avghumidity": 60.0,
429 "daily_will_it_rain": 0,
430 "daily_chance_of_rain": 0,
431 "daily_will_it_snow": 0,
432 "daily_chance_of_snow": 0,
433 "condition": {
434 "text": "Partly cloudy",
435 "icon": "//cdn.weatherapi.com/weather/64x64/day/116.png",
436 "code": 1003
437 },
438 "uv": 5.0
439 },
440 "astro": {
441 "sunrise": "04:55 AM",
442 "sunset": "09:16 PM",
443 "moonrise": "12:26 AM",
444 "moonset": "02:01 PM",
445 "moon_phase": "Last Quarter",
446 "moon_illumination": "51",
447 "is_moon_up": 1,
448 "is_sun_up": 0
449 },
450 "hour": [
451 {
452 "time_epoch": 1688943600,
453 "time": "2023-07-10 00:00",
454 "temp_c": 16.2,
455 "temp_f": 61.2,
456 "is_day": 0,
457 "condition": {
458 "text": "Clear",
459 "icon": "//cdn.weatherapi.com/weather/64x64/night/113.png",
460 "code": 1000
461 },
462 "wind_mph": 7.2,
463 "wind_kph": 11.5,
464 "wind_degree": 223,
465 "wind_dir": "SW",
466 "pressure_mb": 1021.0,
467 "pressure_in": 30.14,
468 "precip_mm": 0.0,
469 "precip_in": 0.0,
470 "humidity": 74,
471 "cloud": 6,
472 "feelslike_c": 16.2,
473 "feelslike_f": 61.2,
474 "windchill_c": 16.2,
475 "windchill_f": 61.2,
476 "heatindex_c": 16.2,
477 "heatindex_f": 61.2,
478 "dewpoint_c": 11.6,
479 "dewpoint_f": 52.9,
480 "will_it_rain": 0,
481 "chance_of_rain": 0,
482 "will_it_snow": 0,
483 "chance_of_snow": 0,
484 "vis_km": 10.0,
485 "vis_miles": 6.0,
486 "gust_mph": 10.7,
487 "gust_kph": 17.3,
488 "uv": 1.0
489 },
490 {
491 "time_epoch": 1688947200,
492 "time": "2023-07-10 01:00",
493 "temp_c": 15.7,
494 "temp_f": 60.3,
495 "is_day": 0,
496 "condition": {
497 "text": "Overcast",
498 "icon": "//cdn.weatherapi.com/weather/64x64/night/122.png",
499 "code": 1009
500 },
501 "wind_mph": 7.2,
502 "wind_kph": 11.5,
503 "wind_degree": 232,
504 "wind_dir": "SW",
505 "pressure_mb": 1021.0,
506 "pressure_in": 30.14,
507 "precip_mm": 0.0,
508 "precip_in": 0.0,
509 "humidity": 75,
510 "cloud": 100,
511 "feelslike_c": 15.7,
512 "feelslike_f": 60.3,
513 "windchill_c": 15.7,
514 "windchill_f": 60.3,
515 "heatindex_c": 15.7,
516 "heatindex_f": 60.3,
517 "dewpoint_c": 11.3,
518 "dewpoint_f": 52.3,
519 "will_it_rain": 0,
520 "chance_of_rain": 0,
521 "will_it_snow": 0,
522 "chance_of_snow": 0,
523 "vis_km": 10.0,
524 "vis_miles": 6.0,
525 "gust_mph": 10.5,
526 "gust_kph": 16.9,
527 "uv": 1.0
528 },
529 ...
530 {
531 "time_epoch": 1689026400,
532 "time": "2023-07-10 23:00",
533 "temp_c": 19.0,
534 "temp_f": 66.2,
535 "is_day": 0,
536 "condition": {
537 "text": "Overcast",
538 "icon": "//cdn.weatherapi.com/weather/64x64/night/122.png",
539 "code": 1009
540 },
541 "wind_mph": 9.4,
542 "wind_kph": 15.1,
543 "wind_degree": 192,
544 "wind_dir": "SSW",
545 "pressure_mb": 1015.0,
546 "pressure_in": 29.96,
547 "precip_mm": 0.0,
548 "precip_in": 0.0,
549 "humidity": 66,
550 "cloud": 100,
551 "feelslike_c": 19.0,
552 "feelslike_f": 66.2,
553 "windchill_c": 19.0,
554 "windchill_f": 66.2,
555 "heatindex_c": 19.0,
556 "heatindex_f": 66.2,
557 "dewpoint_c": 12.4,
558 "dewpoint_f": 54.3,
559 "will_it_rain": 0,
560 "chance_of_rain": 0,
561 "will_it_snow": 0,
562 "chance_of_snow": 0,
563 "vis_km": 10.0,
564 "vis_miles": 6.0,
565 "gust_mph": 13.0,
566 "gust_kph": 20.9,
567 "uv": 1.0
568 }
569 ]
570 }
571 ]
572 }
573 }
574 {{/code}}
575
576 The core code is from file API_WEATHER.lua, and function name is get7DayWeatherapiByCityname.
577
578 (% style="text-align:center" %)
579 [[image:WeatherHTTPAPI.png]]
580
581 The HMI offline simulator result:
582
583 (% style="text-align:center" %)
584 [[image:WeatherHTTPtestdisplay.png]]
585
586 = 17 **CSV File Reading** =
587
588 The example shows how to read the csv file into HMI, and then display as table.
589
590 [[Download link>>https://ftp.we-con.com.cn/Download/WIKI/PI%20HMI/Demo/Lua%20Script/csvRead.zip]]
591
592 The core code is from file readcsv.lua:
593
594 1) The file path is set as Sheet_2023_06_13_15_29_45.csv at the root path for USB;
595
596 2) Remember to change csv separator in the second parameter from function csv_csvToTable according to user's need, this demo is using **semicolon** as separator;
597
598 (% style="text-align:center" %)
599 [[image:CSVreadwithsemicolon.png]]
600
601 3) The reading content is a two-dimensional table, can use the table index to locate the specify data cell;
602
603 For example, want to read the 2nd row C column from the table, the table index will be like table[2][3].
604
605 (% style="text-align:center" %)
606 [[image:celllocation.png]]
607
608 = 18 How to convert a number to a string =
609
610 The example shows how to convert a number to a string using the "tostring()" function.
611
612 [[Download link>>https://ftp.we-con.com.cn/Download/WIKI/PI%20HMI/Demo/Lua%20Script/Number%20to%20string.zip]]
613
614 Note:This demo converts a 64-bit floating to a string,you can change the data format of "@W_HDW0" depand on requirements
615
616 The core code is from file convert.lua:
617
618 (% style="text-align:center" %)
619 [[image:convert.lua.png]]
620
621 The HMI offline simulator result:
622
623 (% style="text-align:center" %)
624 [[image:Converttestdisplay.png]]
625
626 = 19 HUAWEI CLOUD & OpenCloud =
627
628 About the details, please check the powerpoint or video of Lua MQTT & OpenCloud [[Jump To>>doc:PIStudio.Download.1 Manual.WebHome]]
629
630 [[Download link>>https://ftp.we-con.com.cn/Download/WIKI/PI%20HMI/Demo/Lua%20Script/HuaweiMQ%281%29.zip]]
631
632 = 20 UDP Multicast =
633
634 The example shows how to use UDP multicast feature to send and receive data.
635
636 [[Download link>>https://ftp.we-con.com.cn/Download/WIKI/PI%20HMI/Demo/Lua%20Script/UDP%20Multicast.zip]]
637
638 About the details, please check the [[UDP module>>https://docs.we-con.com.cn/bin/view/PIStudio/09%20Lua%20Editor/Lua%20Script/#HUDPmodule-1]]
639
640 = 21 ATC module **send SMS** =
641
642 The example shows how to use HMI to customize communication with the ATC SMS module via Lua script to send SMS.
643
644 [[Download link>>https://ftp.we-con.com.cn/Download/WIKI/PI%20HMI/Demo/Lua%20Script/SMS.zip]]
645
646 = 22 TCP Client =
647
648 The example shows how to use the Lua Socket TCP module to connect with a TCP server.
649
650 [[Download link>>https://ftp.we-con.com.cn/Download/WIKI/PI%20HMI/Demo/Lua%20Script/TCP%20ClientV1.1.zip]]
651
652 ~1. Set the initial values of Server IP and port number.
653
654 (% style="text-align:center" %)
655 [[image:vcbt6CE6EL.png]]
656
657 2. Set the actual receive length of TCP message according to the actual needs.
658
659 (% style="text-align:center" %)
660 [[image:tPN1mbz7ny.png]]
661
662 = 23 Lua SMS =
663
664 The example shows how to use HMI built-in 4G module to send SMS via Lua script. This demo requires the HMI model name with (G) or (AG).
665
666 [[Download link>>https://ftp.we-con.com.cn/Download/WIKI/PI%20HMI/Demo/Lua%20Script/Lua%20SMS%20Library.zip]]
667
668 = 24 ATC module Calling =
669
670 The example shows how to use HMI to customize communication with the ATC-3101 module via Lua script to make phone call.
671
672 [[Download link>>https://ftp.we-con.com.cn/Download/WIKI/PI%20HMI/Demo/Lua%20Script/lua%20ATC%20calling.rar]]
673
674 (% class="box infomessage" %)
675 (((
676 Note:Due to differences in operators, it is recommended to test before use.
677 )))
678
679 = 25 Lua SQLite =
680
681 The example shows how to generate a user customized database and table via Lua script.
682
683 [[Download link>>https://ftp.we-con.com.cn/Download/WIKI/PI%20HMI/Demo/Lua%20Script/SQL%20demo.zip]]
684
685 ~1. Choose the designate storage path of db file, here we choose the U disk;
686
687 (% style="text-align:center" %)
688 [[image:lgvAY47My2.png]]
689
690 2. Create the database a.db and create the table filer;
691
692 (% style="text-align:center" %)
693 [[image:SbfZ7qC2qr.png]]
694
695 3. Write the data of HDW10, then click Add data to insert new record into the table filer;
696
697 (% style="text-align:center" %)
698 [[image:sMi8nKsDCy.png]]
699
700 4. Export the file a.db to PC, and using the DB Browser to view the created data(Because it is not standard data record file, not able to be recognized correctly by DataLogTool);
701
702 (% style="text-align:center" %)
703 [[image:xT8f08pfY0.png]]
704
705 = 26 Send attachment picture with SMTP by Gmail =
706
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]]