Wiki source code of 02 Lua Operation

Version 1.1 by Wecon on 2025/09/03 21:04

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