Wiki source code of 05 Lua Script

Version 77.1 by Jett on 2025/06/07 17:32

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