Wiki source code of 02 Lua Operation

Last modified by Devin Chen on 2025/12/10 11:46

Hide last authors
Wecon 1.1 1 = Support model and version =
2
3 (% class="table-bordered" %)
4 |model|Whether to support Lua script
Devin Chen 2.1 5 |E-4G|support
6 |H-00|support
7 |H-WF|support
Wecon 1.1 8 |H-AG|support
Devin Chen 2.1 9 |S-3N (Discontinued)|support
10 |S-NG (Discontinued)|support
11 |E-00 (Discontinued)|not support
12 |E-2G (Discontinued)|not support
Wecon 1.1 13
14 (((
15 = **Lua Script for V-NET** =
16 )))
17
18 Click the V-Box menu "Lua Script". Lua operation includes: new script, edit script, delete script, batch delete, batch synchronization, import script, export script, debugging, view V-Box script and other functions.
19
20 (% style="text-align:center" %)
21 [[image:1623138622268-172.png||height="158" width="800" class="img-thumbnail"]]
22
23 **Import:**import new script from computer,and the original scripts will be cleared if import new scripts.
24
25 **Export:**export “V-Box.script” to computer.But user can not program it.
26
27 **Sync selected:**update script into V-Box
28
29 **Delete selected:**delete script into V-Box
30
31 **New: **creat new script.Up to five new scripts can be added
32
33 **Debug:**test script and check result.In general,user will print different text to test whether script is correct.
34
35 == **Create a new script** ==
36
37 Click on the **"New"** button to create a new script for this V-Box. It requires two steps to complete.
38
39 (% style="text-align:center" %)
40 [[image:1623139282330-304.png||height="58" width="700" class="img-thumbnail"]]
41
42 **Step 1: **Enter script name “Test1” , choose timing mode and click “save and next”
43
44 (% style="text-align:center" %)
45 [[image:1623139344682-566.png||height="390" width="600" class="img-thumbnail"]]
46
47 **Name:** Enter the name. The name must be begin with letter, within a maximum of 32 characters , characters only support letter and number
48
49 **Execution mode: **select the execution conditions of this script. The execution conditions of the script include the following
50
51 (% style="text-align:center" %)
52 [[image:1623138716090-110.png||height="187" width="600" class="img-thumbnail"]]
53
54 (((
55 (% class="table-bordered" style="width:869px" %)
56 |=(% style="width: 229px;" %)Execution conditions|=(% style="width: 440px;" %)Features|=(% style="width: 197px;" %)Script Quantity
57 |(% style="width:229px" %)Initial execution|(% style="width:440px" %)It is executed after the V-Box is powered on, and only once.|(% style="width:197px" %)1.
58 |(% style="width:229px" %)Execute if connect|(% style="width:440px" %)Execute one time after V-Box connects server.|(% style="width:197px" %)1.
59 |(% style="width:229px" %)Execute if disconnect|(% style="width:440px" %)execute one time after V-Box disconnects server.  |(% style="width:197px" %)1.
60 |(% style="width:229px" %)Timing|(% style="width:440px" %)According to the set timing time, loop execution.|(% style="width:197px" %)Up to 5.
61 )))
62
63 **Timing: **When the execution script condition is timing execution, you need to enter the time and time unit of the timing execution. The time unit can choose days, hours, minutes, seconds, milliseconds. And the timing time must be greater than 1000 milliseconds and cannot exceed 1 day.After the information is filled in correctly, click Save and enter the next step to generate a new script and enter the next step of script editing, script editing.
64
65 (% class="box infomessage" %)
66 (((
67 **✎Note: **After saving, except for the timing time under the timing execution condition, which can be modified, other information cannot be modified once it is saved.
68 )))
69
70 **Step 2**: Write the LUA script
71
72 [[image:1623140173369-625.png||class="img-thumbnail"]]
73
74 After entering the step 2 to write the LUA script. At this time, the initialization code will be displayed in the script editor. As follows:
75
76 function **script name**.main()
77
78 ~-~-dosomething
79
80 End
81
82 **Step 3:**Click "Sync" to synchronize script between V-Box with server
83
84 (% style="text-align:center" %)
85 [[image:1623143884014-119.png||height="46" width="700" class="img-thumbnail"]]
86
87 **Step 4:**Click debug and set on the debug button."happy new year" will be printed
88
89 (% style="text-align:center" %)
90 [[image:1623144228243-269.png||height="204" width="900" class="img-thumbnail"]]
91
92 == **Script list:** ==
93
94 The added script will be displayed in the script list. One line represents one script. As shown below
95
96 (% style="text-align:center" %)
97 [[image:1623142070940-453.png||height="306" width="800" class="img-thumbnail"]]
98
99 == **Description of script parameters:** ==
100
101 (% class="table-bordered" %)
102 |Field|Description
103 |status|Refers to whether the script is synchronized. The state is divided into two states: synchronized and unsynchronized
104 |name|script name
105 |Execution script|The execution conditions of the script
106 |Enable|ON means to run script, and OFF means to close script. When the V-Box is offline or pass-through, the button is grayed out and cannot be operated
107 |Synchronize|Synchronize the script to the V-Box. When the script synchronization fails, it will prompt the synchronization failure, and click on the details to view the failure information feedback from the V-Box. When the V-Box is offline or pass-through, the button is grayed out and cannot be operated
108 |V-Box script|View the script that have been running on the V-Box
109 |operating|delete and edit script
110
111 == **Delete** ==
112
113 Click the delete button in the operation V-Box behind the script list to delete a single script.
114
115 Select multiple script, click the batch delete in the script list button bar, you can delete the selected script
116
117 == **Editor** ==
118
119 Click the edit button in the operation V-Box in thescript list to edit the script. The second step of the default entry script: writing LUA scripts. After entering this page, click the first step to view the basic information of the script. When editing a script, in the basic information, except for the timing, other information cannot be modified.
120
121 (% style="text-align:center" %)
122 [[image:慧网脚本使用帮助-0726.zh-CN.en (1)_html_25473d328696ae96.png||height="432" width="800" class="img-thumbnail"]]
123
124 === **Batch sync** ===
125
126 Select script and click the batch synchronization button above the list to perform batch synchronization of the selected scripts. The compilation failure information after synchronization will be displayed after the synchronization button in the script list.
127
128 (1) Import and export scripts
129
130 (2) Export script: Click in the button bar above the policy list[[image:1623144856369-128.png]] , Can export all the script of the current V-Box as a file with a .script extension
131
132 (3) Import script: Click in the button bar above the script list[[image:1623144876232-174.png]] , You can import an external script file with a .script extension into the V-Box. After importing the script, the script of the current V-Box will be cleared.
133
134 (% style="text-align:center" %)
135 [[image:1623145628300-864.png||height="282" width="700" class="img-thumbnail"]]
136
137 (% class="box infomessage" %)
138 (((
139 **✎Note: **Replacing the communication port will replace the original communication port in the script with the communication port of the current V-Box;
140
141 If the communication port of the current V-Box is empty, it will prompt: the current V-Box has no communication port configuration, no need to replace
142
143 If the communication port in the imported script file is empty, it will prompt: there is no communication port configuration in the script, no need to replace
144 )))
145
146 == **Debugging** ==
147
148 Click the debug button in the button bar above the script list to enter the script debugging window of the V-Box
149
150 (% style="text-align:center" %)
151 [[image:1623145708161-638.png||height="399" width="800" class="img-thumbnail"]]
152
153 The switch button in the debugging window can turn on or off the report debugging information of the current V-Box
154
155 (((
156 = **Script editor** =
157 )))
158
159 The script editor is an online editor for users to write LUA scripts in the edge computing module. In the second step of adding scripts and modifying script, you can switch to the script editor page to write the LUA script of the V-Box script. As shown below
160
161 (% style="text-align:center" %)
162 [[image:1623145805717-528.png||height="410" width="800" class="img-thumbnail"]]
163
164 The function partition on the script edit page is shown in the figure below:
165
166 (% style="text-align:center" %)
167 [[image:1623146931629-902.png||height="636" width="800" class="img-thumbnail"]]
168
169 == **List of monitoring points** ==
170
171 This area lists all the monitoring point lists of the current V-Box and the function of searching monitoring points.
172
173 Click the line of the monitoring point in the monitoring point list, and the monitoring point will be inserted at the current cursor of the script editor. The inserted monitoring point will be added with the @ symbol in front of the monitoring point name in the editor and defined as a string. Such as”@Beijing A Steam temperature”, The monitoring point variable will follow the grammar rules of the string for grammar checking. After synchronizing the script, the monitoring point variable will be converted to an address on the server side and sent to the V-Box side for use.
174
175 Note: The above monitoring points are converted into address format as @Address type_ serial number# station number: register type main number. sub number Among them, if the station number is empty, remove the station number:, if the sub-number is empty, remove the sub-number
176
177 When the mouse passes over the line of the monitoring point, more detailed monitoring point information will be displayed through the floating V-Box, and clicking the floating V-Box can also display to the cursor of the script editor
178
179 == **Tool list** ==
180
181 Located at the top of the script editor
182
183 (% style="text-align:center" %)
184 [[image:慧网脚本使用帮助-0726.zh-CN.en (1)_html_7b2b5c54a1495f20.png||height="51" width="700" class="img-thumbnail"]]
185
186 From left to right
187
188 Save code: save the current code, the small red dot next to it means the code has been modified but not saved
189
190 Clear code: Clear the current code in the script editor. And restore to the initial structure
191
192 Insert new address: insert a new bit address or word address at the current cursor
193
194 Copy:Copy the code, shortcut key [ctrl+c]. For some low-version browsers (such as IE8 and below), you may not be able to copy the content to use outside of this editor. It is recommended to use ctrl+c to copy the key combination.
195
196 Paste:Paste, shortcut key [ctrl+v]. Except for Internet Explorer, this button is limited to pasting and copying the text in the current editor. It is recommended to use ctrl+v to paste the key combination.
197
198 Undo: Undo actions in the editor every step
199
200 Restore: restore the operation in the editor every step
201
202 Comment code: comment or uncomment the code in the current line or the selected line
203
204 Help: Script editor help document. Will be open to the technical department for the management of help files
205
206 == **Code editing area** ==
207
208 The lua script editor provides user-written lua scripts in the script. It can also perform syntax verification, keyword prompts, common code snippet prompts, variable prompts, code completion, etc. for the written code. At the same time, the monitoring point management function is provided, and the address can be directly inserted as a variable in the code.
209
210 (((
211 **~ Grammar check:**
212 )))
213
214 (% style="text-align:center" %)
215 [[image:慧网脚本使用帮助-0726.zh-CN.en (1)_html_ed6bddd7d2e5d863.png||height="174" width="500" class="img-thumbnail"]]
216
217 When writing Lua code, you can check the validity of the syntax in real time. An icon will appear next to the line number of the syntax error line[[image:慧网脚本使用帮助-0726.zh-CN.en (1)_html_9dd46ab797bea73.png||height="13" width="13"]] , The error message will be prompted after the mouse is moved up. When multiple lines have errors, it will be displayed on the first line of the error. After the error in this line is resolved, it will be displayed on the next line of the error line.
218
219 Error example: [3:30]'do' expected near'doo'. Indicates that do is expected to be entered at the thirtieth character position on the third line
220
221 Grammar checking includes the following aspects:
222
223 A: Check the spelling of keywords
224
225 B: Check the definition of variables
226
227 C: Check the usage specifications of operators
228
229 D: Check the syntax of the function body structure
230
231 (% class="box infomessage" %)
232 (((
233 **✎Note: The above syntax check does not include runtime error checking. Run error checking is the error message returned after the code is sent to the **V-Box **and compiled through the **V-Box**.**
234 )))
235
236 (1) Script prompt
237
238 When writing code, provide hints such as fuzzy matching keywords, defined variables, and code snippets. Click the corresponding prompt line to complete the code. As shown below
239
240 (% style="text-align:center" %)
241 [[image:慧网脚本使用帮助-0726.zh-CN.en (1)_html_9726cf15b099e856.png||height="166" width="500" class="img-thumbnail"]]
242
243 The provided prompt codes and complete codes include the following categories:
244
245 A: Keywords (keyword), Lua language keywords, built-in method names, built-in constants, library functions.
246
247 B: Code snippet (snippet), commonly used code snippets in Lua language.
248
249 C: Defined variables (local), the names of all defined variables.
250
251 (% class="table-bordered" %)
252 |(% rowspan="5" %)code segment|local x = 1|Variable definitions
253 |(((
254 function fname(...)
255
256 - body
257
258 end
259 )))|Function structure
260 |(((
261 for i=1,10 do
262
263 print(i)
264
265 end
266 )))|for loop structure
267 |(((
268 while (condition)
269
270 do
271
272 - body
273
274 end
275 )))|while loop structure
276 |(((
277 if (condition)
278
279 then
280
281 - body
282
283 end
284 )))|Conditional structure
285 |System keywords|break~|do~|else~|elseif~|end~|for~|function~|if~|in~|local~|repeat~|return~|then~|until~|while~|or~|and~|not|
286 |Project-specific keywords|status~|wrap~|encode~|decode~|mqtt~|serial~|json~|null~|
287 open~|close~|write~|flush~|read~|addr_getshort~|addr_setshort~|addr_getword~|addr_setword~|addr_getint~|addr_setint~|addr_getdword~|addr_setdword~|addr_getbit~|addr_setbit~|addr_getbit~|addr_setbit~|addraddraddraddraddraddraddraddraddr_addr_doubleaddradd connect~|disconnect~|isconnected~|subscribe~|unsubscribe~|publish~|on|
288 |Method name|_G~|_VERSION~|assert~|collectgarbage~|dofile~|error~|getmetatable~|ipairs~|" +
289 "load~|loadfile~|next~|pairs~|pcall~|print~|rawequal~|" +
290 "rawget~|rawlen~|rawset~|require~|select~|setmetatable~|" +
291 "tonumber~|tostring~|type~|xpcall~|create~|isyieldable~|resume~|running~|" +
292 "status~|wrap~|yield~|debug~|gethook~|getinfo~|getlocal~|" +
293 "getmetatable~|getregistry~|getupvalue~|" +
294 "getuservalue~|sethook~|setlocal~|setmetatable~|setupvalue~|setuservalue~|traceback~|upvalueid~|upvaluejoin~|" +
295 "abs~|acos~|asin~|atan~|ceil~|cos~|deg~|exp~|" +
296 "floor~|fmod~|huge~|log~|max~|maxinteger~|min~|mininteger~|" +
297 "modf~|pi~|rad~|random~|randomseed~|sin~|sqrt~|tan~|" +
298 "tointeger~|type~|ult~|clock~|date~|difftime~|time~|config~|cpath~|" +
299 "loaded~|loadlib~|path~|preload~|searchers~|searchpath~|byte~|char~|dump~|" +
300 "find~|format~|gmatch~|gsub~|len~|lower~|match~|pack~|packsize~|rep~|reverse~|" +
301 "sub~|unpack~|upper~|concat~|insert~|move~|pack~|remove~|sort~|unpack~|charpattern~|" +
302 "codepoint~|codes~|offset~|" +
303 "foreachi~|maxn~|foreach~|concat~|remove~||
304 |Built-in constant|true~|false~|nil~|_G~|_VERSION|
305 |System library functions|basic~|string~|package~|os~|io~|math~|debug~|table~|utf8~|coroutine|
306 |Project-specific library functions|mqtt~|serial|
307 |other|setn~|foreach~|foreachi~|gcinfo~|log10~|maxn|
308
309 (2) Code highlighting
310
311 (% class="table-bordered" %)
312 |**Code type**|**colour**
313 |Normal code|black
314 |Key words|red
315 |variable|black
316 |String|blue
317 |Built-in method name|green
318 |Constants and built-in constants|purple
319 |Library Functions|black
320 |Comment, ~[~[xx]]|gray
321
322 == **Prompt area** ==
323
324 (% style="text-align:center" %)
325 [[image:慧网脚本使用帮助-0726.zh-CN.en (1)_html_5df77b07a355eaf0.png||height="69" width="700" class="img-thumbnail"]]
326
327 a is located below the script editor. It is hidden by default. When you click the custom method name or mouse over the toolbar button, related prompts will be displayed.
328
329 b Double-click the prompt V-Box or click the X button in the upper right corner to close the prompt V-Box
330
331 c Click the up or down arrow to collapse or collapse the prompt V-Box
332
333 == **Save reminder** ==
334
335 In the case that the script content is modified and not saved, jumping to other modules will pop up a pop-up V-Box to confirm whether to leave. The prompt content of different browsers will be slightly different, as shown in the following figure:
336
337 Chrome:
338
339 (% style="text-align:center" %)
340 [[image:慧网脚本使用帮助-0726.zh-CN.en (1)_html_6fc185af5bdd80f8.png||height="155" width="500" class="img-thumbnail"]]
341
342 Firefox:
343
344 (% style="text-align:center" %)
345 [[image:慧网脚本使用帮助-0726.zh-CN.en (1)_html_5f19a37f0b71b6cc.png||height="145" width="600" class="img-thumbnail"]]
346
347 PC configuration tool:
348
349 (% style="text-align:center" %)
350 [[image:慧网脚本使用帮助-0726.zh-CN.en (1)_html_e25c3c79da74c11e.png||height="165" width="400" class="img-thumbnail"]]