Changes for page 01 Lua Functions

Last modified by Theodore Xu on 2023/10/26 10:51

From version 9.1
edited by Stone Wu
on 2022/07/25 11:32
Change comment: Renamed from xwiki:V-BOX.V-Net.1\.User Manual.04 Lua Script.01 Lua Functions.WebHome
To version 21.1
edited by Theodore Xu
on 2023/10/26 10:51
Change comment: There is no comment for this version

Summary

Details

Page properties
Parent
... ... @@ -1,1 +1,1 @@
1 -V-BOX.V-Net.1\.User Manual.04 Lua Script.WebHome
1 +V-BOX.V-Net.Manual.04 Lua Script.WebHome
Author
... ... @@ -1,1 +1,1 @@
1 -XWiki.Stone
1 +XWiki.AiXia
Content
... ... @@ -1356,175 +1356,14 @@
1356 1356  {{/code}}
1357 1357  
1358 1358  (((
1359 -= **8 Internal register** =
1359 +
1360 1360  )))
1361 1361  
1362 -The internal registers of the box are divided into bit addresses and word addresses, which can be accessed in two ways (taking HDW as an example):
1363 -
1364 -**Access by word, prefix @W_HDW.**
1365 -
1366 -For example: @W_HDW0 represents the first word of the system data area, @W_HDW1 represents the second word of the system data area.
1367 -
1368 -**Access in bit mode, the prefix is @B_HDX, the number in front of "." indicates the number of the word, and the number behind is the bit number of the word.**
1369 -
1370 -**For example:** @B_HDX1020.12, its meaning is to access the system data area in bit mode, the specific location is the 13th bit of the 1020th word.
1371 -
1372 -(% class="box infomessage" %)
1373 1373  (((
1374 -**✎Note: **
1375 -
1376 -* The address in @B_HDX is taken from the word in @W_HDW, so pay special attention when using the address.
1377 -** For example, @B_HDX1020.12 is to access the 13th bit of the 1020th word. The value of this bit is the same as the word obtained by @W_HDW001020. The 13th bit of this word is actually the same bit as @B_HDX1020.12.
1378 -* The address of the bit address @B_HDX has a decimal point, while the word address is an integer.
1363 += **8 General Functions** =
1379 1379  )))
1380 1380  
1381 -
1382 1382  (((
1383 -== **Data storage area(HDW/HDX)** ==
1384 -)))
1385 -
1386 -The system storage area (HDW) of the V-BOX is used to store temporary data:
1387 -
1388 -1. Access by word, the number range is: "@W_HDW0"-"@W_HDW299999".
1389 -1. Access in bit mode, the number range is: "@B_HDX0.0"-"@B_HDX299999.15".
1390 -
1391 -(((
1392 -== **Special data area (HSW/HSX)** ==
1393 -
1394 -(% class="box infomessage" %)
1395 -(((
1396 -**✎Note: **
1397 -
1398 -* //HSW// is a system special register, so please refer to the system special register table during use. Do not use addresses that are not mentioned in the table, and use the addresses stated in the table with caution (example: restart ("@W_HSW0") Writing a value of 1 will cause V-BOX to restart).
1399 -* //Without any conditions. Direct use ("@W_HSW0") will cause the V-BOX to restart continuously.// When using ("@W_HSW0") address, please add judgment conditions, such as: connection to MQTT fails, there is no network, the value of a PLC address meets the condition or counts to a certain value.
1400 -)))
1401 -)))
1402 -
1403 -The system data area (HSW) of the box is used for system special registers (system reserved). Use //addr_getword// to obtain the following register information:
1404 -
1405 -(% class="table-bordered" %)
1406 -|=(% style="width: 151px;" %)address|=(% style="width: 169px;" %)function|=(% style="width: 456px;" %)Read and write status: read only, write only, read and write
1407 -|(% style="width:151px" %)@W_HSW0|(% style="width:169px" %)restart|(% style="width:456px" %)read and write
1408 -|(% style="width:151px" %)@W_HSW1|(% style="width:169px" %)Box time: year|(% style="width:456px" %)read and write
1409 -|(% style="width:151px" %)@W_HSW2|(% style="width:169px" %)Box time: month|(% style="width:456px" %)read and write
1410 -|(% style="width:151px" %)@W_HSW3|(% style="width:169px" %)Box time: day|(% style="width:456px" %)read and write
1411 -|(% style="width:151px" %)@W_HSW4|(% style="width:169px" %)Box time: hour|(% style="width:456px" %)read and write
1412 -|(% style="width:151px" %)@W_HSW5|(% style="width:169px" %)Box time: minute|(% style="width:456px" %)read and write
1413 -|(% style="width:151px" %)@W_HSW6|(% style="width:169px" %)Box time: second|(% style="width:456px" %)read and write
1414 -|(% style="width:151px" %)@W_HSW7|(% style="width:169px" %)Box time: week|(% style="width:456px" %)read and write
1415 -|(% style="width:151px" %)@W_HSW8|(% style="width:169px" %)Ethernet IP1|(% style="width:456px" %)read only
1416 -|(% style="width:151px" %)@W_HSW9|(% style="width:169px" %)Ethernet IP2|(% style="width:456px" %)read only
1417 -|(% style="width:151px" %)@W_HSW10|(% style="width:169px" %)Ethernet IP3|(% style="width:456px" %)read only
1418 -|(% style="width:151px" %)@W_HSW11|(% style="width:169px" %)Ethernet IP4|(% style="width:456px" %)read only
1419 -|(% style="width:151px" %)@W_HSW12|(% style="width:169px" %)Ethernet Mask 1|(% style="width:456px" %)read only
1420 -|(% style="width:151px" %)@W_HSW13|(% style="width:169px" %)Ethernet Mask 2|(% style="width:456px" %)read only
1421 -|(% style="width:151px" %)@W_HSW14|(% style="width:169px" %)Ethernet Mask 3|(% style="width:456px" %)read only
1422 -|(% style="width:151px" %)@W_HSW15|(% style="width:169px" %)Ethernet Mask 4|(% style="width:456px" %)read only
1423 -|(% style="width:151px" %)@W_HSW16|(% style="width:169px" %)Ethernet Gateway 1|(% style="width:456px" %)read only
1424 -|(% style="width:151px" %)@W_HSW17|(% style="width:169px" %)Ethernet Gateway 2|(% style="width:456px" %)read only
1425 -|(% style="width:151px" %)@W_HSW18|(% style="width:169px" %)Ethernet Gateway 3|(% style="width:456px" %)read only
1426 -|(% style="width:151px" %)@W_HSW19|(% style="width:169px" %)Ethernet Gateway 4|(% style="width:456px" %)read only
1427 -|(% style="width:151px" %)@W_HSW21|(% style="width:169px" %)Ethernet MAC1|(% style="width:456px" %)read only
1428 -|(% style="width:151px" %)@W_HSW22|(% style="width:169px" %)Ethernet MAC2|(% style="width:456px" %)read only
1429 -|(% style="width:151px" %)@W_HSW23|(% style="width:169px" %)Ethernet MAC3|(% style="width:456px" %)read only
1430 -|(% style="width:151px" %)@W_HSW24|(% style="width:169px" %)Ethernet MAC4|(% style="width:456px" %)read only
1431 -|(% style="width:151px" %)@W_HSW25|(% style="width:169px" %)Ethernet MAC3|(% style="width:456px" %)read only
1432 -|(% style="width:151px" %)@W_HSW26|(% style="width:169px" %)Ethernet MAC4|(% style="width:456px" %)read only
1433 -|(% style="width:151px" %)@W_HSW128|(% style="width:169px" %)WIFI IP1|(% style="width:456px" %)read only
1434 -|(% style="width:151px" %)@W_HSW129|(% style="width:169px" %)WIFI IP2|(% style="width:456px" %)read only
1435 -|(% style="width:151px" %)@W_HSW130|(% style="width:169px" %)WIFI IP3|(% style="width:456px" %)read only
1436 -|(% style="width:151px" %)@W_HSW131|(% style="width:169px" %)WIFI IP4|(% style="width:456px" %)read only
1437 -|(% style="width:151px" %)@W_HSW132|(% style="width:169px" %)WIFI Mask 1|(% style="width:456px" %)read only
1438 -|(% style="width:151px" %)@W_HSW133|(% style="width:169px" %)WIFI Mask 2|(% style="width:456px" %)read only
1439 -|(% style="width:151px" %)@W_HSW134|(% style="width:169px" %)WIFI Mask 3|(% style="width:456px" %)read only
1440 -|(% style="width:151px" %)@W_HSW135|(% style="width:169px" %)WIFI Mask 4|(% style="width:456px" %)read only
1441 -|(% style="width:151px" %)@W_HSW136|(% style="width:169px" %)WIFI Gateway 1|(% style="width:456px" %)read only
1442 -|(% style="width:151px" %)@W_HSW137|(% style="width:169px" %)WIFI Gateway 2|(% style="width:456px" %)read only
1443 -|(% style="width:151px" %)@W_HSW138|(% style="width:169px" %)WIFI Gateway 3|(% style="width:456px" %)read only
1444 -|(% style="width:151px" %)@W_HSW139|(% style="width:169px" %)WIFI Gateway 4|(% style="width:456px" %)read only
1445 -|(% style="width:151px" %)@W_HSW140|(% style="width:169px" %)WIFI MAC1|(% style="width:456px" %)read only
1446 -|(% style="width:151px" %)@W_HSW141|(% style="width:169px" %)WIFI MAC2|(% style="width:456px" %)read only
1447 -|(% style="width:151px" %)@W_HSW142|(% style="width:169px" %)WIFI MAC3|(% style="width:456px" %)read only
1448 -|(% style="width:151px" %)@W_HSW143|(% style="width:169px" %)WIFI MAC4|(% style="width:456px" %)read only
1449 -|(% style="width:151px" %)@W_HSW144|(% style="width:169px" %)WIFI MAC5|(% style="width:456px" %)read only
1450 -|(% style="width:151px" %)@W_HSW145|(% style="width:169px" %)WIFI MAC6|(% style="width:456px" %)read only
1451 -|(% style="width:151px" %)@W_HSW146|(% style="width:169px" %)WIFI Signal value|(% style="width:456px" %)read only
1452 -|(% style="width:151px" %)@W_HSW148|(% style="width:169px" %)4G IP1|(% style="width:456px" %)read only
1453 -|(% style="width:151px" %)@W_HSW149|(% style="width:169px" %)4G IP2|(% style="width:456px" %)read only
1454 -|(% style="width:151px" %)@W_HSW150|(% style="width:169px" %)4G IP3|(% style="width:456px" %)read only
1455 -|(% style="width:151px" %)@W_HSW151|(% style="width:169px" %)4G IP4|(% style="width:456px" %)read only
1456 -|(% style="width:151px" %)@W_HSW152|(% style="width:169px" %)4G Mask 1|(% style="width:456px" %)read only
1457 -|(% style="width:151px" %)@W_HSW153|(% style="width:169px" %)4G Mask 2|(% style="width:456px" %)read only
1458 -|(% style="width:151px" %)@W_HSW154|(% style="width:169px" %)4G Mask 3|(% style="width:456px" %)read only
1459 -|(% style="width:151px" %)@W_HSW155|(% style="width:169px" %)4G Mask 4|(% style="width:456px" %)read only
1460 -|(% style="width:151px" %)@W_HSW156|(% style="width:169px" %)4G Gateway 1|(% style="width:456px" %)read only
1461 -|(% style="width:151px" %)@W_HSW157|(% style="width:169px" %)4G Gateway 2|(% style="width:456px" %)read only
1462 -|(% style="width:151px" %)@W_HSW158|(% style="width:169px" %)4G Gateway 3|(% style="width:456px" %)read only
1463 -|(% style="width:151px" %)@W_HSW159|(% style="width:169px" %)4G Gateway 4|(% style="width:456px" %)read only
1464 -|(% style="width:151px" %)@W_HSW160|(% style="width:169px" %)4G MAC1|(% style="width:456px" %)read only
1465 -|(% style="width:151px" %)@W_HSW161|(% style="width:169px" %)4G MAC2|(% style="width:456px" %)read only
1466 -|(% style="width:151px" %)@W_HSW162|(% style="width:169px" %)4G MAC3|(% style="width:456px" %)read only
1467 -|(% style="width:151px" %)@W_HSW163|(% style="width:169px" %)4G MAC4|(% style="width:456px" %)read only
1468 -|(% style="width:151px" %)@W_HSW164|(% style="width:169px" %)4G MAC5|(% style="width:456px" %)read only
1469 -|(% style="width:151px" %)@W_HSW165|(% style="width:169px" %)4G MAC6|(% style="width:456px" %)read only
1470 -|(% style="width:151px" %)@W_HSW166|(% style="width:169px" %)4G Signal value|(% style="width:456px" %)read only
1471 -
1472 -**Others**
1473 -
1474 -* Access password: addr_getstring("@W_HSW27", 16)
1475 -* Machine code: addr_getstring("@W_HSW60", 64)
1476 -* Positioning method (@W_HSW167): (read only)
1477 -** Latitude and longitude
1478 -*** Longitude: addr_getdouble("@W_HSW168") (read only)
1479 -*** Latitude: addr_getdouble("@W_HSW172") (read only)
1480 -** Base station positioning
1481 -*** LAC: addr_getdword("@W_HSW168") (read only)
1482 -*** CI: addr_getdword("@W_HSW172") (read only)
1483 -* Convert base station to latitude and longitude via API
1484 -** Longitude: addr_getdouble("@W_HSW187") (read only)
1485 -** Latitude: addr_getdouble("@W_HSW183") (read only)
1486 -* Operator information: addr_getdword("@W_HSW181") (read only)
1487 -* Networking mode: addr_getword("@W_HSW177") (read only)
1488 -** 0: Ethernet
1489 -** 1: WIFI
1490 -** 2: 4G
1491 -** 3: 2G
1492 -* Map fence flag: addr_getword("@W_HSW178") (read only)
1493 -** 0: No map fence is drawn
1494 -** 1: Draw a map fence and the box is in the fence
1495 -** 2: Draw a map fence and the box is not in the fence
1496 -* SIM card status addr_getword("@W_HSW179") (read only)
1497 -** 1: No card detected
1498 -** 2: Card insertion detected
1499 -** 3: The card status is abnormal
1500 -* MQTT status addr_getword("@W_HSW180") (read only)
1501 -** 1: online, 2: offline
1502 -* IO interface, X is read only, Y is read and write (H series)
1503 -** addr_getbit(addr1), addr_setbit(addr2)
1504 -** addr1:"@B_Y0" "@B_Y1" "@B_X0" "@B_X1"
1505 -** addr2:"@B_Y0" "@B_Y1"
1506 -* Obtaining IMEI (read only)
1507 -** addr_getstring("@W_HSW191",17)
1508 -* Obtaining ICCID (read only)
1509 -** addr_getstring("@W_HSW225",15)
1510 -
1511 -(((
1512 -== **Power-down storage area (HAW/HAX)** ==
1513 -
1514 -The system storage area (HAW) is used for the system power-down hold registers:
1515 -
1516 -1. Accessed as a word, numbered in the range: "@W_HAW0"-"@W_HAW199999".
1517 -1. Accessed by bit, the numbering range is: "@B_HAX0.0"-"@B_HAX199999.15".
1518 -
1519 -(% class="box infomessage" %)
1520 -(((
1521 -**✎Note:** HAW/HAX is a power-down hold, that is, the registers of this type can retain the data before power-down in case of power-down.
1522 -)))
1523 -
1524 -= **9 General Functions** =
1525 -)))
1526 -
1527 -(((
1528 1528  == **send_sms_ira(string number, string message)** ==
1529 1529  )))
1530 1530  
... ... @@ -1790,7 +1790,7 @@
1790 1790  end
1791 1791  {{/code}}
1792 1792  
1793 -= **10 Special function for V-NET** =
1632 += **9 Special function for V-NET** =
1794 1794  
1795 1795  == **normal_get_alldata()** ==
1796 1796  
... ... @@ -1861,186 +1861,8 @@
1861 1861  
1862 1862  Failed: nil
1863 1863  
1864 -= **11 MySQL database operation** =
1703 += **10 Message summary algorithm** =
1865 1865  
1866 -== **luaMySql.init(string sourcename, string username, string password, string host, number port, string character)** ==
1867 -
1868 -**Function:** Configure database connection parameters
1869 -
1870 -**Parameter:**
1871 -
1872 -sourcename: the name of database
1873 -
1874 -username: the username of the connection
1875 -
1876 -password: the password of the connection
1877 -
1878 -host: the host name of the connection
1879 -
1880 -port: the host port of the connection
1881 -
1882 -character: the character set of the connection
1883 -
1884 -**Return:**
1885 -
1886 -Succeed: string
1887 -
1888 -Failed: multi
1889 -
1890 -== **luaMySql.exec(string statement)** ==
1891 -
1892 -**Function:** Execute the given SQL statement without returning the result set (add, delete, change)
1893 -
1894 -**Parameter:**
1895 -
1896 -statement: the given SQL statement
1897 -
1898 -**Return:**
1899 -
1900 -Succeed: status: returns the number of rows affected by SQL statement execution.
1901 -
1902 -Failed: nil, errorString
1903 -
1904 -== **luaMySql.execWithResult(string statement)** ==
1905 -
1906 -**Function:** Execute the given SQL statement returning the result set (check)
1907 -
1908 -**Parameter:**
1909 -
1910 -statement: the given SQL statement
1911 -
1912 -**Return:**
1913 -
1914 -Succeed: table: returns the result set
1915 -
1916 -Failed: nil, errorString
1917 -
1918 -**For example:**
1919 -
1920 -{{code language="LUA"}}
1921 -mysql = require"mysqlclient"
1922 -
1923 -function DataInitRight()
1924 -
1925 -local dbName = "db_lua1"
1926 -
1927 -local user = "root"
1928 -
1929 -local pwd = "123456"
1930 -
1931 -local host = "192.168.56.186"
1932 -
1933 -local port = 3306
1934 -local character = "UTF8"
1935 -
1936 -mysql.init(dbName, user, pwd, host, port, character)
1937 -
1938 -end
1939 -
1940 -function ExecFunc()
1941 -
1942 -status, errorString = mysql.exec("delete from tb_lua1 where mykey =
1943 -
1944 -10;")
1945 -
1946 -if nil == status then
1947 -
1948 -print("ExecFunc() error:", errorString)
1949 -
1950 -return -1
1951 -
1952 -else
1953 -
1954 -print("the number of rows affected by the command:", status)
1955 -
1956 -end
1957 -
1958 -return 0
1959 -
1960 -end
1961 -
1962 -function ExecWithResultFunc()
1963 -
1964 -status, errorString = mysql.execWithResult("select * from tb_lua1;")
1965 -
1966 -if nil == status then
1967 -
1968 -print("ExecWithResultFunc() error:", errorString)
1969 -
1970 -return -1
1971 -
1972 -else
1973 -
1974 -print("ExecWithResultFunc()
1975 -
1976 -success
1977 -
1978 -: status
1979 -
1980 -type
1981 -
1982 -=
1983 -
1984 -",
1985 -
1986 -type(status))
1987 -
1988 -print("ExecWithResultFunc() success : status len = ", #status)
1989 -
1990 -local num = #status
1991 -
1992 -local i = 1
1993 -
1994 -if num > 0 then
1995 -
1996 -for i = 1, num, 1 do
1997 -
1998 -local var = string.format("select result[%d] :mykey = %d,
1999 -
2000 -value = %s", i, status[i].mykey, status[i].value)
2001 -
2002 -print(var)
2003 -
2004 -end
2005 -
2006 -end
2007 -
2008 -print("---------------")
2009 -
2010 -end
2011 -
2012 -return 0
2013 -end
2014 -
2015 -function luaMysql_apiTest.main()
2016 -
2017 -print("script running ...")
2018 -
2019 -DataInitRight()
2020 -
2021 ---use exec demo
2022 -
2023 -if ExecFunc() < 0 then
2024 -
2025 -return
2026 -
2027 -end
2028 -
2029 ---use execWithResult demo
2030 -
2031 -if ExecWithResultFunc() < 0 then
2032 -
2033 -return
2034 -
2035 -end
2036 -
2037 -print("script running success")
2038 -
2039 -end
2040 -{{/code}}
2041 -
2042 -= **12 Message summary algorithm** =
2043 -
2044 2044  == **hmac(string hash_func, string key, string message)** ==
2045 2045  
2046 2046  **Function:** HMAC calculate