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
-
... ... @@ -106,8 +106,6 @@ 106 106 107 107 ((( 108 108 = **2 Address operation** = 109 - 110 - 111 111 ))) 112 112 113 113 |=16-bit data formal|=HLword|=32-bit data formal|=HLword|= 64-bit data formal|=HLword ... ... @@ -140,20 +140,17 @@ 140 140 43218765 141 141 )))|10 142 142 143 - *If HLword entersany other value,it will be treated as invalid.141 + Table 2-1 144 144 145 - 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 +))) 146 146 148 +== **addr_getshort(string addr[, number type, number hlword])** == 147 147 150 +**Function:** Read 16-bit signed decimal address 148 148 149 -[[image:企业微信截图_20210506180640.png||height="301" width="600" class="img-thumbnail"]] 150 - 151 -== **2.1 addr_getshort(string addr[, number type, number hlword])** == 152 - 153 -**Function:** 154 - 155 -Read 16-bit signed decimal address 156 - 157 157 **Parameters:** 158 158 159 159 //addr//: address ... ... @@ -171,13 +171,11 @@ 171 171 Failed: multi 172 172 173 173 ((( 174 -== ** 2.2addr_setshort(string addr, number num[, number type, number hlword])** ==169 +== **addr_setshort(string addr, number num[, number type, number hlword])** == 175 175 ))) 176 176 177 -**Function:** 172 +**Function:** Write 16-bit signed decimal address 178 178 179 -Write 16-bit signed decimal address 180 - 181 181 **Parameters:** 182 182 183 183 //addr//: address ... ... @@ -195,13 +195,11 @@ 195 195 Failed: multi 196 196 197 197 ((( 198 -== ** 2.3addr_getword(string addr[, number type, number hlword])** ==191 +== **addr_getword(string addr[, number type, number hlword])** == 199 199 ))) 200 200 201 -**Function:** 194 +**Function:** Read 16-bit unsigned decimal address 202 202 203 -Read 16-bit unsigned decimal address 204 - 205 205 **Parameters:** 206 206 207 207 //addr//: address ... ... @@ -217,13 +217,11 @@ 217 217 Failed: multi 218 218 219 219 ((( 220 -== ** 2.4addr_setword(string addr, number num[, number type, number hlword])** ==211 +== **addr_setword(string addr, number num[, number type, number hlword])** == 221 221 ))) 222 222 223 -**Function:** 214 +**Function:**Write 16-bit unsigned decimal address 224 224 225 -Write 16-bit unsigned decimal address 226 - 227 227 **Parameters:** 228 228 229 229 //addr//: address ... ... @@ -241,13 +241,11 @@ 241 241 Failed: multi 242 242 243 243 ((( 244 -== ** 2.5addr_getint(string addr[, number type, number hlword])** ==233 +== **addr_getint(string addr[, number type, number hlword])** == 245 245 ))) 246 246 247 -**Function:** 236 +**Function:** Read 32-bit signed decimal address 248 248 249 -Read 32-bit signed decimal address 250 - 251 251 **Parameters:** 252 252 253 253 //addr//: address ... ... @@ -263,13 +263,11 @@ 263 263 Failed: multi 264 264 265 265 ((( 266 -== ** 2.6addr_setint(string addr, number num[, number type, number hlword])** ==253 +== **addr_setint(string addr, number num[, number type, number hlword])** == 267 267 ))) 268 268 269 -**Function:** 256 +**Function:** Write 32-bit signed decimal address 270 270 271 -Write 32-bit signed decimal address 272 - 273 273 **Parameters:** 274 274 275 275 //addr//: address ... ... @@ -287,13 +287,11 @@ 287 287 Failed: multi 288 288 289 289 ((( 290 -== ** 2.7addr_getdword(string addr[, number type, number hlword])** ==275 +== **addr_getdword(string addr[, number type, number hlword])** == 291 291 ))) 292 292 293 -**Function:** 278 +**Function:** Read 32-bit unsigned decimal address 294 294 295 -Read 32-bit unsigned decimal address 296 - 297 297 **Parameters:** 298 298 299 299 //addr//: address ... ... @@ -309,13 +309,11 @@ 309 309 Failed: multi 310 310 311 311 ((( 312 -== ** 2.8addr_setdword(string addr, number num[, number type, number hlword])** ==295 +== **addr_setdword(string addr, number num[, number type, number hlword])** == 313 313 ))) 314 314 315 -**Function:** 298 +**Function:** Write 32-bit unsigned decimal address 316 316 317 -Write 32-bit unsigned decimal address 318 - 319 319 **Parameters:** 320 320 321 321 //addr//: address ... ... @@ -333,13 +333,11 @@ 333 333 Failed: multi 334 334 335 335 ((( 336 -== ** 2.9addr_getbit(string addr[, number type])** ==317 +== **addr_getbit(string addr[, number type])** == 337 337 ))) 338 338 339 -**Function:** 320 +**Function:** Read a bit of the register address 340 340 341 -Read a bit of the register address 342 - 343 343 **Parameters:** 344 344 345 345 //addr//: address ... ... @@ -355,13 +355,11 @@ 355 355 Failed: multi 356 356 357 357 ((( 358 -== ** 2.10addr_setbit(string addr, number num[, number type])** ==337 +== **addr_setbit(string addr, number num[, number type])** == 359 359 ))) 360 360 361 -**Function:** 340 +**Function:** Write a bit of the register address 362 362 363 -Write a bit of the register address 364 - 365 365 **Parameters:** 366 366 367 367 //addr//: address ... ... @@ -379,13 +379,11 @@ 379 379 Failed: multi 380 380 381 381 ((( 382 -== ** 2.11addr_getfloat(string addr[, number type, number hlword])** ==359 +== **addr_getfloat(string addr[, number type, number hlword])** == 383 383 ))) 384 384 385 -**Function:** 362 +**Function:** Read 32-bit floating address 386 386 387 -Read 32-bit floating address 388 - 389 389 **Parameters:** 390 390 391 391 //addr//: address ... ... @@ -401,13 +401,11 @@ 401 401 Failed: multi 402 402 403 403 ((( 404 -== ** 2.12addr_setfloat(string addr, number num[, number type, number hlword])** ==379 +== **addr_setfloat(string addr, number num[, number type, number hlword])** == 405 405 ))) 406 406 407 -**Function:** 382 +**Function:** Write 32-bit floating address 408 408 409 -Write 32-bit floating address 410 - 411 411 **Parameters:** 412 412 413 413 //addr//: address ... ... @@ -425,13 +425,11 @@ 425 425 Failed: multi 426 426 427 427 ((( 428 -== ** 2.13addr_getdouble(string addr[, number type, number hlword])** ==401 +== **addr_getdouble(string addr[, number type, number hlword])** == 429 429 ))) 430 430 431 -**Function:** 404 +**Function:** Read 64-bit floating address 432 432 433 -Read 64-bit floating address 434 - 435 435 **Parameters:** 436 436 437 437 //addr//: address ... ... @@ -447,13 +447,11 @@ 447 447 Failed: multi 448 448 449 449 ((( 450 -== ** 2.14addr_setdouble(string addr, number num[, number type, number hlword])** ==421 +== **addr_setdouble(string addr, number num[, number type, number hlword])** == 451 451 ))) 452 452 453 -**Function:** 424 +**Function:** Write 64-bit floating address 454 454 455 -Write 64-bit floating address 456 - 457 457 **Parameters:** 458 458 459 459 addr: address ... ... @@ -471,13 +471,11 @@ 471 471 Failed: multi 472 472 473 473 ((( 474 -== ** 2.15addr_getstring(string addr, number length[, number type, number hlbyte])** ==443 +== **addr_getstring(string addr, number length[, number type, number hlbyte])** == 475 475 ))) 476 476 477 -**Function:** 446 +**Function:** Read the specified length string from address 478 478 479 -Read the specified length string from address 480 - 481 481 **Parameters:** 482 482 483 483 //addr//: address ... ... @@ -495,13 +495,11 @@ 495 495 Failed: multi 496 496 497 497 ((( 498 -== ** 2.16addr_setstring(string addr, string str[, number type, number hlbyte])** ==465 +== **addr_setstring(string addr, string str[, number type, number hlbyte])** == 499 499 ))) 500 500 501 -**Function:** 468 +**Function:** Write the specified length string to address 502 502 503 -Write the specified length string to address 504 - 505 505 **Parameters:** 506 506 507 507 //addr//: address ... ... @@ -519,13 +519,11 @@ 519 519 Failed: multi 520 520 521 521 ((( 522 -== ** 2.17addr_bmov(string dst, string src, number length)** ==487 +== **addr_bmov(string dst, string src, number length)** == 523 523 ))) 524 524 525 -**Function:** 490 +**Function:** Copy data from source address to destination address 526 526 527 -Copy data from source address to destination address 528 - 529 529 **Parameters:** 530 530 531 531 //dst//: destination address ... ... @@ -541,13 +541,11 @@ 541 541 **Failed: multi** 542 542 543 543 ((( 544 -== ** 2.18addr_fill(string addr, number num, number length)** ==507 +== **addr_fill(string addr, number num, number length)** == 545 545 ))) 546 546 547 -**Function:** 510 +**Function:** Write the same value to consecutive addresses 548 548 549 -Write the same value to consecutive addresses 550 - 551 551 **Parameters:** 552 552 553 553 //addr//: address ... ... @@ -563,13 +563,11 @@ 563 563 Failed: multi 564 564 565 565 ((( 566 -== ** 2.19addr_newnoaddr(string addr, number offset)** ==527 +== **addr_newnoaddr(string addr, number offset)** == 567 567 ))) 568 568 569 -**Function:** 530 +**Function:** Offset address value relative to //addr// 570 570 571 -Offset address value relative to //addr// 572 - 573 573 **Parameters:** 574 574 575 575 //addr//: address ... ... @@ -583,13 +583,11 @@ 583 583 Failed: multi 584 584 585 585 ((( 586 -== ** 2.20addr_newstataddr(string addr, number offset)** ==545 +== **addr_newstataddr(string addr, number offset)** == 587 587 ))) 588 588 589 -**Function:** 548 +**Function:** Offset station number relative to //addr //station number 590 590 591 -Offset station number relative to //addr //station number 592 - 593 593 **Parameters:** 594 594 595 595 //addr//: address ... ... @@ -602,12 +602,10 @@ 602 602 603 603 Failed: multi 604 604 605 -== ** 2.21addr_gethex64(string addr[, number type, number hlword])** ==562 +== **addr_gethex64(string addr[, number type, number hlword])** == 606 606 607 -**Function:** 564 +**Function:** Read 64-bit hexadecimal numbers 608 608 609 -Read 64-bit hexadecimal numbers 610 - 611 611 **Parameters:** 612 612 613 613 //addr//: address ... ... @@ -622,12 +622,10 @@ 622 622 623 623 Failed: multi 624 624 625 -== ** 2.22addr_sethex64(string addr, number num[, number type, number hlword])** ==580 +== **addr_sethex64(string addr, number num[, number type, number hlword])** == 626 626 627 -**Function:** 582 +**Function:** Write 64-bit hexadecimal addresses 628 628 629 -Write 64-bit hexadecimal addresses 630 - 631 631 **Parameters:** 632 632 633 633 //addr//: address ... ... @@ -648,11 +648,11 @@ 648 648 649 649 Operations on the serial port such as read, write, etc. must use ':' for full mode calls, ie operations on an open serial object. 650 650 651 -**Serial port name and mode :**604 +**Serial port name and mode** 652 652 653 653 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. 654 654 655 -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. 656 656 657 657 |((( 658 658 local setup = { ... ... @@ -674,13 +674,11 @@ 674 674 1. When the data bit is 8, the maximum value of data transmission is 255 (0xFF), which supports the transmission of any character. 675 675 676 676 ((( 677 -== ** 3.1serial.open(table setup)** ==630 +== **serial.open(table setup)** == 678 678 ))) 679 679 680 -**Function:** 633 +**Function:** Enable one serial port 681 681 682 -Enable one serial port 683 - 684 684 **Parameters:** 685 685 686 686 //Setup// is a Lua table; it needs to contain the following fields ... ... @@ -714,17 +714,13 @@ 714 714 Failed: multi 715 715 716 716 ((( 717 -== ** 3.2serial.close(serial obj)** ==668 +== **serial.close(serial obj)** == 718 718 ))) 719 719 720 -**Function:** 671 +**Function:** Disable the serial port 721 721 722 - Disable the serialport673 +**Parameters: **//Obj //is the object returned by serial.open 723 723 724 -**Parameters:** 725 - 726 -//Obj //is the object returned by serial.open 727 - 728 728 **Return:** 729 729 730 730 Succeed: true ... ... @@ -732,13 +732,11 @@ 732 732 Failed: multi 733 733 734 734 ((( 735 -== ** 3.3serial:read(number bytes[, number timeout])** ==682 +== **serial:read(number bytes[, number timeout])** == 736 736 ))) 737 737 738 -**Function:** 685 +**Function:** Read the specified byte length serial port data 739 739 740 -Read the specified byte length serial port data 741 - 742 742 **Parameters:** 743 743 744 744 //bytes//: number of bytes ... ... @@ -752,15 +752,13 @@ 752 752 Failed: multi 753 753 754 754 ((( 755 -== ** 3.4serial:write(string data)** ==700 +== **serial:write(string data)** == 756 756 ))) 757 757 758 -**Function:** 703 +**Function:** Write the specified byte length to serial port data 759 759 760 - Writehepecifiedbyte length to serial port data705 +**Parameters: ** 761 761 762 -**Parameters:** 763 - 764 764 //data//: serial port data 765 765 766 766 **Return:** ... ... @@ -770,13 +770,11 @@ 770 770 Failed: multi 771 771 772 772 ((( 773 -== ** 3.5serial:flush([number flag])** ==716 +== **serial:flush([number flag])** == 774 774 ))) 775 775 776 -**Function:** 719 +**Function:** Clear the serial port buffer 777 777 778 -Clear the serial port buffer 779 - 780 780 **Parameters:** 781 781 782 782 //[flag=2]// clear option: 0: read, 1: write, 2: read-write ... ... @@ -788,17 +788,13 @@ 788 788 Failed: multi 789 789 790 790 ((( 791 -== ** 3.6serial:close()** ==732 +== **serial:close()** == 792 792 ))) 793 793 794 -**Function:** 735 +**Function:** Close the serial port object 795 795 796 - Closeheserial port object737 +**Parameters:** None 797 797 798 -**Parameters:** 799 - 800 -None 801 - 802 802 **Return:** 803 803 804 804 Succeed: true ... ... @@ -815,12 +815,10 @@ 815 815 816 816 **QoS value:** 817 817 818 -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. 819 819 820 -1: The message is delivered at least once, but the message may be delivered repeatedly. 821 - 822 -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. 823 - 824 824 **Retain flag:** 825 825 826 826 0: not reserved; ... ... @@ -828,13 +828,11 @@ 828 828 1: reserved 829 829 830 830 ((( 831 -== ** 4.1mqtt.create(string serverurl, string clientid)** ==766 +== **mqtt.create(string serverurl, string clientid)** == 832 832 ))) 833 833 834 -**Function:** 769 +**Function:** Create an MQTT object 835 835 836 -Create an MQTT object 837 - 838 838 **Parameters:** 839 839 840 840 //serverurl //Server url ... ... @@ -856,17 +856,13 @@ 856 856 Failed: multi 857 857 858 858 ((( 859 -== ** 4.2mqtt.close(mqtt obj)** ==792 +== **mqtt.close(mqtt obj)** == 860 860 ))) 861 861 862 -**Function:** 795 +**Function:** Close the specified MQTT object (if the connected server will be disconnected automatically) 863 863 864 - ClosehepecifiedMQTT object(iftheconnectedserverwill be disconnectedautomatically)797 +**Parameters: **//Obj //is the objeced returned by mqtt.create 865 865 866 -**Parameters:** 867 - 868 -//Obj //is the objeced returned by mqtt.create 869 - 870 870 **Return:** 871 871 872 872 Succeed: true ... ... @@ -874,32 +874,25 @@ 874 874 Failed: multi 875 875 876 876 ((( 877 -== ** 4.3mqtt:connect(table conn[, table lwt, table cart])** ==806 +== **mqtt:connect(table conn[, table lwt, table cart])** == 878 878 ))) 879 879 880 -**Function:** 809 +**Function:**Establish a connection to the server 881 881 882 -Establish a connection to the server 883 - 884 884 **Parameters:** 885 885 886 886 //conn //is a Lua table and needs to contain the following fields 887 887 888 -//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: 889 889 890 -//string conn.password//, password 891 - 892 -//number [conn.netway=0]//, networking method, if set error number will use Ethernet method 893 - 894 -* 0: Ethernet 895 -* 1: WIFI 896 -* 2: 4G 897 -* 3: 2G 898 - 899 -//number [conn.keepalive=60]//, keep connected heartbeat interval, in seconds 900 - 901 -//number [conn.cleansession=1]//, empty the session as described below: 902 - 903 903 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: 904 904 905 905 * 1 (Empty): If a session exists and is 1, the previous session messages on the client and server are emptied. ... ... @@ -907,14 +907,11 @@ 907 907 908 908 //lwt// (Last Will and Testament) is a Lua table and needs to contain the following fields 909 909 910 -//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 911 911 912 -//string lwt.message//, message 913 - 914 -//number [lwt.qos=0]//, qos value 915 - 916 -//number [lwt.retain=0]//, retain flag 917 - 918 918 **Return:** 919 919 920 920 Succeed: true ... ... @@ -922,17 +922,13 @@ 922 922 Failed: multi 923 923 924 924 ((( 925 -== ** 4.4mqtt:disconnect([number timeout])** ==844 +== **mqtt:disconnect([number timeout])** == 926 926 ))) 927 927 928 -**Function:** 847 +**Function:** Disconnect from the MQTT server 929 929 930 -Disconnect fromtheMQTTserver849 +**Parameters: **//[timeout=10000] //Disconnect waiting timeout, in milliseconds 931 931 932 -**Parameters:** 933 - 934 -//[timeout=10000] //Disconnect waiting timeout, in milliseconds 935 - 936 936 **Return:** 937 937 938 938 Succeed: true ... ... @@ -940,17 +940,13 @@ 940 940 Failed: multi 941 941 942 942 ((( 943 -== ** 4.5mqtt:isconnected()** ==858 +== **mqtt:isconnected()** == 944 944 ))) 945 945 946 -**Function:** 861 +**Function:** Test whether or not a client is currently connected to the MQTT server 947 947 948 - Test whetheror notaclientis currently connectedto the MQTT server863 +**Parameters:** None 949 949 950 -**Parameters:** 951 - 952 -None 953 - 954 954 **Return:** 955 955 956 956 Succeed: true ~-~-Connected ... ... @@ -958,13 +958,11 @@ 958 958 Failed: false ~-~- Unconnected and other unknowns 959 959 960 960 ((( 961 -== ** 4.6mqtt:subscribe(string topic, number qos)** ==872 +== **mqtt:subscribe(string topic, number qos)** == 962 962 ))) 963 963 964 -**Function:** 875 +**Function: **Subscribe to the topic (before the subscription, the user must first call the connect method to connect to the server) 965 965 966 -Subscribe to the topic (before the subscription, the user must first call the connect method to connect to the server) 967 - 968 968 **Parameters:** 969 969 970 970 //topic//, topic name ... ... @@ -978,13 +978,11 @@ 978 978 Failed: multi 979 979 980 980 ((( 981 -== ** 4.7mqtt:unsubscribe(string topic)** ==890 +== **mqtt:unsubscribe(string topic)** == 982 982 ))) 983 983 984 -**Function:** 893 +**Function:** Unsubscribe topic 985 985 986 -Unsubscribe topic 987 - 988 988 **Parameters:** 989 989 990 990 //topic//, topic name ... ... @@ -996,13 +996,11 @@ 996 996 Failed: multi 997 997 998 998 ((( 999 -== ** 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])** == 1000 1000 ))) 1001 1001 1002 -**Function:** 909 +**Function:** Publish message 1003 1003 1004 -Publish message 1005 - 1006 1006 **Parameters:** 1007 1007 1008 1008 //topic//, topic name ... ... @@ -1022,17 +1022,13 @@ 1022 1022 Failed: multi 1023 1023 1024 1024 ((( 1025 -== ** 4.9mqtt:close()** ==930 +== **mqtt:close()** == 1026 1026 ))) 1027 1027 1028 -**Function:** 933 +**Function:** Close the mqtt object (the connection to the server will be automatically disconnected) 1029 1029 1030 - Close themqtt object(theconnection to the server will be automatically disconnected)935 +**Parameters:** None 1031 1031 1032 -**Parameters:** 1033 - 1034 -None 1035 - 1036 1036 **Return:** 1037 1037 1038 1038 Succeed: true ... ... @@ -1040,13 +1040,11 @@ 1040 1040 Failed: multi 1041 1041 1042 1042 ((( 1043 -== ** 4.10mqtt:on(string method, function callback)** ==944 +== **mqtt:on(string method, function callback)** == 1044 1044 ))) 1045 1045 1046 -**Function:** 947 +**Function:** Register event callback function 1047 1047 1048 -Register event callback function 1049 - 1050 1050 **Parameters:** 1051 1051 1052 1052 //method//, It can be message/arrived/offline, these 3 types of events ... ... @@ -1059,20 +1059,17 @@ 1059 1059 1060 1060 Parameter: 1061 1061 1062 -//Topic//, topic name 961 +* //Topic//, topic name 962 +* //Message//, content 1063 1063 1064 - //Message//, content964 +**2."arrived" is published by publish, this function will be called after the publication arrives** 1065 1065 1066 -**2.**"arrived" is published by publish, this function will be called after the publication arrives 1067 - 1068 1068 //Callback// prototype~:// function ()// 1069 1069 1070 -Parameter: 968 +Parameter: None 1071 1071 1072 - None970 +**3.This function will be called after the "offline" connection is lost** 1073 1073 1074 -**3.**This function will be called after the "offline" connection is lost 1075 - 1076 1076 //Callback// prototype~:// function (string cause)// 1077 1077 1078 1078 Parameter: ... ... @@ -1086,17 +1086,13 @@ 1086 1086 Failed: multi 1087 1087 1088 1088 ((( 1089 -== ** 4.11mqtt:setup_cfg()** ==985 +== **mqtt:setup_cfg()** == 1090 1090 ))) 1091 1091 1092 -**Function:** 988 +**Function:** Cloud mode interface, to obtain MQTT information configured by the cloud platform 1093 1093 1094 - Cloudmodeinterface, toobtainMQTT information configured by the cloud platform990 +**Parameters:** None 1095 1095 1096 -**Parameters:** 1097 - 1098 -None 1099 - 1100 1100 **Return:** 1101 1101 1102 1102 //serverurl, clientid, conn, lwt, cart //(5 returns, respectively, server address, client ID, connection table, last word table, certificate table) ... ... @@ -1114,39 +1114,27 @@ 1114 1114 Lua only has a table data structure, so all arrays and key-value objects of json will be returned as a table. 1115 1115 1116 1116 ((( 1117 -== ** 5.1json.encode( lua_object )** ==1009 +== **json.encode( lua_object )** == 1118 1118 ))) 1119 1119 1120 -**Function:** 1012 +**Function: **Convert lua data type to json string 1121 1121 1122 - Convertlua data typetojson string1014 +**Parameters: **Lua data type (including boolean, number, string, table) 1123 1123 1124 -** Parameters:**1016 +**Return:** Json format string 1125 1125 1126 -Lua data type (including boolean, number, string, table) 1127 - 1128 -**Return:** 1129 - 1130 -Json format string 1131 - 1132 1132 ((( 1133 -== ** 5.2json.decode(string json_string)** ==1019 +== **json.decode(string json_string)** == 1134 1134 ))) 1135 1135 1136 -**Function:** 1022 +**Function:** Convert json string to lua data type 1137 1137 1138 - Convert jsonluadata type1024 +**Parameters: **//json_string//, string of json data structure 1139 1139 1140 -** Parameters:**1026 +**Return: **Lua data type 1141 1141 1142 -//json_string//, string of json data structure 1143 - 1144 -**Return:** 1145 - 1146 -Lua data type 1147 - 1148 1148 ((( 1149 -== ** 5.3json.null** ==1029 +== **json.null** == 1150 1150 ))) 1151 1151 1152 1152 **Function:** ... ... @@ -1153,32 +1153,24 @@ 1153 1153 1154 1154 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. 1155 1155 1156 -**Parameters:** 1036 +**Parameters:** None 1157 1157 1158 -None 1038 +**Return: **None 1159 1159 1160 -**Return:** 1161 - 1162 -None 1163 - 1164 1164 = **6 Cloud mode** = 1165 1165 1166 1166 The cloud interface is only used in cloud mode, and V-NET mode is not available. 1167 1167 1168 1168 ((( 1169 -== ** 6.1bns_get_alldata()** ==1045 +== **bns_get_alldata()** == 1170 1170 ))) 1171 1171 1172 -**Function:** 1048 +**Function:** Obtain all monitoring points (point table) data configured by the end user 1173 1173 1174 - 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 1175 1175 1176 - 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 1177 1177 1178 -**Parameters:** 1179 - 1180 -None 1181 - 1182 1182 **Return:** 1183 1183 1184 1184 Succeed: table two-dimensional array, the structure is as follows ... ... @@ -1208,13 +1208,11 @@ 1208 1208 Failed: //table// empty table 1209 1209 1210 1210 ((( 1211 -== ** 6.2bns_get_config(string from)** ==1083 +== **bns_get_config(string from)** == 1212 1212 ))) 1213 1213 1214 -**Function:** 1086 +**Function:** Obtain custom configuration parameters with the specified from type 1215 1215 1216 -Obtain custom configuration parameters with the specified from type 1217 - 1218 1218 **parameter:** 1219 1219 1220 1220 from type, there are the following two categories, the string must be all lowercase ... ... @@ -1232,13 +1232,11 @@ 1232 1232 Failed~:// table// empty table 1233 1233 1234 1234 ((( 1235 -== ** 6.3bns_get_data(string name, string data)** ==1105 +== **bns_get_data(string name, string data)** == 1236 1236 ))) 1237 1237 1238 -**Function:** 1108 +**Function:**write data to the name of the monitoring point 1239 1239 1240 -write data to the name of the monitoring point 1241 - 1242 1242 **parameter:** 1243 1243 1244 1244 //name //The name of the monitoring point ... ... @@ -1252,7 +1252,7 @@ 1252 1252 Failed: nil 1253 1253 1254 1254 ((( 1255 -== ** 6.4bns_get_data(string name)** ==1123 +== **bns_get_data(string name)** == 1256 1256 ))) 1257 1257 1258 1258 **Function:** ... ... @@ -1270,17 +1270,13 @@ 1270 1270 Failed: nil 1271 1271 1272 1272 ((( 1273 -== ** 6.5bns_get_datadesc()** ==1141 +== **bns_get_datadesc()** == 1274 1274 ))) 1275 1275 1276 -**Function:** 1144 +**Function: **Obtain all configured communication ports and monitoring point information 1277 1277 1278 - Obtain all configured communication portsand monitoring point information1146 +**Parameters:** None 1279 1279 1280 -**Parameters:** 1281 - 1282 -None 1283 - 1284 1284 **Return:** 1285 1285 1286 1286 Succeed: table three-dimensional array, the structure is as follows ... ... @@ -1333,17 +1333,13 @@ 1333 1333 Failed~:// table// empty table 1334 1334 1335 1335 ((( 1336 -== ** 6.6bns_get_machineinfo()** ==1200 +== **bns_get_machineinfo()** == 1337 1337 ))) 1338 1338 1339 -**Function:** 1203 +**Function:** get machine information 1340 1340 1341 - get machine information1205 +**Parameters:** None 1342 1342 1343 -**Parameters:** 1344 - 1345 -None 1346 - 1347 1347 **Return:** 1348 1348 1349 1349 Succeed: 3 string type results (model, machine code, software version) ... ... @@ -1351,13 +1351,11 @@ 1351 1351 Failed: nil 1352 1352 1353 1353 ((( 1354 -== ** 6.7bns_get_groupdata(string name)** ==1214 +== **bns_get_groupdata(string name)** == 1355 1355 ))) 1356 1356 1357 -**Function:** 1217 +**Function:** Get all monitoring point data under the specified group name 1358 1358 1359 -Get all monitoring point data under the specified group name 1360 - 1361 1361 **parameter:** 1362 1362 1363 1363 //Name // group name ... ... @@ -1369,17 +1369,13 @@ 1369 1369 Failed: //table// empty table 1370 1370 1371 1371 ((( 1372 -== ** 6.8bns_get_groupdesc()** ==1230 +== **bns_get_groupdesc()** == 1373 1373 ))) 1374 1374 1375 -**Function:** 1233 +**Function:** Get all group information 1376 1376 1377 - Getall group information1235 +**Parameters:** None 1378 1378 1379 -**Parameters:** 1380 - 1381 -None 1382 - 1383 1383 **Return:** 1384 1384 1385 1385 Succeed: //table// two-dimensional array, the structure is as follows ... ... @@ -1393,17 +1393,13 @@ 1393 1393 Failed: //table // empty table 1394 1394 1395 1395 ((( 1396 -== ** 6.9bns_get_onecache(string msg)** ==1250 +== **bns_get_onecache(string msg)** == 1397 1397 ))) 1398 1398 1399 -**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. 1400 1400 1401 - 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 1402 1402 1403 -**Parameters:** 1404 - 1405 -//msg// String 1406 - 1407 1407 **Return:** 1408 1408 1409 1409 Succeed: true ... ... @@ -1411,17 +1411,13 @@ 1411 1411 Failed: nil 1412 1412 1413 1413 ((( 1414 -== ** 6.10bns_get_allcache()** ==1264 +== **bns_get_allcache()** == 1415 1415 ))) 1416 1416 1417 -**Function:** 1267 +**Function:** Get all the cached content (once the internal cache file will be emptied) 1418 1418 1419 - Getall the cached content (oncethe internal cache file will be emptied)1269 +**Parameters:** None 1420 1420 1421 -**Parameters:** 1422 - 1423 -None 1424 - 1425 1425 **Return:** 1426 1426 1427 1427 Succeed: //table// one-dimensional array ... ... @@ -1449,11 +1449,55 @@ 1449 1449 Network communication includes Http request interface, this document does not provide interface description, please refer to the online document for how to use it. 1450 1450 1451 1451 ((( 1452 -== ** 7.1http request** ==1298 +== **http request** == 1453 1453 ))) 1454 1454 1455 1455 [[http:~~/~~/w3.impa.br/~~~~diego/software/luasocket/http.html#request>>url:http://w3.impa.br/~~diego/software/luasocket/http.html#request]] 1456 1456 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 + 1457 1457 ((( 1458 1458 = **8 Internal register** = 1459 1459 )))