Changes for page 2 Script
Last modified by Devin Chen on 2025/06/06 14:03
From version 48.1
edited by Hunter
on 2023/03/30 16:44
on 2023/03/30 16:44
Change comment:
There is no comment for this version
To version 70.1
edited by Theodore Xu
on 2023/08/25 09:48
on 2023/08/25 09:48
Change comment:
There is no comment for this version
Summary
-
Page properties (2 modified, 0 added, 0 removed)
-
Attachments (0 modified, 9 added, 0 removed)
Details
- Page properties
-
- Author
-
... ... @@ -1,1 +1,1 @@ 1 -XWiki. Hunter1 +XWiki.AiXia - Content
-
... ... @@ -1,9 +1,9 @@ 1 1 = **1 General Script Demo** = 2 2 3 -== **1.1 Address Operation :Write/Read data from address A to B** ==3 +== **1.1 Address Operation** == 4 4 5 5 ((( 6 -For example:transfer D2 to D0 6 +Write/Read data from address A to B**. **For example:transfer D2 to D0 7 7 ))) 8 8 9 9 (% style="text-align:center" %) ... ... @@ -27,25 +27,19 @@ 27 27 28 28 == **1.4 Short message** == 29 29 30 - When the alarm condition is reached: temp1 > 5 & temp2 >10 & temp3 < 20(lasts more than 5 seconds) , then send an "alarm trigger" sms.30 +The following demo shows that when the alarm condition is reached: temp1 > 5 & temp2 >10 & temp3 < 20(lasts more than 5 seconds) , then send an "alarm trigger" sms. 31 31 32 -When the alarm condition is released,then send an "alarm release" sms. 32 +When the alarm condition is released,then send an "alarm release" sms. Script is as below: 33 33 34 -(% style="text-align:center" %) 35 -[[image:1645535936750-316.png||height="385" width="400" class="img-thumbnail"]] 36 - 37 -Script is as below: 38 - 39 -(% class="box infomessage" %) 40 -((( 34 +{{code language="lua"}} 41 41 function sms.main() 42 - ~-~-~-~-~-~-send condition~-~-~-~-~-~-36 +------send condition------ 43 43 local temp1 = addr_getword("@Temperature1") 44 44 local temp2 = addr_getword("@Temperature2") 45 45 local temp3 = addr_getword("@Temperature3") 46 46 local timer = addr_getword("@Timer") 47 47 local tag = addr_getbit("@Tag") 48 - ~-~-~-~-~-~-lasting time~-~-~-~-~-~-42 +------lasting time------ 49 49 if temp1 > 5 and temp2 > 10 and temp3 < 20 then 50 50 timer = timer + 1 51 51 addr_setword("@Timer",timer) ... ... @@ -53,7 +53,7 @@ 53 53 timer = 0 54 54 addr_setword("@Timer",timer) 55 55 end 56 - ~-~-~-~-~-~-send sms & output Y0~-~-~-~-~-~-50 +------send sms & output Y0------ 57 57 if timer > 5 then 58 58 if tag == 0 then 59 59 send_sms_ira("19859254700","alarm trigger") ... ... @@ -64,7 +64,7 @@ 64 64 addr_setbit("@Tag",0) 65 65 end 66 66 end 67 - )))61 +{{/code}} 68 68 69 69 == **1.5 Telegram notification** == 70 70 ... ... @@ -145,7 +145,7 @@ 145 145 146 146 This example shows how to use the LINE Notify to send message into LINE group. When monitoring bit "@test" changes, it will trigger and send the message. Please replace with your own Token. 147 147 148 -{{code}} 142 +{{code language="lua"}} 149 149 local tempBit = 0 150 150 local tempWord = 0 151 151 ... ... @@ -349,7 +349,7 @@ 349 349 end 350 350 {{/code}} 351 351 352 -== **1.8 H ow to parse value from HTTP response body** ==346 +== **1.8 HTTP response body** == 353 353 354 354 This example use [[https:~~/~~/www.weatherapi.com/>>https://www.weatherapi.com/]] as example, to show how to parse value from HTTP response body. When we input the city name into address "@HDW5050": 355 355 ... ... @@ -461,8 +461,25 @@ 461 461 end 462 462 {{/code}} 463 463 464 -= ** 2V-Box connectwiththirdpart server** =458 +== **1.10 Read 64bits Unsigned Value** == 465 465 460 +In our built-in function library doesn't have the function for reading 64-bit unsigned format value, so the following function is for solve this. But if the number is greater 2^53, the precision will be lost. So the final result will be a little bit different from the original value. 461 + 462 +{{code language="lua"}} 463 +function addr_getquatra(address) 464 + local highAddress = addr_newnoaddr(address,2) 465 + local low32 = addr_getdword(address) 466 + local high32 = addr_getdword(highAddress) 467 + --print("the low number is "..low32) 468 + --print("the high number is "..high32) 469 + local formatVal = string.format("%64.0f",2^32*high32+low32) 470 + print("the format value is ".. formatVal) 471 + return formatVal 472 +end 473 +{{/code}} 474 + 475 += **2 Third part server** = 476 + 466 466 V-Box have two mode.One is for V-Net,User need to use WECON server to store data.We call this V-NET platform. 467 467 468 468 (% class="mark" %)1.Europe server:eu.v-box.net ... ... @@ -486,7 +486,7 @@ 486 486 (% class="wikigeneratedid" %) 487 487 Tool link: **[[MQTT.fx>>http://mqttfx.jensd.de/index.php/download]]** 488 488 489 -== **2.1 V-Box connect with test server(General Example)** ==500 +== **2.1 Test server(General Example)** == 490 490 491 491 The following example is trying to publish to the topic "testtopic/test/no1/7890", and subscribe the topic "testtopic/test/no1/123456". 492 492 ... ... @@ -510,6 +510,7 @@ 510 510 {{code language="lua"}} 511 511 --MQTT configuration table 512 512 local MQTT_CFG={} 524 +--if there is no need the username and password, please put them as "" 513 513 MQTT_CFG.username = "weconsupport" 514 514 MQTT_CFG.password = "123456" 515 515 MQTT_CFG.netway = 0 ... ... @@ -549,7 +549,7 @@ 549 549 function mqtt_init() 550 550 print(string.format("mqtt init mqtt_url:%s mqtt_clientid:%s", MQTT_URL, MQTT_CLIENT_ID)) 551 551 if g_mq then 552 - mqtt.close() --Close mqtt object 564 + mqtt.close(g_mq) --Close mqtt object 553 553 end 554 554 g_mq, err = mqtt.create(MQTT_URL, MQTT_CLIENT_ID) -- create mqtt object,and declare it as a global variable 555 555 if g_mq then ... ... @@ -634,7 +634,7 @@ 634 634 end 635 635 {{/code}} 636 636 637 -== **2.2 V-Box connect with customer server:grouprobotinfo.com** ==649 +== **2.2 Customer server:grouprobotinfo.com** == 638 638 639 639 This demo does not use SSL certification. Script is as below 640 640 ... ... @@ -775,7 +775,7 @@ 775 775 end 776 776 {{/code}} 777 777 778 -== **2.3 V-Box connect withAzure platform** ==790 +== **2.3 Azure platform** == 779 779 780 780 In this demo,V-Box connects with Azure by SSL certification. 781 781 ... ... @@ -906,8 +906,12 @@ 906 906 end 907 907 ))) 908 908 909 -== **2.4 H ow to configure the Huawei platform?(✎Note: Huawei IOT DA function is only in China area.If you want this function,you need to use chinese mobile to register)** ==921 +== **2.4 Huawei platform** == 910 910 923 +{{info}} 924 +**✎Note**:**Huawei IOT DA function is only in China area.If you want this function,you need to use chinese mobile to register** 925 +{{/info}} 926 + 911 911 1.Register a account: [[https:~~/~~/www.huaweicloud.com/intl/en-us/s/JUlPVERNJQ>>https://www.huaweicloud.com/intl/en-us/s/JUlPVERNJQ]] 912 912 913 913 2.log in the Huawei IOTDA ... ... @@ -1055,10 +1055,8 @@ 1055 1055 (% style="text-align:center" %) 1056 1056 [[image:1624441186851-536.png||height="434" width="700" class="img-thumbnail"]] 1057 1057 1058 -== **2.5V-Boxconnectwith Huaweiplatform**==1074 +=== Huawei by SSL certification. === 1059 1059 1060 -In this demo,V-Box connects with Huawei by SSL certification. 1061 - 1062 1062 1.Create a project access for Huawei IOT 1063 1063 1064 1064 2.configure MQTT configuration ... ... @@ -1176,7 +1176,7 @@ 1176 1176 (% style="text-align:center" %) 1177 1177 [[image:1624506666650-161.png||height="547" width="1000" class="img-thumbnail"]] 1178 1178 1179 -== **2.6 V-Box connect withAWS platform** ==1193 +== **2.6 AWS platform** == 1180 1180 1181 1181 === **Log in AWS** === 1182 1182 ... ... @@ -1241,7 +1241,7 @@ 1241 1241 [[image:image-20220709165402-11.png]] 1242 1242 1243 1243 1244 -=== ** Test withMQTT.fx tool** ===1258 +=== **MQTT.fx tool** === 1245 1245 1246 1246 Click “View Setting” to get the “Broker Adress” 1247 1247 ... ... @@ -1269,7 +1269,7 @@ 1269 1269 1270 1270 [[image:image-20220709165402-18.png]] 1271 1271 1272 -=== **C onfigurate in CloudTool** ===1286 +=== **CloudTool** === 1273 1273 1274 1274 Copy the same setting in MQTT.fx to MQTT configuration 1275 1275 ... ... @@ -1467,3 +1467,188 @@ 1467 1467 Get message in AWS 1468 1468 1469 1469 [[image:image-20220709165402-21.png]] 1484 + 1485 +== **2.7 Mysql** == 1486 + 1487 +=== 1.Install Mysql software === 1488 + 1489 +Download the latest version of Mysql. 1490 + 1491 +(% style="text-align:center" %) 1492 +[[image:Mysql的软件版本.png]] 1493 + 1494 +=== 2.Navicat connect Mysql === 1495 + 1496 +Connecting to Mysql with navicat. 1497 + 1498 +(% style="text-align:center" %) 1499 +[[image:连接到mysql.png]] 1500 + 1501 +=== 3.Create database === 1502 + 1503 +Character set should be choose utf8mb3/utf8mb4 and Collation choose utf8mb3_danish_ci/utf8mb4_danish_ci. 1504 + 1505 +(% style="text-align:center" %) 1506 +[[image:创建数据库.png]] 1507 + 1508 +=== 4.Create data table === 1509 + 1510 +Create a table, enter the fields you need. 1511 + 1512 +(% style="text-align:center" %) 1513 +[[image:创建表1.png]] 1514 + 1515 +Save, enter table name. 1516 + 1517 +(% style="text-align:center" %) 1518 +[[image:创建表2.png]] 1519 + 1520 +=== 5.Input Table Data === 1521 + 1522 +(% style="text-align:center" %) 1523 +[[image:输入或者导入数据.png]] 1524 + 1525 +=== 6.Script === 1526 + 1527 +**luaMySql.init(string sourcename, string username, string password, string host, number port, string character)** 1528 + 1529 +**Function:** Configure database connection parameters 1530 + 1531 +**Parameter:** 1532 + 1533 +sourcename: the name of database 1534 + 1535 +username: the username of the connection 1536 + 1537 +password: the password of the connection 1538 + 1539 +host: the host name of the connection 1540 + 1541 +port: the host port of the connection 1542 + 1543 +character: the character set of the connection 1544 + 1545 +**Return:** 1546 + 1547 +Succeed: string 1548 + 1549 +Failed: multi 1550 + 1551 +**luaMySql.exec(string statement)** 1552 + 1553 +**Function:** Execute the given SQL statement without returning the result set (add, delete, change) 1554 + 1555 +**Parameter:** 1556 + 1557 +statement: the given SQL statement 1558 + 1559 +**Return:** 1560 + 1561 +Succeed: status: returns the number of rows affected by SQL statement execution. 1562 + 1563 +Failed: nil, errorString 1564 + 1565 +**luaMySql.execWithResult(string statement)** 1566 + 1567 +**Function:** Execute the given SQL statement returning the result set (check) 1568 + 1569 +**Parameter:** 1570 + 1571 +statement: the given SQL statement 1572 + 1573 +**Return:** 1574 + 1575 +Succeed: table: returns the result set 1576 + 1577 +Failed: nil, errorString 1578 + 1579 +**For example:** 1580 + 1581 + 1582 +{{code language="LUA"}} 1583 +-- Assuming the "mysqlclient" library is properly installed and available 1584 +mysql = require("mysqlclient") 1585 + 1586 +function DataInitRight() 1587 + local dbName = "excel" 1588 + local user = "root" 1589 + local pwd = "XXXXX" 1590 + local host = "192.168.39.146" 1591 + local port = 3306 1592 + local character = "utf8mb3" 1593 + 1594 + mysql.init(dbName, user, pwd, host, port, character) 1595 +end 1596 + 1597 +function ExecFunc() 1598 + status, errorString = mysql.exec("delete from student where Name = 'XXX';") --Delete statement, column name = table element 1599 + if nil == status then 1600 + print("ExecFunc() error:", errorString) 1601 + return -1 1602 + else 1603 + print("the number of rows affected by the command:", status) 1604 + end 1605 + return 0 1606 +end 1607 + 1608 + 1609 +function ExecWithResultFunc() 1610 + status, errorString = mysql.execWithResult("select * from student;") 1611 + if nil == status then 1612 + print("ExecWithResultFunc() error:", errorString) 1613 + return -1 1614 + else 1615 + print("ExecWithResultFunc() success : status type = ", type(status)) 1616 + print("ExecWithResultFunc() success : status len = ", #status) 1617 + local num = #status 1618 + local i = 1 1619 + if num > 0 then 1620 + for i = 1, num, 1 do 1621 + local var = string.format("select result[%d] :Num = %d,Name = %s,Age = %d", i, status[i].Num, status[i].Name,status[i].Age) --Iterate through the data in the table, noting whether the elements are strings or numbers 1622 + print(var) 1623 + end 1624 + end 1625 + print("---------------") 1626 + end 1627 + return 0 1628 +end 1629 + 1630 +function MySQL.main() 1631 + print("script running ...") 1632 + DataInitRight() 1633 + 1634 + -- use exec demo 1635 + if ExecFunc() < 0 then 1636 + return 1637 + end 1638 + 1639 + -- use execWithResult demo 1640 + if ExecWithResultFunc() < 0 then 1641 + return 1642 + end 1643 + 1644 + print("script running success") 1645 +end 1646 +{{/code}} 1647 + 1648 +=== 7.Debug === 1649 + 1650 +(% style="text-align:center" %) 1651 +[[image:调试结果.png]] 1652 + 1653 +=== 8.Problem === 1654 + 1655 +During our debugging process it may there are some problems about Mysql, such as 1656 + 1657 +* MySQL: Host 192.168.XXX.XXX is not allowed to connect. 1658 +* MySQL: Host 192.168.XXX.XXX is blocked because of many connection errors. 1659 +* MySQL: SSL connection error: unknown error number. 1660 +* ((( 1661 +1449-The user specified as a definer(‘mysql.infoschema‘@localhost‘) does not exist. 1662 +))) 1663 + 1664 +This type of problem has nothing to do with scripts or devices, it is a Mysql configuration issue. If you have any of these problems, please look for a solution online. 1665 + 1666 +{{info}} 1667 +✎Note: If you want to use CMD to access Mysql, you need to add the bin file to the environment variable, please check online for details of the operation. 1668 +{{/info}}
- Mysql的软件版本.png
-
- Author
-
... ... @@ -1,0 +1,1 @@ 1 +XWiki.AiXia - Size
-
... ... @@ -1,0 +1,1 @@ 1 +78.4 KB - Content
- 创建数据库.png
-
- Author
-
... ... @@ -1,0 +1,1 @@ 1 +XWiki.AiXia - Size
-
... ... @@ -1,0 +1,1 @@ 1 +53.2 KB - Content
- 创建表1.png
-
- Author
-
... ... @@ -1,0 +1,1 @@ 1 +XWiki.AiXia - Size
-
... ... @@ -1,0 +1,1 @@ 1 +49.0 KB - Content
- 创建表2.png
-
- Author
-
... ... @@ -1,0 +1,1 @@ 1 +XWiki.AiXia - Size
-
... ... @@ -1,0 +1,1 @@ 1 +18.4 KB - Content
- 调试结果.png
-
- Author
-
... ... @@ -1,0 +1,1 @@ 1 +XWiki.AiXia - Size
-
... ... @@ -1,0 +1,1 @@ 1 +68.4 KB - Content
- 输入或者导入数据.png
-
- Author
-
... ... @@ -1,0 +1,1 @@ 1 +XWiki.AiXia - Size
-
... ... @@ -1,0 +1,1 @@ 1 +26.6 KB - Content
- 连接到mysql.png
-
- Author
-
... ... @@ -1,0 +1,1 @@ 1 +XWiki.AiXia - Size
-
... ... @@ -1,0 +1,1 @@ 1 +59.0 KB - Content
- 连接数据库1.png
-
- Author
-
... ... @@ -1,0 +1,1 @@ 1 +XWiki.AiXia - Size
-
... ... @@ -1,0 +1,1 @@ 1 +56.5 KB - Content
- 连接数据库2.png
-
- Author
-
... ... @@ -1,0 +1,1 @@ 1 +XWiki.AiXia - Size
-
... ... @@ -1,0 +1,1 @@ 1 +25.5 KB - Content