Changes for page 01 Lua Functions
Last modified by Theodore Xu on 2023/10/26 10:51
Summary
-
Page properties (1 modified, 0 added, 0 removed)
Details
- Page properties
-
- Content
-
... ... @@ -1,4 +1,4 @@ 1 -= **1 Interface Description** =1 += **1 Interface description** = 2 2 3 3 == **Data type definition** == 4 4 ... ... @@ -92,24 +92,20 @@ 92 92 1. From the print result, the first line and the second line are successfully called and returns true; the third line fails the call, the error message is translated as: the bar student has been registered, and there is indeed an error in the code. 93 93 1. The fourth line of code uses two variables to receive the return value. The call failed, the first variable stat is nil, and the second variable err stores the error message. Then print it out using print, which is the output of the third line. This example shows how to capture and view the error message. 94 94 95 -== **Modification of the PrintFunction** ==95 +== **Modification of print function** == 96 96 97 -For the convenience of remote development, the print data is sent to the front end (web page) by means of network transmission, and the user can see the result of the debug output, because it consumes certain data and occupies the bandwidth of the server (or occupies server resources). So makethe following restrictions:97 +For the convenience of remote development, the print data is sent to the front end (web page) by means of network transmission, and the user can see the result of the debug output, because it consumes certain data and occupies the bandwidth of the server (or occupies server resources). So the following restrictions are made. 98 98 99 -**1.Interval limit: **When debugging, transfer once every 2~~3 seconds; 99 +1. **Interval limit: **When debugging, transfer once every 2~~3 seconds; 100 +1. **Data limit: **The transfer data cannot be larger than 1.5KB in a single transmission, otherwise the extra part will be ignored; 101 +1. **Transmission limit: **The data transmission will be stopped automatically after the debugging windows is not closed normally. Only when it is in the debugging window and the switch is on, there is data transmission; 100 100 101 -**2.Data limit: **The transfer data cannot be larger than 1.5KB, and the extra part will be ignored; 102 - 103 -**3.Transmission limit: **The data transmission will be stopped automatically after the debugging windows is not closed normally. Only when it is in the debugging window and the switch is on, there is data transmission; 104 - 105 105 Users should pay attention to avoid printing a lot of useless information, should minimize the debug output 106 106 107 107 In addition, please refer to the front-end documentation for how to use view debugging. 108 108 109 109 ((( 110 -= **2 Address Operation** = 111 - 112 - 108 += **2 Address operation** = 113 113 ))) 114 114 115 115 |=16-bit data formal|=HLword|=32-bit data formal|=HLword|= 64-bit data formal|=HLword ... ... @@ -142,20 +142,17 @@ 142 142 43218765 143 143 )))|10 144 144 145 - *If HLword entersany other value,it will be treated as invalid.141 + Table 2-1 146 146 147 - Demo: Reads a 32-bit floating-point number at position D0 of PLC 143 +(% class="box errormessage" %) 144 +((( 145 +**✎Note: **If HLword enters any other value, it will be treated as invalid. 146 +))) 148 148 148 +== **addr_getshort(string addr[, number type, number hlword])** == 149 149 150 +**Function:** Read 16-bit signed decimal address 150 150 151 -[[image:企业微信截图_20210506180640.png||height="301" width="600" class="img-thumbnail"]] 152 - 153 -== **2.1 addr_getshort(string addr[, number type, number hlword])** == 154 - 155 -**Function:** 156 - 157 -Read 16-bit signed decimal address 158 - 159 159 **Parameters:** 160 160 161 161 //addr//: address ... ... @@ -173,13 +173,11 @@ 173 173 Failed: multi 174 174 175 175 ((( 176 -== ** 2.2addr_setshort(string addr, number num[, number type, number hlword])** ==169 +== **addr_setshort(string addr, number num[, number type, number hlword])** == 177 177 ))) 178 178 179 -**Function:** 172 +**Function:** Write 16-bit signed decimal address 180 180 181 -Write 16-bit signed decimal address 182 - 183 183 **Parameters:** 184 184 185 185 //addr//: address ... ... @@ -197,13 +197,11 @@ 197 197 Failed: multi 198 198 199 199 ((( 200 -== ** 2.3addr_getword(string addr[, number type, number hlword])** ==191 +== **addr_getword(string addr[, number type, number hlword])** == 201 201 ))) 202 202 203 -**Function:** 194 +**Function:** Read 16-bit unsigned decimal address 204 204 205 -Read 16-bit unsigned decimal address 206 - 207 207 **Parameters:** 208 208 209 209 //addr//: address ... ... @@ -219,13 +219,11 @@ 219 219 Failed: multi 220 220 221 221 ((( 222 -== ** 2.4addr_setword(string addr, number num[, number type, number hlword])** ==211 +== **addr_setword(string addr, number num[, number type, number hlword])** == 223 223 ))) 224 224 225 -**Function:** 214 +**Function:**Write 16-bit unsigned decimal address 226 226 227 -Write 16-bit unsigned decimal address 228 - 229 229 **Parameters:** 230 230 231 231 //addr//: address ... ... @@ -243,13 +243,11 @@ 243 243 Failed: multi 244 244 245 245 ((( 246 -== ** 2.5addr_getint(string addr[, number type, number hlword])** ==233 +== **addr_getint(string addr[, number type, number hlword])** == 247 247 ))) 248 248 249 -**Function:** 236 +**Function:** Read 32-bit signed decimal address 250 250 251 -Read 32-bit signed decimal address 252 - 253 253 **Parameters:** 254 254 255 255 //addr//: address ... ... @@ -265,13 +265,11 @@ 265 265 Failed: multi 266 266 267 267 ((( 268 -== ** 2.6addr_setint(string addr, number num[, number type, number hlword])** ==253 +== **addr_setint(string addr, number num[, number type, number hlword])** == 269 269 ))) 270 270 271 -**Function:** 256 +**Function:** Write 32-bit signed decimal address 272 272 273 -Write 32-bit signed decimal address 274 - 275 275 **Parameters:** 276 276 277 277 //addr//: address ... ... @@ -289,13 +289,11 @@ 289 289 Failed: multi 290 290 291 291 ((( 292 -== ** 2.7addr_getdword(string addr[, number type, number hlword])** ==275 +== **addr_getdword(string addr[, number type, number hlword])** == 293 293 ))) 294 294 295 -**Function:** 278 +**Function:** Read 32-bit unsigned decimal address 296 296 297 -Read 32-bit unsigned decimal address 298 - 299 299 **Parameters:** 300 300 301 301 //addr//: address ... ... @@ -311,13 +311,11 @@ 311 311 Failed: multi 312 312 313 313 ((( 314 -== ** 2.8addr_setdword(string addr, number num[, number type, number hlword])** ==295 +== **addr_setdword(string addr, number num[, number type, number hlword])** == 315 315 ))) 316 316 317 -**Function:** 298 +**Function:** Write 32-bit unsigned decimal address 318 318 319 -Write 32-bit unsigned decimal address 320 - 321 321 **Parameters:** 322 322 323 323 //addr//: address ... ... @@ -335,13 +335,11 @@ 335 335 Failed: multi 336 336 337 337 ((( 338 -== ** 2.9addr_getbit(string addr[, number type])** ==317 +== **addr_getbit(string addr[, number type])** == 339 339 ))) 340 340 341 -**Function:** 320 +**Function:** Read a bit of the register address 342 342 343 -Read a bit of the register address 344 - 345 345 **Parameters:** 346 346 347 347 //addr//: address ... ... @@ -357,13 +357,11 @@ 357 357 Failed: multi 358 358 359 359 ((( 360 -== ** 2.10addr_setbit(string addr, number num[, number type])** ==337 +== **addr_setbit(string addr, number num[, number type])** == 361 361 ))) 362 362 363 -**Function:** 340 +**Function:** Write a bit of the register address 364 364 365 -Write a bit of the register address 366 - 367 367 **Parameters:** 368 368 369 369 //addr//: address ... ... @@ -381,13 +381,11 @@ 381 381 Failed: multi 382 382 383 383 ((( 384 -== ** 2.11addr_getfloat(string addr[, number type, number hlword])** ==359 +== **addr_getfloat(string addr[, number type, number hlword])** == 385 385 ))) 386 386 387 -**Function:** 362 +**Function:** Read 32-bit floating address 388 388 389 -Read 32-bit floating address 390 - 391 391 **Parameters:** 392 392 393 393 //addr//: address ... ... @@ -403,13 +403,11 @@ 403 403 Failed: multi 404 404 405 405 ((( 406 -== ** 2.12addr_setfloat(string addr, number num[, number type, number hlword])** ==379 +== **addr_setfloat(string addr, number num[, number type, number hlword])** == 407 407 ))) 408 408 409 -**Function:** 382 +**Function:** Write 32-bit floating address 410 410 411 -Write 32-bit floating address 412 - 413 413 **Parameters:** 414 414 415 415 //addr//: address ... ... @@ -427,13 +427,11 @@ 427 427 Failed: multi 428 428 429 429 ((( 430 -== ** 2.13addr_getdouble(string addr[, number type, number hlword])** ==401 +== **addr_getdouble(string addr[, number type, number hlword])** == 431 431 ))) 432 432 433 -**Function:** 404 +**Function:** Read 64-bit floating address 434 434 435 -Read 64-bit floating address 436 - 437 437 **Parameters:** 438 438 439 439 //addr//: address ... ... @@ -449,13 +449,11 @@ 449 449 Failed: multi 450 450 451 451 ((( 452 -== ** 2.14addr_setdouble(string addr, number num[, number type, number hlword])** ==421 +== **addr_setdouble(string addr, number num[, number type, number hlword])** == 453 453 ))) 454 454 455 -**Function:** 424 +**Function:** Write 64-bit floating address 456 456 457 -Write 64-bit floating address 458 - 459 459 **Parameters:** 460 460 461 461 addr: address ... ... @@ -473,13 +473,11 @@ 473 473 Failed: multi 474 474 475 475 ((( 476 -== ** 2.15addr_getstring(string addr, number length[, number type, number hlbyte])** ==443 +== **addr_getstring(string addr, number length[, number type, number hlbyte])** == 477 477 ))) 478 478 479 -**Function:** 446 +**Function:** Read the specified length string from address 480 480 481 -Read the specified length string from address 482 - 483 483 **Parameters:** 484 484 485 485 //addr//: address ... ... @@ -497,13 +497,11 @@ 497 497 Failed: multi 498 498 499 499 ((( 500 -== ** 2.16addr_setstring(string addr, string str[, number type, number hlbyte])** ==465 +== **addr_setstring(string addr, string str[, number type, number hlbyte])** == 501 501 ))) 502 502 503 -**Function:** 468 +**Function:** Write the specified length string to address 504 504 505 -Write the specified length string to address 506 - 507 507 **Parameters:** 508 508 509 509 //addr//: address ... ... @@ -521,13 +521,11 @@ 521 521 Failed: multi 522 522 523 523 ((( 524 -== ** 2.17addr_bmov(string dst, string src, number length)** ==487 +== **addr_bmov(string dst, string src, number length)** == 525 525 ))) 526 526 527 -**Function:** 490 +**Function:** Copy data from source address to destination address 528 528 529 -Copy data from source address to destination address 530 - 531 531 **Parameters:** 532 532 533 533 //dst//: destination address ... ... @@ -543,13 +543,11 @@ 543 543 **Failed: multi** 544 544 545 545 ((( 546 -== ** 2.18addr_fill(string addr, number num, number length)** ==507 +== **addr_fill(string addr, number num, number length)** == 547 547 ))) 548 548 549 -**Function:** 510 +**Function:** Write the same value to consecutive addresses 550 550 551 -Write the same value to consecutive addresses 552 - 553 553 **Parameters:** 554 554 555 555 //addr//: address ... ... @@ -565,13 +565,11 @@ 565 565 Failed: multi 566 566 567 567 ((( 568 -== ** 2.19addr_newnoaddr(string addr, number offset)** ==527 +== **addr_newnoaddr(string addr, number offset)** == 569 569 ))) 570 570 571 -**Function:** 530 +**Function:** Offset address value relative to //addr// 572 572 573 -Offset address value relative to //addr// 574 - 575 575 **Parameters:** 576 576 577 577 //addr//: address ... ... @@ -585,13 +585,11 @@ 585 585 Failed: multi 586 586 587 587 ((( 588 -== ** 2.20addr_newstataddr(string addr, number offset)** ==545 +== **addr_newstataddr(string addr, number offset)** == 589 589 ))) 590 590 591 -**Function:** 548 +**Function:** Offset station number relative to //addr //station number 592 592 593 -Offset station number relative to //addr //station number 594 - 595 595 **Parameters:** 596 596 597 597 //addr//: address ... ... @@ -604,12 +604,10 @@ 604 604 605 605 Failed: multi 606 606 607 -== ** 2.21addr_gethex64(string addr[, number type, number hlword])** ==562 +== **addr_gethex64(string addr[, number type, number hlword])** == 608 608 609 -**Function:** 564 +**Function:** Read 64-bit hexadecimal numbers 610 610 611 -Read 64-bit hexadecimal numbers 612 - 613 613 **Parameters:** 614 614 615 615 //addr//: address ... ... @@ -624,12 +624,10 @@ 624 624 625 625 Failed: multi 626 626 627 -== ** 2.22addr_sethex64(string addr, number num[, number type, number hlword])** ==580 +== **addr_sethex64(string addr, number num[, number type, number hlword])** == 628 628 629 -**Function:** 582 +**Function:** Write 64-bit hexadecimal addresses 630 630 631 -Write 64-bit hexadecimal addresses 632 - 633 633 **Parameters:** 634 634 635 635 //addr//: address ... ... @@ -650,11 +650,11 @@ 650 650 651 651 Operations on the serial port such as read, write, etc. must use ':' for full mode calls, ie operations on an open serial object. 652 652 653 -**Serial port name and mode :**604 +**Serial port name and mode** 654 654 655 655 The serial port configured in the communication configuration window cannot be configured again using the script. RS232 and RS458 (or RS422) can be used simultaneously, but RS422 and RS485 are mutually exclusive.For example, when the communication port is configured with COM1-485, the script can only open COM1-232, but not COM1-485/422. Similarly, when the communication port is configured with COM2-485, the script can only open COM2-232, but not COM2-485. 656 656 657 -Attempting to use a script to open a serial port in an unsupported mode will result in an error directly, as below 608 +Attempting to use a script to open a serial port in an unsupported mode will result in an error directly, as below. 658 658 659 659 |((( 660 660 local setup = { ... ... @@ -676,13 +676,11 @@ 676 676 1. When the data bit is 8, the maximum value of data transmission is 255 (0xFF), which supports the transmission of any character. 677 677 678 678 ((( 679 -== ** 3.1serial.open(table setup)** ==630 +== **serial.open(table setup)** == 680 680 ))) 681 681 682 -**Function:** 633 +**Function:** Enable one serial port 683 683 684 -Enable one serial port 685 - 686 686 **Parameters:** 687 687 688 688 //Setup// is a Lua table; it needs to contain the following fields ... ... @@ -716,17 +716,13 @@ 716 716 Failed: multi 717 717 718 718 ((( 719 -== ** 3.2serial.close(serial obj)** ==668 +== **serial.close(serial obj)** == 720 720 ))) 721 721 722 -**Function:** 671 +**Function:** Disable the serial port 723 723 724 - Disable the serialport673 +**Parameters: **//Obj //is the object returned by serial.open 725 725 726 -**Parameters:** 727 - 728 -//Obj //is the object returned by serial.open 729 - 730 730 **Return:** 731 731 732 732 Succeed: true ... ... @@ -734,13 +734,11 @@ 734 734 Failed: multi 735 735 736 736 ((( 737 -== ** 3.3serial:read(number bytes[, number timeout])** ==682 +== **serial:read(number bytes[, number timeout])** == 738 738 ))) 739 739 740 -**Function:** 685 +**Function:** Read the specified byte length serial port data 741 741 742 -Read the specified byte length serial port data 743 - 744 744 **Parameters:** 745 745 746 746 //bytes//: number of bytes ... ... @@ -754,15 +754,13 @@ 754 754 Failed: multi 755 755 756 756 ((( 757 -== ** 3.4serial:write(string data)** ==700 +== **serial:write(string data)** == 758 758 ))) 759 759 760 -**Function:** 703 +**Function:** Write the specified byte length to serial port data 761 761 762 - Writehepecifiedbyte length to serial port data705 +**Parameters: ** 763 763 764 -**Parameters:** 765 - 766 766 //data//: serial port data 767 767 768 768 **Return:** ... ... @@ -772,13 +772,11 @@ 772 772 Failed: multi 773 773 774 774 ((( 775 -== ** 3.5serial:flush([number flag])** ==716 +== **serial:flush([number flag])** == 776 776 ))) 777 777 778 -**Function:** 719 +**Function:** Clear the serial port buffer 779 779 780 -Clear the serial port buffer 781 - 782 782 **Parameters:** 783 783 784 784 //[flag=2]// clear option: 0: read, 1: write, 2: read-write ... ... @@ -790,17 +790,13 @@ 790 790 Failed: multi 791 791 792 792 ((( 793 -== ** 3.6serial:close()** ==732 +== **serial:close()** == 794 794 ))) 795 795 796 -**Function:** 735 +**Function:** Close the serial port object 797 797 798 - Closeheserial port object737 +**Parameters:** None 799 799 800 -**Parameters:** 801 - 802 -None 803 - 804 804 **Return:** 805 805 806 806 Succeed: true ... ... @@ -817,12 +817,10 @@ 817 817 818 818 **QoS value:** 819 819 820 -0: Only push messages once, messages may be lost or duplicated. It can be used for environmental sensor data, it doesn't matter if lose a record, because there will be a second push message soon. This method is mainly used for normal APP push, but if the user smart device is not connected when the message is pushed, the message will be discarded, and the smart device will not be received when it is networked again. 755 +* 0: Only push messages once, messages may be lost or duplicated. It can be used for environmental sensor data, it doesn't matter if lose a record, because there will be a second push message soon. This method is mainly used for normal APP push, but if the user smart device is not connected when the message is pushed, the message will be discarded, and the smart device will not be received when it is networked again. 756 +* 1: The message is delivered at least once, but the message may be delivered repeatedly. 757 +* 2: The message was delivered exactly once. This level can be used in a billing system. In a billing system, repeated or missing messages can lead to incorrect results. This highest quality message push service can also be used for instant messaging APP pushes, ensuring that users only receive messages once. 821 821 822 -1: The message is delivered at least once, but the message may be delivered repeatedly. 823 - 824 -2: The message was delivered exactly once. This level can be used in a billing system. In a billing system, repeated or missing messages can lead to incorrect results. This highest quality message push service can also be used for instant messaging APP pushes, ensuring that users only receive messages once. 825 - 826 826 **Retain flag:** 827 827 828 828 0: not reserved; ... ... @@ -830,13 +830,11 @@ 830 830 1: reserved 831 831 832 832 ((( 833 -== ** 4.1mqtt.create(string serverurl, string clientid)** ==766 +== **mqtt.create(string serverurl, string clientid)** == 834 834 ))) 835 835 836 -**Function:** 769 +**Function:** Create an MQTT object 837 837 838 -Create an MQTT object 839 - 840 840 **Parameters:** 841 841 842 842 //serverurl //Server url ... ... @@ -858,17 +858,13 @@ 858 858 Failed: multi 859 859 860 860 ((( 861 -== ** 4.2mqtt.close(mqtt obj)** ==792 +== **mqtt.close(mqtt obj)** == 862 862 ))) 863 863 864 -**Function:** 795 +**Function:** Close the specified MQTT object (if the connected server will be disconnected automatically) 865 865 866 - ClosehepecifiedMQTT object(iftheconnectedserverwill be disconnectedautomatically)797 +**Parameters: **//Obj //is the objeced returned by mqtt.create 867 867 868 -**Parameters:** 869 - 870 -//Obj //is the objeced returned by mqtt.create 871 - 872 872 **Return:** 873 873 874 874 Succeed: true ... ... @@ -876,32 +876,25 @@ 876 876 Failed: multi 877 877 878 878 ((( 879 -== ** 4.3mqtt:connect(table conn[, table lwt, table cart])** ==806 +== **mqtt:connect(table conn[, table lwt, table cart])** == 880 880 ))) 881 881 882 -**Function:** 809 +**Function:**Establish a connection to the server 883 883 884 -Establish a connection to the server 885 - 886 886 **Parameters:** 887 887 888 888 //conn //is a Lua table and needs to contain the following fields 889 889 890 -//string conn.username//, user name 815 +* //string conn.username//, user name 816 +* //string conn.password//, password 817 +* //number [conn.netway=0]//, networking method, if set error number will use Ethernet method 818 +** 0: Ethernet 819 +** 1: WIFI 820 +** 2: 4G 821 +** 3: 2G 822 +* //number [conn.keepalive=60]//, keep connected heartbeat interval, in seconds 823 +* //number [conn.cleansession=1]//, empty the session as described below: 891 891 892 -//string conn.password//, password 893 - 894 -//number [conn.netway=0]//, networking method, if set error number will use Ethernet method 895 - 896 -* 0: Ethernet 897 -* 1: WIFI 898 -* 2: 4G 899 -* 3: 2G 900 - 901 -//number [conn.keepalive=60]//, keep connected heartbeat interval, in seconds 902 - 903 -//number [conn.cleansession=1]//, empty the session as described below: 904 - 905 905 This function is used to control the behavior when connecting and disconnecting, and the client and server will retain the session information. This information is used to guarantee "at least once" and "accurately once" delivery, as well as the subject of the client subscription, the user can choose to keep or ignore the session message, set as follows: 906 906 907 907 * 1 (Empty): If a session exists and is 1, the previous session messages on the client and server are emptied. ... ... @@ -909,14 +909,11 @@ 909 909 910 910 //lwt// (Last Will and Testament) is a Lua table and needs to contain the following fields 911 911 912 -//string lwt.topic//, topic 832 +* //string lwt.topic//, topic 833 +* //string lwt.message//, message 834 +* //number [lwt.qos=0]//, qos value 835 +* //number [lwt.retain=0]//, retain flag 913 913 914 -//string lwt.message//, message 915 - 916 -//number [lwt.qos=0]//, qos value 917 - 918 -//number [lwt.retain=0]//, retain flag 919 - 920 920 **Return:** 921 921 922 922 Succeed: true ... ... @@ -924,17 +924,13 @@ 924 924 Failed: multi 925 925 926 926 ((( 927 -== ** 4.4mqtt:disconnect([number timeout])** ==844 +== **mqtt:disconnect([number timeout])** == 928 928 ))) 929 929 930 -**Function:** 847 +**Function:** Disconnect from the MQTT server 931 931 932 -Disconnect fromtheMQTTserver849 +**Parameters: **//[timeout=10000] //Disconnect waiting timeout, in milliseconds 933 933 934 -**Parameters:** 935 - 936 -//[timeout=10000] //Disconnect waiting timeout, in milliseconds 937 - 938 938 **Return:** 939 939 940 940 Succeed: true ... ... @@ -942,17 +942,13 @@ 942 942 Failed: multi 943 943 944 944 ((( 945 -== ** 4.5mqtt:isconnected()** ==858 +== **mqtt:isconnected()** == 946 946 ))) 947 947 948 -**Function:** 861 +**Function:** Test whether or not a client is currently connected to the MQTT server 949 949 950 - Test whetheror notaclientis currently connectedto the MQTT server863 +**Parameters:** None 951 951 952 -**Parameters:** 953 - 954 -None 955 - 956 956 **Return:** 957 957 958 958 Succeed: true ~-~-Connected ... ... @@ -960,13 +960,11 @@ 960 960 Failed: false ~-~- Unconnected and other unknowns 961 961 962 962 ((( 963 -== ** 4.6mqtt:subscribe(string topic, number qos)** ==872 +== **mqtt:subscribe(string topic, number qos)** == 964 964 ))) 965 965 966 -**Function:** 875 +**Function: **Subscribe to the topic (before the subscription, the user must first call the connect method to connect to the server) 967 967 968 -Subscribe to the topic (before the subscription, the user must first call the connect method to connect to the server) 969 - 970 970 **Parameters:** 971 971 972 972 //topic//, topic name ... ... @@ -980,13 +980,11 @@ 980 980 Failed: multi 981 981 982 982 ((( 983 -== ** 4.7mqtt:unsubscribe(string topic)** ==890 +== **mqtt:unsubscribe(string topic)** == 984 984 ))) 985 985 986 -**Function:** 893 +**Function:** Unsubscribe topic 987 987 988 -Unsubscribe topic 989 - 990 990 **Parameters:** 991 991 992 992 //topic//, topic name ... ... @@ -998,13 +998,11 @@ 998 998 Failed: multi 999 999 1000 1000 ((( 1001 -== ** 4.8mqtt:publish(string topic, string message, number qos, number retain[, number timeout])** ==906 +== **mqtt:publish(string topic, string message, number qos, number retain[, number timeout])** == 1002 1002 ))) 1003 1003 1004 -**Function:** 909 +**Function:** Publish message 1005 1005 1006 -Publish message 1007 - 1008 1008 **Parameters:** 1009 1009 1010 1010 //topic//, topic name ... ... @@ -1024,17 +1024,13 @@ 1024 1024 Failed: multi 1025 1025 1026 1026 ((( 1027 -== ** 4.9mqtt:close()** ==930 +== **mqtt:close()** == 1028 1028 ))) 1029 1029 1030 -**Function:** 933 +**Function:** Close the mqtt object (the connection to the server will be automatically disconnected) 1031 1031 1032 - Close themqtt object(theconnection to the server will be automatically disconnected)935 +**Parameters:** None 1033 1033 1034 -**Parameters:** 1035 - 1036 -None 1037 - 1038 1038 **Return:** 1039 1039 1040 1040 Succeed: true ... ... @@ -1042,13 +1042,11 @@ 1042 1042 Failed: multi 1043 1043 1044 1044 ((( 1045 -== ** 4.10mqtt:on(string method, function callback)** ==944 +== **mqtt:on(string method, function callback)** == 1046 1046 ))) 1047 1047 1048 -**Function:** 947 +**Function:** Register event callback function 1049 1049 1050 -Register event callback function 1051 - 1052 1052 **Parameters:** 1053 1053 1054 1054 //method//, It can be message/arrived/offline, these 3 types of events ... ... @@ -1061,20 +1061,17 @@ 1061 1061 1062 1062 Parameter: 1063 1063 1064 -//Topic//, topic name 961 +* //Topic//, topic name 962 +* //Message//, content 1065 1065 1066 - //Message//, content964 +**2."arrived" is published by publish, this function will be called after the publication arrives** 1067 1067 1068 -**2.**"arrived" is published by publish, this function will be called after the publication arrives 1069 - 1070 1070 //Callback// prototype~:// function ()// 1071 1071 1072 -Parameter: 968 +Parameter: None 1073 1073 1074 - None970 +**3.This function will be called after the "offline" connection is lost** 1075 1075 1076 -**3.**This function will be called after the "offline" connection is lost 1077 - 1078 1078 //Callback// prototype~:// function (string cause)// 1079 1079 1080 1080 Parameter: ... ... @@ -1088,17 +1088,13 @@ 1088 1088 Failed: multi 1089 1089 1090 1090 ((( 1091 -== ** 4.11mqtt:setup_cfg()** ==985 +== **mqtt:setup_cfg()** == 1092 1092 ))) 1093 1093 1094 -**Function:** 988 +**Function:** Cloud mode interface, to obtain MQTT information configured by the cloud platform 1095 1095 1096 - Cloudmodeinterface, toobtainMQTT information configured by the cloud platform990 +**Parameters:** None 1097 1097 1098 -**Parameters:** 1099 - 1100 -None 1101 - 1102 1102 **Return:** 1103 1103 1104 1104 //serverurl, clientid, conn, lwt, cart //(5 returns, respectively, server address, client ID, connection table, last word table, certificate table) ... ... @@ -1116,39 +1116,27 @@ 1116 1116 Lua only has a table data structure, so all arrays and key-value objects of json will be returned as a table. 1117 1117 1118 1118 ((( 1119 -== ** 5.1json.encode( lua_object )** ==1009 +== **json.encode( lua_object )** == 1120 1120 ))) 1121 1121 1122 -**Function:** 1012 +**Function: **Convert lua data type to json string 1123 1123 1124 - Convertlua data typetojson string1014 +**Parameters: **Lua data type (including boolean, number, string, table) 1125 1125 1126 -** Parameters:**1016 +**Return:** Json format string 1127 1127 1128 -Lua data type (including boolean, number, string, table) 1129 - 1130 -**Return:** 1131 - 1132 -Json format string 1133 - 1134 1134 ((( 1135 -== ** 5.2json.decode(string json_string)** ==1019 +== **json.decode(string json_string)** == 1136 1136 ))) 1137 1137 1138 -**Function:** 1022 +**Function:** Convert json string to lua data type 1139 1139 1140 - Convert jsonluadata type1024 +**Parameters: **//json_string//, string of json data structure 1141 1141 1142 -** Parameters:**1026 +**Return: **Lua data type 1143 1143 1144 -//json_string//, string of json data structure 1145 - 1146 -**Return:** 1147 - 1148 -Lua data type 1149 - 1150 1150 ((( 1151 -== ** 5.3json.null** ==1029 +== **json.null** == 1152 1152 ))) 1153 1153 1154 1154 **Function:** ... ... @@ -1155,32 +1155,24 @@ 1155 1155 1156 1156 This method is used when assembling json data, which is equivalent to null in json. If the user directly uses json.null() to return the address of the function, it must be valid with the use of encode. 1157 1157 1158 -**Parameters:** 1036 +**Parameters:** None 1159 1159 1160 -None 1038 +**Return: **None 1161 1161 1162 -**Return:** 1163 - 1164 -None 1165 - 1166 1166 = **6 Cloud mode** = 1167 1167 1168 1168 The cloud interface is only used in cloud mode, and V-NET mode is not available. 1169 1169 1170 1170 ((( 1171 -== ** 6.1bns_get_alldata()** ==1045 +== **bns_get_alldata()** == 1172 1172 ))) 1173 1173 1174 -**Function:** 1048 +**Function:** Obtain all monitoring points (point table) data configured by the end user 1175 1175 1176 - Obtain allmonitoringpoints(point table)dataconfiguredbythe enduser1050 +**✎Note: **Assuming there are timing scripts A and B with a period of 1 second, if this function is called in script A, the data will not be obtained if called in script B 1177 1177 1178 - Note: Assuming thereareiming scripts A and B with a period of 1second, if this function is called in script A, the data will not be obtained if called in script B1052 +**Parameters:** None 1179 1179 1180 -**Parameters:** 1181 - 1182 -None 1183 - 1184 1184 **Return:** 1185 1185 1186 1186 Succeed: table two-dimensional array, the structure is as follows ... ... @@ -1210,13 +1210,11 @@ 1210 1210 Failed: //table// empty table 1211 1211 1212 1212 ((( 1213 -== ** 6.2bns_get_config(string from)** ==1083 +== **bns_get_config(string from)** == 1214 1214 ))) 1215 1215 1216 -**Function:** 1086 +**Function:** Obtain custom configuration parameters with the specified from type 1217 1217 1218 -Obtain custom configuration parameters with the specified from type 1219 - 1220 1220 **parameter:** 1221 1221 1222 1222 from type, there are the following two categories, the string must be all lowercase ... ... @@ -1234,13 +1234,11 @@ 1234 1234 Failed~:// table// empty table 1235 1235 1236 1236 ((( 1237 -== ** 6.3bns_get_data(string name, string data)** ==1105 +== **bns_get_data(string name, string data)** == 1238 1238 ))) 1239 1239 1240 -**Function:** 1108 +**Function:**write data to the name of the monitoring point 1241 1241 1242 -write data to the name of the monitoring point 1243 - 1244 1244 **parameter:** 1245 1245 1246 1246 //name //The name of the monitoring point ... ... @@ -1254,7 +1254,7 @@ 1254 1254 Failed: nil 1255 1255 1256 1256 ((( 1257 -== ** 6.4bns_get_data(string name)** ==1123 +== **bns_get_data(string name)** == 1258 1258 ))) 1259 1259 1260 1260 **Function:** ... ... @@ -1272,17 +1272,13 @@ 1272 1272 Failed: nil 1273 1273 1274 1274 ((( 1275 -== ** 6.5bns_get_datadesc()** ==1141 +== **bns_get_datadesc()** == 1276 1276 ))) 1277 1277 1278 -**Function:** 1144 +**Function: **Obtain all configured communication ports and monitoring point information 1279 1279 1280 - Obtain all configured communication portsand monitoring point information1146 +**Parameters:** None 1281 1281 1282 -**Parameters:** 1283 - 1284 -None 1285 - 1286 1286 **Return:** 1287 1287 1288 1288 Succeed: table three-dimensional array, the structure is as follows ... ... @@ -1335,17 +1335,13 @@ 1335 1335 Failed~:// table// empty table 1336 1336 1337 1337 ((( 1338 -== ** 6.6bns_get_machineinfo()** ==1200 +== **bns_get_machineinfo()** == 1339 1339 ))) 1340 1340 1341 -**Function:** 1203 +**Function:** get machine information 1342 1342 1343 - get machine information1205 +**Parameters:** None 1344 1344 1345 -**Parameters:** 1346 - 1347 -None 1348 - 1349 1349 **Return:** 1350 1350 1351 1351 Succeed: 3 string type results (model, machine code, software version) ... ... @@ -1353,13 +1353,11 @@ 1353 1353 Failed: nil 1354 1354 1355 1355 ((( 1356 -== ** 6.7bns_get_groupdata(string name)** ==1214 +== **bns_get_groupdata(string name)** == 1357 1357 ))) 1358 1358 1359 -**Function:** 1217 +**Function:** Get all monitoring point data under the specified group name 1360 1360 1361 -Get all monitoring point data under the specified group name 1362 - 1363 1363 **parameter:** 1364 1364 1365 1365 //Name // group name ... ... @@ -1371,17 +1371,13 @@ 1371 1371 Failed: //table// empty table 1372 1372 1373 1373 ((( 1374 -== ** 6.8bns_get_groupdesc()** ==1230 +== **bns_get_groupdesc()** == 1375 1375 ))) 1376 1376 1377 -**Function:** 1233 +**Function:** Get all group information 1378 1378 1379 - Getall group information1235 +**Parameters:** None 1380 1380 1381 -**Parameters:** 1382 - 1383 -None 1384 - 1385 1385 **Return:** 1386 1386 1387 1387 Succeed: //table// two-dimensional array, the structure is as follows ... ... @@ -1395,17 +1395,13 @@ 1395 1395 Failed: //table // empty table 1396 1396 1397 1397 ((( 1398 -== ** 6.9bns_get_onecache(string msg)** ==1250 +== **bns_get_onecache(string msg)** == 1399 1399 ))) 1400 1400 1401 -**Function:** 1253 +**Function:** Save a message to the cache file, which can be stored after power failure. Store up to 2000 items, delete the old and save the new in a rolling manner when it is full. 1402 1402 1403 - Saveassageto thecache file, which can be storedafter power failure. Store up to 2000 items,delete the old and save the new in arollingmanner when it is full.1255 +**Parameters: **//msg// String 1404 1404 1405 -**Parameters:** 1406 - 1407 -//msg// String 1408 - 1409 1409 **Return:** 1410 1410 1411 1411 Succeed: true ... ... @@ -1413,17 +1413,13 @@ 1413 1413 Failed: nil 1414 1414 1415 1415 ((( 1416 -== ** 6.10bns_get_allcache()** ==1264 +== **bns_get_allcache()** == 1417 1417 ))) 1418 1418 1419 -**Function:** 1267 +**Function:** Get all the cached content (once the internal cache file will be emptied) 1420 1420 1421 - Getall the cached content (oncethe internal cache file will be emptied)1269 +**Parameters:** None 1422 1422 1423 -**Parameters:** 1424 - 1425 -None 1426 - 1427 1427 **Return:** 1428 1428 1429 1429 Succeed: //table// one-dimensional array ... ... @@ -1451,11 +1451,55 @@ 1451 1451 Network communication includes Http request interface, this document does not provide interface description, please refer to the online document for how to use it. 1452 1452 1453 1453 ((( 1454 -== ** 7.1http request** ==1298 +== **http request** == 1455 1455 ))) 1456 1456 1457 1457 [[http:~~/~~/w3.impa.br/~~~~diego/software/luasocket/http.html#request>>url:http://w3.impa.br/~~diego/software/luasocket/http.html#request]] 1458 1458 1303 +== https request == 1304 + 1305 +Example: 1306 + 1307 +local json = require("json") 1308 + 1309 +local https = require("https") 1310 + 1311 +functions https_demo.main() 1312 + 1313 +local url = "https:~/~/XXXXXXXXXXXXXXXXXXXXXXXXXX" 1314 + 1315 +local body = {} 1316 + 1317 +body["XXXXXX"] = "XXXXX" 1318 + 1319 +body["XXXXXXX"] = "XXXXXXXXXXX" 1320 + 1321 +local bodyJson = json.encode(body) 1322 + 1323 +local header = {} 1324 + 1325 +header["content-type"] = "application/json" 1326 + 1327 +local result_table, code, headers, status = https.request(url, 1328 + 1329 +bodyJson) 1330 + 1331 +if code == 200 then 1332 + 1333 +print("https suc") 1334 + 1335 +return true 1336 + 1337 +else 1338 + 1339 +print("https fail") 1340 + 1341 +return nil 1342 + 1343 +end 1344 + 1345 +end 1346 + 1459 1459 ((( 1460 1460 = **8 Internal register** = 1461 1461 )))