A byte transparent transmission method for IoT based on H5JS local programming

Through H5JS local programming and Tencent Cloud IoT MQTT, full-range byte transparent transmission and two-way communication are realized, solving the problems of interrupt priority and high-speed sampling data transmission in microcontroller programming, simplifying the programming process and improving system stability and efficiency.

CN113824783BActive Publication Date: 2024-12-10HANGZHOU HEXUE EDUCATION TECH CO LTD

Patent Information

Application Number
CN202111098910.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-09-18
Publication Date
2024-12-10
Estimated Expiration
2041-09-18

AI Technical Summary

Technical Problem

Microcontroller programmers encounter difficulties in network programming, especially the problem of interrupt priority setting and data transmission in high-speed sampling systems. Existing scripting languages ​​such as JS and LUA lack effective interrupt priority setting and timing asynchronous execution priority, resulting in Programming is complex and difficult to achieve high-speed timing sampling.

Method used

Using local programming method based on H5JS, the Tencent Cloud Internet of Things MQTT server and Nodemcu module realizes full-range byte transparent transmission, combined with HTML-JS program to run on a mobile phone or computer, simplifying the interrupt priority setting and data transmission. MQTT and UDP protocols conduct two-way communication, and record the working status through the microcontroller's RTC UserMemory or Flash file, splitting the large program into a mini program to solve the problem of insufficient memory.

Benefits of technology

It realizes simplified user programming, reduces programming amount, provides programming examples, solves the problems of interrupt priority and high-speed sampling data transmission, improves the stability and efficiency of the system, and separates the working parameters of the microcontroller from the wireless WIFI connection. Convenient to development and use.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113824783B_ABST
    Figure CN113824783B_ABST
Patent Text Reader

Abstract

The present invention discloses a method for transparent transmission of byte of Internet of Things based on H5JS local programming, fully explores the potential application characteristics of cloud Internet of Things MQTT combined with Nodemcu, and establishes a local operation mode of Html-JS program on a mobile terminal (referring to a mobile phone or a computer) with full-range byte transparent transmission as the basis of network communication. It is proposed that cloud Internet of Things MQTT supplements the direct WeChat and sound alarm functions, and provides a local execution of Internet of Things Html-JS general program, which not only greatly reduces the user programming links, avoids low-level repetition, but also provides programming examples. Because this mode is also particularly suitable for combining with a single-chip microcomputer, and MQTT is not required in a local area network. At the same time, it is also proposed that the Nodemcu program migrates to JS or realizes program minimization through reset, as well as high-speed timing sampling, and uses a single-chip microcomputer combined with ESP-12 to batch and centrally transmit data to a mobile terminal mode connected to wifi. Such a streamlined and complete Internet of Things, from local area network to wide area network, from computer mobile phone connection to single-chip microcomputer to send WeChat, adopts mainstream technology, and is very suitable for use as a unified textbook of Internet of Things for colleges and universities.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention belongs to the field of computer network communication control, and in particular relates to an Internet of Things byte transparent transmission method based on H5JS local programming. Background Art

[0002] Many MCU programmers are not familiar with network programming and hope to have a simple and convenient way to integrate with the Internet of Things. This does not mean that network programming is more difficult or more complicated, but it means that it is not easy to learn network programming. Even if you try to avoid back-end programming and identify a language according to the ideas of this article, there are still many traps, and even very basic questions will not be answered. For example, the JS scripting language or the Nodemcu LUA scripting language cannot find the (interrupt) priority setting of program execution (the execution order setting of a large number of asynchronous processing programs in JS, including ES6's Promise, actually only refers to the execution order setting of the startup program, not that the low-priority program can be interrupted by the high-priority program during execution. The same is true for Nodemcu LUA. Its node.task.post() priority setting module cannot find any information about interrupt priority setting). And this interrupt priority setting is very critical in high-speed sampling and batch centralized data transmission systems. What is even more inconvenient is that the priority of the scheduled asynchronous execution program in the commonly used scripting languages ​​(including JS and Nodemcu LUA) is always the lowest, which poses a problem for high-speed timed sampling. To this end, this project explores the byte-transmitting communication method and finds a solution by locally executing Html-JS programs combined with microcontrollers. Summary of the invention

[0003] Based on the above background technology, the present invention provides an Internet of Things byte transparent transmission method based on H5JS local programming.

[0004] According to an embodiment of the present invention, a method for transparent transmission of IoT bytes based on H5JS local programming is provided. The method is implemented on an IoT structure, and an Html-JS local program is run on a mobile phone or computer. The method for transparent transmission of IoT bytes includes the following steps:

[0005] (1) For the Internet Wide Area Network, an Internet of Things structure is constructed, wherein the Internet of Things structure includes: a Tencent Cloud Internet of Things MQTT server, a node module, a mobile phone and / or a computer, wherein the node module and the mobile phone and / or the computer are all connected to the MQTT server to achieve two-way communication from the mobile phone or computer to the node module;

[0006] (2) Select the ESP-12 series node module, install the Nodemcu firmware, and connect to the MQTT server through the MQTT module in the Nodemcu firmware;

[0007] (3) As a network backend MQTT service, no user programming is required, and the user's workflow adjustment does not require changing its program; when creating a new product in Tencent Cloud IoT MQTT, the default JSON data format is changed to a custom data format, and the binary byte stream data transmission mode is selected through the LUA language programming of the node module and the JS language programming of the mobile phone or computer, so that each byte in the data transmission package is in the full range of 0-255, and the network communication between the mobile phone or computer and the node module through MQTT is a two-way direct byte transmission without encoding / decoding, referred to as full-range byte transparent transmission;

[0008] (3.1) Define control commands based on full-range byte transparent transmission, including full-range byte file transmission from the mobile phone or computer end to the node module end;

[0009] (3.2) According to the full-range byte transparent transmission, all data processing in the node module except for direct IO device driving is transmitted to the mobile phone or computer for processing through bidirectional full-range byte transparent transmission;

[0010] (4) Control the operation permissions of n users on mobile phones or computers to control m node modules by setting the Tencent Cloud IoT MQTT rule engine;

[0011] (5) The computer has a browser, and the browser runs the HTML-JS scripting language locally; the mobile phone runs the HTML-JS scripting language locally, and converts the HTML-JS program into a mobile app through HBuilderX; the connection between the mobile phone or computer and the MQTT server is realized through JS plus the plug-in mqtt.js;

[0012] (5.1) Programs other than those that present the personalized needs of users will be uniformly programmed by professional companies and designed into the following general programs that can be executed independently and serve as programming demonstrations:

[0013] mqttconnection.htm: Generate UserName and Password based on ProductID, device name, and Hmac signature algorithm, and generate login parameters and connection detection for Tencent Cloud IoT MQTT device on the computer;

[0014] mqttcommunication.htm: Multiple computers run at the same time to test the data or Chinese characters sent between MQTT login devices;

[0015] enduser.lua: node module connects to WIFI;

[0016] get_mqtt.htm, get_mqtt.lua: The computer sets the MQTT device login parameters of the node module through HTTP to test whether the node module MQTT connection is successful;

[0017] init.lua: the self-starting program after the node module is reset;

[0018] Tencent mqtt.lua: node module working program, supporting user demonstration programs mqtt_wx.htm and mqtt_wx.apk;

[0019] Simple push http.htm: test the automatic WeChat notification from the computer;

[0020] Jiantui http.lua: node module automatically sends WeChat notification test;

[0021] Provide demonstration programs for users to realize personalized control display interface or management process:

[0022] mqtt_wx.htm: Tencent Cloud MQTT IoT operation control test and demonstration program on PC.

[0023] mqtt_wx.apk: Tencent Cloud MQTT IoT operation control test and demonstration program for mobile phones.

[0024] usrprg.lua: user-defined program in the node module, mainly writes user-defined global function usrdfn();

[0025] (6) Perform initialization settings before the node module works normally, including the following steps:

[0026] (6.1) When powered on or reset, the LED indicator of the node module flashes slowly. It is searching for WIFI during the slow flashing. The slow flashing will last for a long time. At this time, the user uses a computer to connect to the WIFI of the node module AP: NodeMCU_6-bit random number, and uses a browser to access 192.168.4.1. The searched WIFI will be listed. The user selects the WIFI that he can access, enters the password, and then resets and restarts;

[0027] (6.2) After the node module is restarted, the LED indicator of the node module flashes slowly for a few seconds, then flashes quickly, and the LED indicator becomes bright, indicating that the WIFI connection is successful, but the MQTT is not connected. At this time, the node module automatically enters get_mqtt.lua Device login parameter setting program, the user's computer is set back to the WIFI that he can access, double-click to start the get_mqtt.htm program in the computer, enter the device parameters and username / password settings for Tencent Cloud IoT MQTT login, fill in the device parameters ProductID, device name, and DeviceSceret set in Tencent Cloud IoT MQTT one by one, and the get_mqtt.htm program will automatically generate UserName and Password, and test whether the MQTT connection login of the node module is successful or not; if successful, click to keep, and the device login parameters ProductID, device name, UserName, and Password of the successful MQTT connection will be automatically written into the mqtt.txt file in the node module. After power-on or reset and restart, the node module will automatically enter the MQTT connection login success state; if it is always unsuccessful, the user can double-click to start the mqtt connection.htm program in the computer. This program has the same Tencent Cloud IoT MQTT device login parameter setting interface as the get_mqtt.htm program. Use the computer browser to directly connect to Tencent Cloud IoT MQTT to verify the connectivity of each MQTT device login parameter;

[0028] (6.3) Once the node module MQTT connection login is successful, the mqtt.txt file is generated. After that, whenever the node module is powered on or reset, it will automatically enter the Tencent mqtt.lua MQTT response program to realize the measurement and control of the node module of the Internet of Things. The LED indicator will flash slowly first, then quickly, and finally turn off, indicating that the MQTT connection is successful;

[0029] (7) In the Tencent Cloud IoT MQTT protocol, the MQTT WeChat and alarm functions are added. The specific operations of the MQTT WeChat function are as follows: by adding a specified Topic, publish (topic, msg) to the Topic, that is, send the information msg to WeChat. The recipients of WeChat are determined by any of the following three settings:

[0030] (7.1) The WeChat APP on the mobile phone of the person who manages the Tencent Cloud Service login account must be able to scan the code to log in to the Tencent Cloud Service and send WeChat messages. In this case, the WeChat ID of the person who manages the Tencent Cloud Service login account is the recipient of the WeChat message, Topic = Product ID / Device Name / WX1;

[0031] (7.2) After logging in with the Tencent Cloud Service Management account, enter the MQTT work settings page and enter the WeChat ID number or group name of the WeChat sender or recipient. The individual or group name entered must be the individual or group to which WeChat can send in the WeChat address book of the account logged in with the Cloud Service Management account. Topic = product ID / device name / WX2;

[0032] (7.3) After logging in with the cloud service management account, enter the MQTT work setting page. All the individuals in the WeChat address book of the cloud service management account can be sent to by WeChat. You can use the WeChat APP on your mobile phone to scan the QR code on the MQTT work setting page. Those who pass the verification are the individuals who can be sent to by WeChat. Topic = product ID / device name / WX2;

[0033] When MQTT sends WeChat to the recipient group Topic = product ID / device name / WX2, it means multiple groups of people, which can be further subdivided into Topic = product ID / device name / WX2 / user 1; Topic = product ID / device name / WX2 / user 2;

[0034] (7.4) When MQTT sends a WeChat message with Topic = product ID / device name / WXA1, WXA2, not only a WeChat message is sent, but also an alarm is set, similar to the alarm call before the WeChat [Voice Call] is connected.

[0035] Furthermore, it also includes:

[0036] In the local area network, two-way transparent communication based on Html-JS running locally on mobile phones or computers:

[0037] (8) In the local area network, the two-way transparent communication between the mobile phone or computer and the node module adopts the UDP network protocol without backend service. Since the computer browser does not support UDP, a WS service conversion to UDP is added locally on the computer, and it is limited to an exe program that does not need to be installed. The computer browser accesses the WS service conversion to UDP through the WebSocket protocol;

[0038] (8.1) The mobile terminal has introduced UDP support through java.net in the H5+APP project of HBuilderX. UDP communication is realized through Html5+JS programming and the mobile APP program is generated by HBuilderX, without the need to convert WS service to UDP;

[0039] (8.2) Utilize UDP broadcast mode to solve the problem of unfixed IP of WIFI connection (DHCP), realize the named communication of multi-node modules in LAN, and simplify the whole system to only 4 programs:

[0040] WS service to UDP.exe: computer program, WebSocket protocol WS service to UDP protocol, first started and always running;

[0041] Naming program.htm: The computer browser Html5-JS runs locally to connect to the WS service program. When each node module is running, other node modules will be turned off. Only the node module currently being named is online. Enter the name in the naming program interface. The computer will record the unique number of this node module and the entered name in the local storage of the computer; it can also include setting WIFI and password;

[0042] Test program.htm: The computer browser Html5-JS runs locally to connect to the WS service program. When multiple node modules are running online at the same time, the computer can test each node module by naming to confirm the two-way data communication, and observe whether the LED indicator of the node module is normal or not; it is also a programming demonstration program provided to users. The computer browser accesses the WS service through the WebSocket protocol; if there is only one node module, the above naming process is not required, and it can also be directly connected without a router, that is, the computer WIFI is directly connected to the AP of the node module;

[0043] Node module.lua: This is the only supporting program for the node module. The operation of the above HTML-JS programs, including mobile phone APP, WIFI and password settings, are interpreted and executed by the LUA program through sending and receiving UDP data; the UDP data sending and receiving of the LUA program is the net.udpsocket operation of the net module in the nodemcu firmware;

[0044] For mobile phones, the above named program.htm and test program.htm are changed to named program.apk and test program.apk, the operation method remains unchanged, and there is no need to convert the WS service to UDP.exe computer program;

[0045] (8.3) The node module sends real-time alarms through WeChat via a third party WeChat website. Specifically, nodemcu sends HTTPGET. When downloading nodemcu firmware, select the http module, and the LUA program uses http.get() to send.

[0046] Furthermore, it also includes:

[0047] (9) The full range byte transparent transmission has the following unified sending and receiving forms:

[0048] (9.1) Sending and receiving JS MQTT on mobile phone or computer:

[0049] MQTT object.onMessageArrived=function (received object) {topic=received object.destinationName; data=received object.payloadBytes}

[0050] Send object = new Paho.MQTT.Message(data);

[0051] Send object.destinationName=topic

[0052] MQTT object.send(sending object) or MQTT object.publish(topic, data, 1);

[0053] (9.2) Node module end LUA MQTT sending and receiving:

[0054] MQTT object: on("message", function(MQTT object, topic, data) end)

[0055] MQTT object: publish(topic,data,1);

[0056] (9.3) PC-side JS LAN WS sending and receiving:

[0057] WS object = new WebSocket("ws: / / 127.0.0.1:8183")

[0058] WS object.onopen=function() {Network connection notification}

[0059] WS object.onmessage=function(ev){received data=new Uint8Array(ev.data)

[0060] WS object.send (send data);

[0061] (9.4) Mobile JS LAN UDP sending and receiving:

[0062] UDP sending and receiving object = new DatagramSocket (local port)

[0063] Send data packet = new DatagramPacket (send data, send data length, Addr.getByName (other party IP), other party port)

[0064] UDP transceiver object.send (send data packet)

[0065] Received datagram = new DatagramPacket(abf, abf.length)

[0066] UDP send and receive object.receive (receive data packet)

[0067] Received data packet.getData(); Received data packet.getLength(); The other party's port = received data packet.getPort(); The other party's IP = received data packet.getAddress();

[0068] (9.5) Node module end LUA LAN UDP sending and receiving:

[0069] UDP connection object: on("receive", function(UDP connection object, received data, peer port, peer IP) end)

[0070] UDP connection object: send (other party port, other party IP, send data).

[0071] Furthermore, the method also includes the steps of solving the problem that the ESP-12 node module has insufficient RAM for running the Nodemcu firmware, and the steps include:

[0072] (10) Split the LUA large program in the node module into small programs and run them separately. Record the working status through the RTC UserMemory Module or Flash file. After automatic reset and restart, init.lua decides to enter a corresponding small program to run separately according to the working status recorded by the RTC UserMemory Module or Flash file. After the operation is completed, reset and restart again to cycle this process.

[0073] Furthermore, it also includes:

[0074] (11) Use the high-priority timer interrupt of the domestically produced Macrocrystalline STC15W408AS series microcontroller to perform high-speed sampling. When the sampled data accumulates to a certain amount, the data is transmitted to the node module in a centralized manner with low priority. After the node module receives the data, it forwards the centralized sampled data to the computer or mobile phone according to the above (9) LAN UDP or Internet MQTT communication mode.

[0075] Furthermore, a mode for separating the setting of the microcontroller operating parameters from the operation can be established, characterized in that it also includes:

[0076] (12) Node modules and single-chip microcomputer control systems can separate the wireless WIFI connection to computers or mobile phones from the specific single-chip microcomputer controlled applications, so that they can be separated in secondary development and end-user use;

[0077] For the development process: only one or two HTML-JS programmers or professional companies who are familiar with the two-way transparent communication based on the local operation of Html-JS on mobile phones or computers and the unified sending and receiving form of full-range byte transparent transmission in the local area network are needed to set the application-related working parameters, so that the working parameter settings can be realized on the computer or mobile phone with intuitive dynamic operation prompts, and the set parameter data can be stored in the node module and the file or Flash EPROM of the single-chip microcomputer; single-chip microcomputer developers who are not familiar with HTML-JS programming only need to make direct programming development for control according to the data in the file or Flash EPROM of the node module and the single-chip microcomputer, without worrying about the WIFI connection to the computer or mobile phone to set the working parameters; the node module operation solves the steps of insufficient RAM memory when the ESP-12 node module is installed with Nodemcu firmware. According to the data status in the file or Flash EPROM of the node module and the single-chip microcomputer, it will automatically select to enter the WIFI transparent communication program or the application program directly for control when the node module is reset;

[0078] For end users: The settings before use are connected to the computer or mobile phone through wireless WIFI, and there are dynamic prompts on the computer or mobile phone for intuitive operation; after setting the working parameters, when you need to use it, power on or press the reset button to start the work. At this time, it is completely unrelated to the computer or mobile phone, and you can press buttons and several LED indicators to select work; to re-enter the WIFI connection to the computer or mobile phone settings, pressing a key, double-clicking, long pressing, or two keys at the same time, or holding down a key when powering on are all common entry methods.

[0079] Furthermore, the Nodemcu LUA program in the node module can be put into the Flash ROM and run in LFS.

[0080] Furthermore, before Tencent Cloud IoT MQTT adds the WeChat function, the mobile phone standby real-time alarm can temporarily use a third-party WeChat website, press (8.3).

[0081] Furthermore, the Tencent Cloud IoT MQTT is replaced with the IoT MQTT of Alibaba Cloud, Huawei Cloud or OneNet.

[0082] The beneficial effects of the present invention are: the programming links based on MQTT and byte transparent transmission are reduced, and a local executed Internet of Things Html-JS general program is provided, which not only reduces the user's programming amount, avoids low-level repetition, but also provides users with programming examples. It also proposes a way for MQTT to directly send WeChat (including sound) alarms and transfer the single-chip microcomputer working program to a mobile phone or computer. At the same time, it also proposes a method for Nodemcu to realize the execution of a large program into a small program by resetting, and in order to solve the problem of high-speed timing sampling, it is proposed to use a common typical single-chip microcomputer high-speed timing sampling combined with an ESP-12 module (using the Internet of Things transparent transmission) to batch and centrally transmit data to a computer or mobile phone connected to wifi.

[0083] The Internet of Things not only refers to the cross-regional Internet, but also includes local area networks that do not involve the Internet. Because this mobile Html-JS program localization operation mode based on full-range byte transparent transmission is particularly suitable for combining with single-chip microcomputers, and there is no need for MQTT in the local area network (especially the rule engine that beginners are not familiar with), a local area network UDP communication mode is proposed, including the supporting program composition and the single-chip microcomputer WeChat solution.

[0084] Such a streamlined Internet of Things, from local area networks to wide area networks, from computer and mobile phone connections to single-chip microcomputers to send WeChat messages, adopts mainstream technology and is complete. BRIEF DESCRIPTION OF THE DRAWINGS

[0085] Figure 1 A schematic diagram of the Internet of Things structure provided in this embodiment. DETAILED DESCRIPTION

[0086] Network technology covers a wide range of areas, and new branch technologies emerge in an endless stream, which confuses beginners or users who seek to solve practical network problems simply and quickly, and they don’t know how many front-end and back-end technologies they need to learn. The present invention targets basic Internet of Things applications, and selects a complete set of solutions suitable for beginners from numerous network technologies, so that beginners can realize their own personalized operation display interface or management function Internet of Things applications as long as they learn the most basic HTML+JS programming. The present invention first selects from the hardware composition platform, which must not only conform to the mainstream of development, make full use of existing technologies, reduce the links that users must program themselves, avoid low-level repetition, but also be simple to learn, safe and reliable. It is also best to have low cost, small size, and low power consumption.

[0087] After selecting the network technology and the hardware and software system configuration, professional programming is also required to unify the various functions required to form a practical system, and each functional module is as typical and universal as possible. Only such a system can achieve twice the result with half the effort for users.

[0088] Please note that the users mentioned here are actually technicians or programming beginners. As mentioned before, they have to design and program their own personalized operation display interface or management functions. They are different from users in the conventional sense who entrust the development of the entire system to others.

[0089] Therefore, the present invention provides an IoT byte transparent transmission method based on H5JS local programming, which is implemented on an IoT structure, wherein the IoT structure includes: a Tencent Cloud IoT MQTT server, a node module, a mobile phone terminal and / or a computer terminal; the node module and the mobile phone and / or computer mobile terminal are all connected to the MQTT server to realize two-way byte transparent transmission communication from the mobile phone or computer to the node module, referring to Figure 1 .

[0090] In this example, the system architecture of the Internet of Things is: using the mainstream Tencent Cloud Internet of Things MQTT lightweight network communication protocol, using the ESP-12 module (microcontroller with WIFI) as the measurement and control node (referred to as the node module) of the object end of the Internet of Things, and using a mobile phone or computer for control and management. This hardware architecture seems simple, but it is actually pragmatic and typical, and it is the hardware foundation for the following in-depth development.

[0091] Software system configuration: ESP-12 node module, equipped with Nodemcu firmware, programmed in LUA scripting language.

[0092] A little more explanation is needed about the node module ESP-12 and Nodemcu. It is a 32-bit microcontroller with WIFI function using the ESP8266 chip. The ESP-12 module is just one of the most practical products in this series. The products in this series are very rich, especially the other Nodemcu module based on the ESP-12 module, which is equipped with an RS232 to USB interface, 5V power supply conversion and all port pins are brought out, which is more convenient for experiments or introductory learning. This series can be equipped with a variety of software development systems, but considering the goal of the present invention is to reduce the programming difficulty of users as much as possible, choosing Nodemcu firmware is the best solution. It is programmed with LUA scripting language (programmable with Notepad + upload tool), and there are ready-made supporting programs for many commonly used electronic devices, such as digital temperature sensor DS18B20, temperature and humidity sensor HDT12, PWM waveform generation, one bus interface OW, two bus interface I2C, three bus interface SPI, serial port UART, and necessary file operations FILE, network services NET, WIFI, MQTT, etc., and a website is set up for users to freely select modules to download (without registration and login trouble), see "nodemcu-build.com" for details, and the present invention collectively refers to all of these as node modules. In addition, the ESP-12 module is relatively cheap, small in size (half a stamp), and low in power consumption (3.3V80mA). Using such a perfect single-chip microcomputer module that integrates WIFI Internet access and measurement and control sampling as the node measurement and control sampling module of this Internet of Things project is of course a great convenience for users, especially beginners.

[0093] The computer system (such as Windows) itself has a browser, and the browser can directly run the HTML-JS (JavaScript) scripting language locally, which allows the HTML-JS program to run directly without a programming development environment, that is, to learn HTML-JS programming, you only need a notepad, and the execution results of the HTML-JS program locally on the computer can be directly seen in the browser, which is very convenient for learning and trying. In fact, the browser is a web page access tool, and HTML and JS are the web page files themselves (but the conventional HTML and JS files are all from the website Web server, which is often called back-end programming, rather than directly starting and running locally. And the new security same-domain access rules also prohibit JS from running directly to the website locally, which will be mentioned later), with a wide range of popularization and rich learning resources. As the basis for writing web pages, it can also be used for work presentation after learning. Therefore, the JS scripting language is currently very popular, but the purpose of the present invention is to facilitate learning and entry, so only the basic parts of HTML and JS are required (no jQuery, no ES6, etc., no need to build any programming environment). In other words, what is emphasized here is the simplicity of JS learning and entry, and its inherent superiority in interface display. In addition, a key point that should be emphasized is that the HTML-JS program mentioned above can be directly started and executed locally on the mobile phone or computer (disk), which makes it possible to move the program originally used for the node module microcontroller to a computer or mobile phone with super processing power without going through a Web server (eliminating a large back-end programming link). Many of the technical routes to be developed below are centered around this key point.

[0094] Regarding the local execution of HTML-JS scripting language on mobile phones, a common method is to install and run the HBuilderX to APP program (pure HTML+JS to APP is the simplest basic type in the HBuilderX project).

[0095] Since the Internet of Things described in the present invention adopts the mainstream cloud Internet of Things, the MQTT lightweight network communication protocol of Tencent Cloud Internet of Things is selected. In addition to providing basic network communication, it can also obtain three major advantages: (1) Each byte of the communication data packet can be in the full range of 0-255 (eliminating the limited transcoding capability of the single-chip microcomputer); (2) The operation authority control of n users on the mobile phone or computer to control m node modules is determined by the [Rule Engine] setting of Tencent Cloud Internet of Things MQTT (no need to develop and set user operation authority management by yourself, and it is very troublesome to set operation authority identification statements everywhere in programming); (3) The core of the convenient learning of the present invention is that the HTML-JS script language runs locally on the computer (according to the same domain access security rules, JS is prohibited from running locally to directly access the website). Only through the plug-in mqtt.js can JS run locally to directly access the external network MQTT server.

[0096] JS (JavaScript scripting language) itself does not have MQTT function, and the plug-in mqtt.js must be added to connect the mobile phone or computer to the Tencent Cloud IoT MQTT server. The node module is installed with Nodemcu firmware and the MQTT module is selected to connect to the Tencent Cloud IoT MQTT server. The Tencent Cloud IoT MQTT server realizes two-way network communication between the mobile phone or computer and the ESP-12 node module (that is, cross-router or remote communication).

[0097] Based on the above-mentioned hardware and software system configuration of the Internet of Things, the present invention provides an Internet of Things byte transparent transmission method based on H5JS local programming, which includes the following steps:

[0098] (1) When creating a new (ordinary) product in Tencent Cloud IoT MQTT, change the default JSON data format to a custom data format, and then use the following programming statements to implement MQTT bidirectional data transmission binary byte stream, that is, each byte is in the full range of 0-255. The LUA statement of the node module Nodemcu MQTT is:

[0099] local ubs=string.char(0,1,2, ... , 255); mclt:publish(topic,ubs,1,0,func)

[0100] The statement of mqtt.js on the mobile phone or computer is:

[0101] var ABbf=new ArrayBuffer(bfln)

[0102] var Ui8Ar = new Uint8Array (ABbf) / / Operate as an unsigned one-byte array

[0103] var mqttMsg=new Paho.MQTT.Message(ABbf)

[0104] mqttMsg.destinationName=topic

[0105] mclient.send(mqttMsg) or mclient.publish(topic, ABbf, 1)

[0106] In this way, the communication between the JS language on the mobile phone or computer and the LUA language on the node module via MQTT is a two-way direct byte transmission, eliminating the resource-consuming encoding / decoding algorithm (such as the commonly used Base64), which is particularly suitable for single-chip microcomputers and is a basis of the present invention, referred to as: full-range byte transparent transmission, which not only alleviates the insufficient processing power of single-chip microcomputers, especially the Nodemcu firmware does not provide bitwise logical operation instructions (JS has bitwise operators), but also facilitates the transfer of the work of the node module single-chip microcomputer to the mobile phone or computer with super processing power. For example, the reading of the 18B20 temperature sensor is not decoded after being obtained at the node module end, but is directly sent to the computer end according to the original code. After the computer end receives it, it is decoded / displayed by JS. The JS decoding conversion display is much more convenient and faster than the LUA language on the node module end. It can also transfer any file, which is also achieved by this point.

[0107] (2) Select the ESP-12 series node module, install the Nodemcu firmware, and connect to the MQTT server through the MQTT module in the Nodemcu firmware;

[0108] (3) As a network backend MQTT service, no user programming is required, and the user's workflow adjustment does not require changing its program; when creating a new product in Tencent Cloud IoT MQTT, the default JSON data format is changed to a custom data format, and the binary byte stream data transmission mode is selected through the LUA language programming of the node module and the JS language programming of the mobile phone or computer, so that each byte in the data transmission package is in the full range of 0-255, and the network communication between the mobile phone or computer and the node module through MQTT is a two-way direct byte transmission without encoding / decoding, referred to as full-range byte transparent transmission;

[0109] (3.1) Define the control command sequence based on MQTT byte stream communication. The first byte is the command category, and the following bytes are either subcategories or parameters. For example:

[0110] ABbf[0]=1 indicates remote power switch, ABbf[1]=0 indicates off, and ABbf[1]=1 indicates on;

[0111] ABbf[0]=2 means start reading temperature, ABbf[1]=n means send temperature data every n seconds, n=0 means stop sending; ABbf[2]=m means read m 18B20 temperature sensor, m=0 means read all;

[0112] ABbf[0]=3 means transferring the file to the node module. The next 10 bytes ABbf[1]-ABbf

[10] represent the file name (if insufficient, fill with 0), and all the following bytes represent the file content.

[0113] More freely definable.

[0114] The above-mentioned files include executable files init.lua or prog.lc, which realize remote file updates or node module system updates, and combined with the dofile(prog.lua) statement, remote debugging of node modules is realized. Operation permission control is determined by the [Rule Engine] setting of Tencent Cloud IoT MQTT.

[0115] (3.2) Transfer the work of the node module microcontroller to the mobile phone or computer, as mentioned in (1).

[0116] (4) The control of the operation permissions of n users on mobile phones or computers to control m ESP-12 node modules is determined by the [Rule Engine] settings of Tencent Cloud IoT MQTT (there is no need to set up the very troublesome operation permission management by yourself). For details, see the [Rule Engine] settings of Tencent Cloud IoT MQTT "cloud.tencent.com / document / product / 634 / 14446" and the supporting operation instructions document "console.cloud.tencent.com / iothub / rule".

[0117] (5) The computer has a browser that runs the HTML-JS scripting language locally. The mobile phone uses HBuilderX to convert the HTML-JS program into a mobile app (see: hx.dcloud.net.cn / Tutorial / project). The mobile phone or computer is connected to the MQTT server through JS plus the plug-in mqtt.js (see: www.eclipse.org / paho / files / jsdoc / paho-mqtt.js.html).

[0118] (5.1) In order to significantly reduce user programming, the relevant programs that constitute the Internet of Things should be uniformly programmed by professional companies as much as possible and designed as general programs (meaning that no matter how the user program changes, the general program does not need to be changed. And it can be executed independently to complete a certain typical function). Since Html-JS is a scripting language that can be opened with Notepad, these programs are also programming demonstrations, which not only reduces the amount of user programming and avoids low-level repetition, but also provides users with programming examples. It should be emphasized that these include the setting programs and test programs for users to build the Internet of Things at various stages, which are also the basis for realizing online technical services. Otherwise, each user will encounter a variety of problems and no company has the energy to deal with them. The problems must be classified and unified so that there is a unified basis for users to express their problems.

[0119] Common procedures include:

[0120] mqttconnection.htm: Generate UserName and Password based on ProductID, device name, and Hmac signature algorithm, and generate login parameters and connection detection for Tencent Cloud IoT MQTT device on the computer.

[0121] mqttcommunication.htm: Run multiple computers at the same time to test the data or Chinese characters sent between each MQTT login device.

[0122] enduser.lua:ESP-12 node module connects to WIFI.

[0123] get_mqtt.htm, get_mqtt.lua: The computer sets the MQTT device login parameters of the ESP-12 node module through HTTP (solves the problem of using the local area network to achieve direct wireless communication between the computer and the ESP-12 node module before MQTT connection. At this time, the ESP-12 node module is a web server) and tests whether the node module MQTT connection is successful.

[0124] init.lua: The self-starting program after the node module is reset.

[0125] Tencent mqtt.lua: node module working program, supporting user-programmed tencMqtt.htm and tencMqtt.apk.

[0126] http_wx.htm: Test of automatically sending WeChat notifications from the computer.

[0127] http_wx.lua: Node module automatically sends WeChat notification test.

[0128] What needs to be programmed by the user is to realize the personalized control display interface or measurement and control data management process. It is an HTML-JS script language program running on the user's local computer. No programming development environment is required (it can be edited in Notepad), and the debugging results are intuitive. Demonstration programs are also provided for users to learn and adapt.

[0129] tencMqtt.htm: Tencent Cloud MQTT IoT operation control test and demonstration program for PC.

[0130] tencMqtt.apk: Tencent Cloud MQTT IoT operation control test and demonstration program for mobile phones.

[0131] usrprg.lua: User-defined program in the node module, mainly writes the global function usrdfn().

[0132] Users can start learning to imitate by rewriting nouns and parameters.

[0133] In order to expand the function of the node module, a user-programmable Lua language interface is also reserved:

[0134] When the first byte of the MQTT command sequence sent to the node module is 98, the user-defined global function usrdfn(msg) in the node module's reset self-starting program init.lua will be executed;

[0135] When the first byte of the MQTT command sequence sent to the node module is 99, the node module's reset self-starting program init.lua will execute the user-defined global function usrdfn() in the user-defined program usrprg.lua, that is, init.lua contains the statement:

[0136] require("usrprg").usrdfn(msg) -- msg is the received MQTT data packet, which is interpreted and processed by the user's own programming of usrdfn(). Or

[0137] if usrdfn==nil then dofile("usrprg.lua"); usrdfn(msg) else usrdfn(msg) end

[0138] -- The global custom function usrdfn(msg) in the user-defined program usrprg.lua is not preceded by local.

[0139] In addition to the custom global function name usrdfn, the node module also has several dedicated global variable names that should not be accidentally reused or changed: such as: tmr0, mclt, fmqtt0, fbk0, wx.

[0140] The user-defined program of the node module is particularly suitable for the mode where large programs are directly executed in LFS. At this time, all LUA working programs have been compiled and packaged into LUA.img and loaded into Flash ROM (see: nodemcu.readthedocs.io / en / dev / lfs for details). At this time, the user-defined program is a supplement to LUA.img.

[0141] Note that although you can set a user-defined global function usrdfn() in init.lua and call it from the MQTT command sequence ABbf[0]=98, it is not recommended to modify init.lua, as this may cause errors and repeated restarts, which may lead beginners to mistakenly believe that the ESP-12 node module is scrapped.

[0142] A demonstration program usrprg.lua is also provided for user self-programming of node modules.

[0143] Before debugging the IoT, first create a Tencent Cloud login account, perform real-name authentication, create an IoT MQTT product ID, and then create device names one by one. For detailed operations, see: cloud.tencent.com.

[0144] With the Tencent Cloud login account, IoT MQTT product ID, device name and other parameters, it is recommended to test the connection to MQTT on the computer first, and fully understand many issues. From another perspective, the use of MQTT here reduces a lot of programming links (eliminating the entire back-end programming and user management), but this is to transfer the problem to learning Cloud IoT MQTT, especially to learn the [Rule Engine] that standard MQTT does not have. It is even more necessary to connect to Tencent Cloud IoT MQTT directly from the computer before involving the IoT node module, and practice the MQTT device connection parameters, multi-device communication, continuous data transmission and Chinese characters JS program statements, etc. It is not only that two devices communicate with each other through Tencent Cloud IoT MQTT, but also determines the operation permission control of n users on the mobile phone or computer to m node modules (set through Tencent Cloud IoT [Rule Engine]), so there is no need to develop and set user operation permission management, and it also avoids the trouble of setting a large section of operation permission identification statements everywhere in programming.

[0145] Common computer-side MQTT test programs include:

[0146] mqttconnect.htm: Generate UserName and Password based on ProductID, device name, and Hmac signature algorithm, generate Tencent Cloud IoT MQTT device login parameters and detect connection. If the connection is successful, save the device login parameters locally on the computer, and automatically connect to MQTT next time. (Note: After the device name is created on Tencent Cloud IoT, the UserName and Password used for MQTT device login connection must be obtained through the security algorithm. Based on timeliness and randomness, an infinite number of UserNames and Passwords can be generated and can be used for the MQTT login connection of the device name; but a device name is not allowed to log in multiple times at the same time. These can be confirmed through the mqttconnect.htm program.)

[0147] The reason why we always say "device login parameters ProductID, device name, UserName, Password" instead of the standard MQTT which has only one fixed UserName and Password is because device login MQTT requires not only each device login to have its own UserName and Password, but also ProductID and device name as components of connecting to the MQTT server name and Topic, so the mqtt.txt file needs to record so many device login parameters.

[0148] mqttcommunication.htm: Multiple computers (with different device name login parameters) can connect to MQTT at the same time to test the data or Chinese characters between the MQTT login devices. It is especially used to verify the intercommunication effect of the devices set by the [Rule Engine] and the corresponding topic settings. Note that for higher security, the MQTT in major mainstream cloud services in China is not a standard MQTT. The sending target of the standard MQTT is directly determined by the Topic at the time of sending (there is no concept of device name login). The sending Topic of MQTT in mainstream cloud services is limited to the device's own Topic. The interoperability of the sending target is determined by the Topic of each device by adding the definition of the [Rule Engine]. Therefore, it can be understood as [Device Login MQTT]. Note that the devices of the n users on the mobile phone or computer side and the m node modules on the IoT side mentioned in this article are actually the same device names when the device names are created in Tencent Cloud IoT MQTT. In terms of naming, the n users on the mobile phone or computer side can be named USRn, and the m node modules on the IoT side can be named DVCm to distinguish them. The interoperability between USRn and DVCm is established by logging into Tencent Cloud's [IoT Communication] [Rule Engine] and setting the [Rule Engine] for Topic = Product ID / USRn and Topic = Product ID / DVCm for each device name.

[0149] It is very convenient and intuitive for users to practice MQTT communication with HTML-JS programs on their computers. Once you are familiar with this, you will have the communication foundation of the Internet of Things mentioned in this article, and you will have experience in operational flexibility in the connection of the Internet of Things node modules in the next stage. Whether you are doing workaround tests when encountering problems or seeking help online, you can use the test program information here as a reference point.

[0150] Here, mqtt connection.htm and mqtt communication.htm are both HTML-JS scripting languages. After becoming familiar with them, users can adapt / reduce them to personalized special programs for their own environment.

[0151] In addition, the Chinese characters in the names of many of the above programs are of course intuitive, but the program file names on the Internet and those that need to be converted from HBuilderX to APP cannot be in Chinese, so some program file names cannot be in Chinese. The same applies below.

[0152] (6) The initialization steps before the IoT node module works normally are as follows:

[0153] (6.1) When powered on or reset for the first time, the LED indicator of the node module (controlled by init.lua to execute enduser.lua) flashes slowly at intervals of 0.5 seconds, and it will take up to half a minute to search for WIFI. At this time, the user uses a computer to connect to the WIFI of the node module AP: NodeMCU_xxxxxx, and uses a browser to access 192.168.4.1, where the searched WIFI will be listed. The user selects the WIFI that he can access and enters the password, and then the node module is reset and restarted.

[0154] (6.2) After the node module is restarted, the LED indicator will flash slowly for 0.5 seconds and then flash 5 times (stay on) for about 2-10 seconds, indicating that the WIFI connection is successful (but MQTT has not yet logged in). At this time, the node module will automatically enter the get_mqtt.lua device login parameter setting program. The user's computer connects back to the WIFI that he can access, double-click to start the get_mqtt.htm program in the computer, enter the device parameters and user name / password settings for Tencent Cloud IoT MQTT login, and fill in the device parameters ProductID, device name, and DeviceSceret set in Tencent Cloud IoT MQTT one by one. The get_mqtt.htm program will automatically generate UserName and Password. , and test whether the MQTT connection login of the node module is successful or not; if successful, click [Retain], and the device login parameters ProductID, device name, UserName, and Password of the successful MQTT connection will be automatically written into the mqtt.txt file in the node module. The next time it is powered on or reset, the node module will automatically enter the MQTT connection login success state (stay dark after 5 quick flashes); if it is always unsuccessful, the user can double-click to start the mqtt connection.htm program in the computer. This program has the same Tencent Cloud IoT MQTT device login parameter setting interface as the get_mqtt.htm program. Use the computer browser to directly connect to Tencent Cloud IoT MQTT to test the connectivity of each MQTT device login parameter.

[0155] (6.3) Once the node module has the mqtt.txt file and the MQTT connection login is successful, the node module will automatically enter the Tencent mqtt.lua MQTT response program every time it is powered on or reset to monitor the measurement and control operations of the node (that is, the network is connected, and everything can be operated intuitively from a computer or mobile phone).

[0156] (7) So far, the basic functions of the Internet of Things have been built, but an important real-time alarm function is still missing, and it seems difficult to find a simple programming method at first glance. The reasons are as follows:

[0157] Self-written programs will be shut down by the system after 5 minutes when the phone is in standby mode. Even if you use the programming environment of the phone system to create a standby alarm waiting program (including the troublesome operation permission system settings), according to the current power saving strategy of mobile phone manufacturers, when the phone is in standby mode, the system will terminate all user apps, except for some big-name software on the whitelist, such as WeChat, Alipay, Huawei services, etc.

[0158] The more practical situation is that many small and medium-sized IoT applications really need to work for a long time when the phone is off and in standby mode, such as anti-theft alarms, fire alarms, and elderly fall alarms. The frequency of actual alarms in these applications is extremely low. If you make a special APP to run in the background on the phone for a long time, it is not suitable. It consumes power and is easy to be accidentally turned off (that is, there is no guarantee that the program will respond normally at critical times).

[0159] After comprehensive analysis, a perfect solution emerged: the best choice is to install the real-time standby alarm function on mobile phone apps that everyone has installed, such as WeChat, Alipay, and Huawei services. Here, we take WeChat, which is also from Tencent, as an example to add the WeChat function to Tencent Cloud IoT MQTT.

[0160] From the perspective of network technology architecture, the MQTT in the major cloud services for the Internet of Things is not the standard MQTT. Instead, it is an MQTT with a limited Topic and an additional [Rule Engine] (this article calls it [Device Login MQTT], see console.cloud.tencent.com / iothub / rule for details). So it is reasonable to add the WeChat sending function. What is even more effective is that Tencent's IoT MQTT device login and the ready-made WeChat login account can be used as a ready-made WeChat push management and control security mechanism, which greatly simplifies the security authentication operation process for people receiving WeChat push notifications.

[0161] The specific implementation details are as follows:

[0162] In the Tencent Cloud IoT MQTT protocol, the MQTT WeChat function is added. By adding a specified Topic, publish (topic, msg) to the Topic, that is, the information msg is sent to WeChat. The recipients of WeChat are determined by the following three settings:

[0163] (7.1) The WeChat APP on the mobile phone of the Tencent Cloud Service Management Login Account must be able to scan the QR code to log in to the Tencent Cloud Service and send WeChat messages. In this case, the WeChat ID of the Tencent Cloud Service Management Login Account is the recipient of the WeChat message, Topic = Product ID / Device Name / WX1;

[0164] (7.2) After logging in with the Tencent Cloud Service Management account, enter the MQTT work settings page and enter the WeChat ID number or group name of the recipient (this operation is similar to the [Rule Engine] setting). The individual or group name entered must be all the individuals or groups in the WeChat address book of the Tencent Cloud Service Management account that can be sent to WeChat. Topic = product ID / device name / WX2;

[0165] (7.3) After logging in with the Tencent Cloud Service Management account, enter the MQTT work settings page. All the individuals in the WeChat address book of the Tencent Cloud Service Management account can use the WeChat APP on their mobile phones to scan the QR code on the MQTT work settings page. Those who pass the verification are the individuals who can be sent to by WeChat. Topic = product ID / device name / WX2. For example, the LUA program statement is mclt:publish('product ID / device name / WX2', 'Alarm: '..message).

[0166] When MQTT sends WeChat to the recipient group Topic = product ID / device name / WX2, it means multiple groups of people, which can be further subdivided into Topic = product ID / device name / WX2 / Zhang San; Topic = product ID / device name / WX2 / Li Si.

[0167] Note: To set up the MQTT WeChat function, you must first confirm that the WeChat APP on your mobile phone that is logged into the Tencent Cloud Service Management account can scan the code to log into Tencent Cloud and send WeChat messages to the WeChat sender and recipient groups.

[0168] Regarding the settings of WeChat sending and receiving groups, enter the Tencent Cloud Service Management Interface on a computer, mobile phone, or mobile terminal. After successfully logging in with the management account, there are operation items for setting the allowed WeChat sending and receiving groups for each product ID / device name you have created.

[0169] (7.4) When MQTT sends WeChat Topic = product ID / device name / WXA1, WXA2, not only WeChat is sent, but also an alarm (long sound reminder), similar to the alarm call before the WeChat [Voice Call] is connected. This is mainly for emergency alarms such as accidents and failures.

[0170] The above fully explores the potential functions of Tencent Cloud MQTT and WeChat, greatly reducing the user programming steps.

[0171] So far, a streamlined technical route has been paved, which is actually the result of a careful selection of existing technologies and potential highlights that are perfectly integrated (especially in terms of simplicity to achieve twice the result with half the effort, such as: direct transparent transmission of the entire range of MQTT bytes 0-255, running the front-end program locally without programming the back-end MQTT, only setting up the Tencent Cloud [Rule Engine], moving the MCU program to the front end of the computer as much as possible and replacing it with a local JS program, and providing a local executed IoT Html-JS general program, which not only reduces the user's programming workload and avoids low-level duplication, but also provides users with programming examples). These wonderful ideas can also be applied to local area networks.

[0172] (8) As a measure of completeness, especially in the early stage of internal trial operation or familiarization learning, the Internet of Things should also include a local area network mode, that is, in a building or a room, only through the local area network (not related to any commercial Internet) to achieve two-way transparent network communication from the mobile phone or computer end to the node module end. This is not only safe (not connected to the external network) and free of various network fees, but also does not involve cloud service MQTT, avoiding the need to first familiarize yourself with security authentication to create a Tencent Cloud Internet of Things account and practice setting up the MQTT rule engine, making learning the Internet of Things have a lower entry point. In fact, most small Internet of Things projects are applications within the local area network. Of course, after the application within the local area network is completed, it is necessary to expand it to cross-regional or remote areas, and then add the cloud MQTT part. This does not conflict with the mode described in the present invention. The user only needs to modify the byte sending and receiving call interface at both ends (all based on byte transparent transmission, see 9 below).

[0173] As the core control microcontroller of home appliances and instruments, the mobile phone wireless direct connection also has an exclusive special application field of acting as a super display screen and control function keys, which greatly simplifies the display panel or control buttons of home appliances and instruments, simplifies the production process, and improves the convenience and intuitiveness of operation.

[0174] UDP is a non-connection simple network protocol. It has no interference and almost no packet loss in LAN applications. It is very suitable for single-chip microcomputers to transmit large amounts of data at high speed (such as electrocardiogram display, 2.4G wireless FSK communication group control host computer management trunk data transmission). Therefore, the LAN communication from the mobile phone or computer to the node module uses the UDP network protocol. Since the computer browser does not support UDP, add WS (WebSocket) service to the computer locally to convert to UDP, and the computer browser directly supports WS.

[0175] The computer local WS service to UDP is a separately run [WS service to UDP.exe] computer program, which does not need to be installed or registered to set up an account (to facilitate users and avoid the complicated download and installation of NodeJS and environment configuration).

[0176] One way to implement [WS service to UDP.exe] is to first install nodejs, then run the test WS service to UDP.js, and then use nodejs's pkg to package it into a standalone [WS service to UDP.exe].

[0177] The key steps of NodeJS to implement WS service to UDP.js include: establishing UDP listening, starting WebSocket service to listen to WS: service requests, once there is a request from the computer browser with ws: / / 127.0.0.1:8183 protocol, WS response remembers the client, and finds the IP and port number 8080 of the node module corresponding to the unique number according to the name, and directly forwards UDP; once UDP data is received, its name and unique number can be found in the local storage of the computer according to its IP, and combined with the received UDP data, it is pushed to the remembered browser JS of the client using WS. Some key feature statements are as follows:

[0178] const dgram = require('dgram'); / / Load UDP module

[0179] const udpClt = dgram.createSocket('udp4');

[0180] udpClt.on('close',()=>{console.log('UDP is closed')});

[0181] udpClt.on('error',(err)=>{console.log(UDP err)});

[0182] udpClt.on('listening',()=>{console.log('UDP socket is listening...')});

[0183] udpClt.bind(8081); / / Set UDP port to 8081

[0184] var ws = require ("ws"); / / Load WS module

[0185] var wsSvr = new ws.Server({host:"127.0.0.1", port:8183});

[0186] console.log('WS sever is listening at port localhost:8183');

[0187] wsSvr.on("connection", wsCnct);

[0188] function wsCnct(wsObj) {

[0189] console.log("WS connected");

[0190] udpClt.on('message',(msg,udpinfo)=>{ / / UDP listens for received forwarding WS

[0191] wsObj.send(msg)}) / / Forwarding without any transcoding

[0192] wsObj.on("message", function(data) { / / WS listens for received forwarded UDP

[0193] udpClt.send(data,8080,'192.168.8.255')});

[0194] wsObj.on("close", function() {console.log("WS request close")});

[0195] wsObj.on("error", function(err) {console.log("WS request error",err)});

[0196] }

[0197] (8.2) The computer browser uses the ws: / / 127.0.0.1:8183 protocol supported by html5-JS to request the WS service, and the WS service forwards UDP. There is no distinction between service and client in UDP communication, and all are sent using the other party's IP and port number. But the actual situation is that the (DHCP) IP of the node module WIFI is not fixed. If the WS service wants to communicate with UDP, it must first determine the IP of the other node module. Fortunately, UDP has a broadcast function and is sent using the UDP universal broadcast address. When the other node module receives the UDP broadcast, it records the IP and port number of the WS service sent, and uses the IP and port number to send back the UDP information. When the WS service receives the UDP information, it has the IP and port number of the other node module, and records it as the target IP and port number during normal operation.

[0198] The above is the case of one node module. For the case of multiple node modules, an initial naming and setting process needs to be added (corresponding to the creation and setting of the device name of MQTT): before each node module works normally, it is necessary to name it one by one on the computer and record its unique number. In the future, the user will control each node module according to the name. In fact, the system works according to the unique number of the node module corresponding to the name.

[0199] The specific naming process is: turn off other node modules and only leave one. Press the above WS service to UDP to connect to the node module that communicates via UDP network with a computer browser, let it read the unique number, send it to the computer, and record it in the local storage of the computer together with the name entered by the user (it will not disappear when the power is turned off).

[0200] When multiple node modules are online at the same time, the computer uses broadcasts with unique numbers to determine the IP of each node module. Each node module will only send back UDP information when it receives a unique number that matches its own. The computer can then fill in the current IP and port number for the existing name and unique number one by one.

[0201] Note that the port number for UDP network communication is usually agreed upon in advance. For example, the UDP port number of a mobile computer or mobile phone is 8081, and the UDP port number of each node module is 8080.

[0202] When multiple node modules are online at the same time and all current IPs (and port number 8080) have been determined to enter the normal WS service to UDP conversion, the key steps for NodeJS to implement [WS service to UDP.js] include: establishing UDP listening, and starting the WebSocket service to start listening for WS: service requests. Once there is a request from a computer browser with the ws: / / 127.0.0.1:8183 protocol, the WS response remembers the client, and finds the IP and port number 8080 of the node module corresponding to the unique number based on the name, and directly forwards UDP; once UDP data is received, its name and unique number can be found in the local storage of the computer based on its IP, and combined with the received UDP data, it is pushed to the remembered browser JS of the client using WS.

[0203] According to the above working principle, four procedures are actually determined (which can be used as external features):

[0204] WS service to UDP.exe: The service program is started first and runs all the time (regardless of whether there are node modules online or HTML-JS is running).

[0205] Naming program.htm: Name each node module. When running, turn off other node modules. Only the node module currently being named (numbered) is online. Enter the name in the operation interface that appears when the computer runs the naming program.htm. The computer will record the unique number of this node module and the entered name in the local storage of the computer (it will not disappear when the power is turned off, so this operation is only done once). You can also use the current operation sequence number as the (number) and paste it on this node module (to show intuitive distinction) (but the internal operation is always based on the unique number). You can also set WIFI and password here.

[0206] Note: For the named program.htm, specify the node module's AP mode to connect, that is, the computer WIFI directly connects to the node module's AP (the broadcast IP of the WS service to UDP is 196.168.4.255 or 196.168.4.1), then set the node module's WIFI and password (after that, the node module will automatically connect to WIFI after powering on or restarting, and the LED indicator will flash slowly for about 2-10 seconds at 0.5 second intervals until the WIFI connection is successful and there will be a burst of 5 fast flashes. The computer will also connect back to the original WIFI). That is: the node module can be set to WIFI using the HTTP method (enduser.lua) in (6.1) or the UDP method here (in short: as long as the network is connected, the operation from the computer or mobile phone is intuitive).

[0207] Test program.htm: A test program that can test multiple node modules online at the same time. When running, the computer can test each node module by naming to confirm the two-way data communication and observe whether the LED indicator of the node module is normal or not. It is also a programming demonstration program provided to users.

[0208] Note: When multiple node modules are online at the same time, there must be a LAN mode composed of a wireless router. Each node module must have been automatically connected to WIFI successfully, and each node module has a name recorded in the computer.

[0209] For the case of only one node module, no naming is required, that is, if the WS service to UDP.exe service program cannot find the naming record, it will be processed as a single node module.

[0210] For the test program .htm, specify the connection in AP mode of the node module, that is, the computer (WIFI connection) is directly connected to the AP of the node module (the broadcast IP of WS service to UDP is 196.168.4.255 or 196.168.4.1), then WS service to UDP.exe is processed as a direct connection to a single node module without a router.

[0211] Node module.lua: unified node module supporting program (just one). The operation of the above HTML-JS programs, including mobile phone APP, WIFI and password settings, are all interpreted and executed by this LUA program through sending and receiving UDP data.

[0212] (8.1) Regarding the use of mobile phones to replace the computer operation here, because the mobile phone programming of this invention is to convert the HTML-JS program into a mobile phone APP program through HBuilderX, what is more advantageous is that the introduction of java.net in the [H5+APP] project of HBuilderX has support for UDP, so the above WS service to UDP.exe service program is completely unnecessary. In addition, the data transparent transmission through UDP to the node module end and the naming and recording process of multiple node modules (including setting WIFI and password) are of course similarly maintained, that is, there are corresponding naming programs.apk and test programs.apk. The supporting programs (node ​​modules.lua) of all node module ends are still the same (unchanged).

[0213] Specific HBuilderX HTML5plus related statements about UDP operation (UDP operation statements on mobile phones are not common, the main UDP sending and receiving statements are listed as follows, for those who are interested to search online):

[0214] var DatagramPacket = plus.android.importClass("java.net.DatagramPacket");

[0215] var DatagramSocket = plus.android.importClass("java.net.DatagramSocket");

[0216] var socket = new DatagramSocket (8081); / / Set UDP port

[0217] var spkt=new DatagramPacket(data, data.length, address, port);

[0218] socket.send(spkt); / / UDP sends data packet spkt

[0219] var rpkt=new DatagramPacket(buf,buf.length);

[0220] socket.receive(rpkt); / / UDP receives data packet rpkt.

[0221] (8.3) If the LAN router is connected to the external network, the node module can still send WeChat in real time, and send WeChat websites through third parties, such as: www.xtuis.cn, xz.qqoq.net / # / index, Server sauce sc.ftqq.com. Nodemcu sends HTTP GET. When downloading the nodemcu firmware, select the http module, and the LUA program uses the http.get() statement to send.

[0222] In advance, the user scans the code on the third-party WeChat website to log in (follow or pay), sets the WeChat address (which will be provided after following or paying) and content input field in the user program, and saves the parameters required by these two third-party WeChat websites in the node module file in advance.

[0223] (9) Based on two-way transparent transmission, one of the conveniences is that it is easy to change the communication mode once you are familiar with the transparent transmission statements, such as upgrading from UDP in the local area network to MQTT in the wide area network in the present invention. Unified means that it has nothing to do with the user's personalized workflow design. The received data always triggers a function with received data parameters to process the received data. The UDP and MQTT two-way transparent transmission receiving and sending statements used in the present invention are summarized as follows (which can be used as keywords for online retrieval):

[0224] (9.1) Sending and receiving JS MQTT on mobile phone or computer:

[0225] client.onMessageArrived=function (mqttMsg) {topic=mqttMsg.destinationName; Msg=mqttMsg.payloadBytes}

[0226] mqttMsg=new Paho.MQTT.Message(Msg)

[0227] mqttMsg.destinationName=topic

[0228] client.send(mqttMsg) or client.publish(topic, Msg, 1)

[0229] (9.2) Node module end LUA MQTT sending and receiving:

[0230] mclt:on("message", function(client, topic, data) received processing end)

[0231] mclt:publish(topic, data, 1)

[0232] (9.3) PC-side JS LAN WS sending and receiving:

[0233] var wsObj = new WebSocket("ws: / / 127.0.0.1:8183")

[0234] wsObj.binaryType="arraybuffer"

[0235] wsObj.onopen=function() {document.all.dsp.innerHTML="WebSocket open"}

[0236] wsObj.onmessage=function(ev){var bf=new Uint8Array(ev.data)}

[0237] wsObj.send(data)

[0238] (9.4) Mobile JS LAN UDP sending and receiving (H5+JS UDP):

[0239] skt=new DatagramSocket(8081)

[0240] spkt=new DatagramPacket(abf, abf.length, Addr.getByName(IP), 8080)

[0241] skt.send(spkt)

[0242] rpkt=new DatagramPacket(abf,abf.length)

[0243] skt.receive(rpkt)

[0244] rpkt.getData(); rpkt.getLength(); rpkt.getPort(); rpkt.getAddress()

[0245] (9.5) Node module end LUA LAN UDP sending and receiving:

[0246] UdpSocket:on("receive", function(socket, data, port, ip) receive processing end)

[0247] UdpSocket:send(8081, ip, data)

[0248] All the above data types for sending and receiving have the type of byte array with full range of 0~255, that is, this section directly gives the statement format of full range byte transparent transmission in summary.

[0249] Note that the full range of byte array types are directly supported as transmission data packets, such as UDP or MQTT of Nodemcu LUA, which supports both array type and string type without explanation; the WS of the computer browser is set through the wsObj.binaryType="arraybuffer" statement; the MQTT.js of the computer browser is specified by setting the data object property Msg=mqttMsg.payloadBytes.

[0250] What needs to be explained in detail here is that the mobile terminal can directly use UDP by introducing java.net through HBuilderX's [H5+APP project], but the exception is that its receiving method is a simple blocking type (always waiting until receiving), while the others are event-triggered, and the receiving processing function is triggered only when receiving. For the blocking type of Html5plus-JS UDP receiving, skt.setSoTimeout(10) can be used to set a very short (receiving blocking) time (such as 10 milliseconds) but have a receiving pre-storage function. With the help of the timer setInterval(usrCallback, 200), it can be received every 200 milliseconds (blocked for 10 milliseconds if no data arrives), and the usrCallback(rpkt) function is executed when data is received. This is equivalent to the event-triggered type (it can also be directly encapsulated into the receiving event trigger function of the UDP sending and receiving object through the object encapsulation statement). Specific examples:

[0251] usrCallback(rpkt) { process received: rpkt.getData(); rpkt.getLength(); rpkt.getPort(); rpkt.getAddress()}

[0252] var skt=new DatagramSocket(port);

[0253] skt.setSoTimeout(10)

[0254] var abf = new Array(256)

[0255] var rpkt=new DatagramPacket(abf, abf.length)

[0256] setInterval(recv(usrCallback), 200)

[0257] function recv(callback) {

[0258] try{skt.receive(rpkt);

[0259] if(rpkt.getLength()>0) callback(rpkt)

[0260] catch(e) {}

[0261] }

[0262] In addition, there is a small exception in the (Java) UDP sending in HBuilderX's [H5+APP project]. The byte range of its sent data packets is 0~127, -1~-128. To unify them into the full range of bytes 0~255, conversion is required:

[0263] b=(b<128)?b:(b-256). This simple conversion is no problem for modern mobile phones.

[0264] (10) The node module ESP-12 has only 40K RAM. If the program is slightly larger, it will exceed the restart limit, and there is no effective way to exit the executed program. For this reason, the idea is to split the large program into small programs, and record the working process status by resetting the RTC User Memory Module or Flash file without clearing it. After automatic reset and restart, init.lua enters a corresponding program according to the working process status recorded in the RTC User Memory or Flash file. After the execution is completed (adjust the RTC User Memory Module or Flash file record), reset and restart again to cycle this process. Generally speaking, long-term working parameters are recorded by Flash files and will not be lost when power is off. For example, the get_mqtt.lua program records the MQTT device login parameters in the mqtt.txt file. After power-on or reset and restart, the node module self-starting program init.lua will enter the Tencent mqtt.lua working program according to the mqtt.txt file, avoiding the get_mqtt.lua program occupying memory at the same time (cannot exit unless reset); the temporary working process status is recorded by RTC Memory. If an abnormality is detected and a WeChat alarm is required (29K memory is required, and only the WeChat program can be run separately), after automatic reset, init.lua enters the WeChat program (excluding the original working program) according to RTC Memory. After sending WeChat, the RTC Memory status is restored and reset and restarted to return to the original working program (avoiding the WeChat program occupying memory at the same time).

[0265] (11) As an application field of the present invention, a technical solution is provided to solve the problem of high-speed timed sampling and centralized data transmission in batches. It is proposed to use a high-priority timed interrupt of an ordinary typical single-chip microcomputer (such as the typical domestic high-end configuration Macrocrystalline STC15W408AS series with a price of 3 yuan) to perform high-speed sampling. When the sampled data accumulates to a certain amount, the data is transmitted to the node module (Nodemcu ESP-12) with low priority. After receiving the data, the node module forwards the centralized sampled data to the computer or mobile phone according to the above-mentioned LAN UDP or Internet MQTT communication mode.

[0266] The reason why a typical single-chip microcomputer is added to achieve high-speed sampling is that neither the JS scripting language nor the Nodemcu LUA scripting language can find the (interrupt) priority setting for program execution (the execution order setting of a large number of asynchronous processing programs in JS, including ES6's Promise, actually only refers to the execution order setting of the startup program, not that a low-priority program can be interrupted by a high-priority program during execution. The same is true for Nodemcu LUA, its node.task.post() priority setting module, and no information about interrupt priority setting can be found). In fact, the JS scripting language was originally proposed for the dynamic display effect of web pages, and it is not positioned for real-time operations. No wonder in step (9.4) the mobile JS LAN UDP sending and receiving (HBuilderX H5+JS UDP) is a simple blocking form, and there is no simple way to directly give a unified receiving trigger function form. According to the documentation provided by JS, the addition of ES6's Promise and async await should be able to solve the blocking problem of skt.receive(rpkt) (meaning not using setInterval or setTimeout), but it is actually impossible. Using setInterval or setTimeout already implements asynchronous non-blocking (this is the method used in step 9.4), so it is unnecessary to encapsulate Promise for asynchronous non-blocking.

[0267] But the real problem is that the asynchronous non-blocking implemented by setInterval or setTimeout has the lowest priority for timing execution, and no high-priority timer can be found. In particular, the node module (Nodemcu LUA) used to control sensor sampling cannot find a high-priority timer (it should be set in the RTC Time module, which is the most natural). This is a great pity, which leads to the need to add a typical microcontroller to achieve high-speed sampling. Let's take a look at an application example: a real-time electrocardiogram display device requires ADC sampling to be executed at a priority timing of 500 points per second. After there are 500 points of data (each data is one byte), the whole batch is sent together. Of course, it will be interrupted by the ADC sampling with a higher priority many times during the transmission (ADC sampling will come once every 2 milliseconds, and a 500-byte data packet cannot be transmitted within 2 milliseconds). Fortunately, this typical problem can be perfectly solved by adding a Hongjing STC15W408AS series microcontroller: using the two-level priority interrupt mechanism of the classic traditional 51-type microcontroller, the high-priority timing interrupt executes the high-speed sampling program, and when the data transmission program is executed, it does not affect the timing interrupt to execute high-speed sampling. In addition, the Hongjing STC15W408AS series of single-chip microcomputers can not only solve the problem of priority execution of programs, but also have higher sampling accuracy than ESP-12, and provide up to 8 ADC input ports, and are cheap and small in size. The communication between the STC15W408AS single-chip microcomputer and ESP-12 is very convenient, and can be achieved through the RS serial port (three-wire), SPI (five-wire), or I2C (two-wire; the slave I2C transceiver program on the STC15W408AS side must be written by yourself) supported by both parties. The data reaches the ESP-12 node module and is then forwarded to the computer or mobile phone, which is the theme of this project. Step (9) has summarized the key statements for data transmission and reception in the two network communication modes. In other words, this section actually provides a typical practical example of the present invention.

[0268] (12) The node module and single-chip microcomputer control system can separate the wireless WIFI connection part of the computer or mobile phone from the specific single-chip microcomputer controlled application, so that they can be separated in secondary development or end-user use.

[0269] For the development process: only 1~2 HTML-JS programmers or professional companies who are familiar with the two-way transparent communication based on the local operation of Html-JS on mobile phones or computers and the unified sending and receiving form of full-range byte transparent transmission in the local area network are needed to set the application-related working parameters, so that the working parameter settings can be realized on the computer or mobile phone with intuitive dynamic operation prompts, and the set parameter data can be stored in the node module and the file or Flash EPROM of the single-chip microcomputer. Single-chip microcomputer developers who are not familiar with HTML-JS programming only need to make direct control programming development based on the node module and the file or Flash EPROM data of the single-chip microcomputer, without having to worry about the WIFI connection to the computer or mobile phone to set the working parameters. The node module runs according to the steps to solve the problem of insufficient RAM when installing Nodemcu firmware on ESP-12 node module. (The LUA program in the node module is split into small programs and runs separately. The working status is recorded through RTC User Memory Module or Flash file. After automatic reset and restart, init.lua decides to enter a corresponding small program and run it separately according to the working status recorded by RTC User Memory Module or Flash file. After the operation is completed, reset and restart again to cycle this process.) According to the files or Flash in the node module and the microcontroller The data status in the EPROM will automatically select to enter the WIFI transparent communication program or the application program directly for control when the node module is reset (it may not involve the network and computer or mobile phone setting working parameter interface design at all. It should be noted here that the programming of network communication and computer or mobile phone setting working parameter interface design is one-time and as universal as possible, so it only needs 1 to 2 programmers familiar with HTML-JS or professional companies to do it. The development of single-chip microcomputers can evolve into many products according to different product electrical appliances and positioning and grading, and each of them needs to be programmed separately by the single-chip microcomputer. For example, a mobile phone operation interface for setting the firepower at a fixed time is designed, which can also be used for rice cookers, health stoves, induction cookers, electric ceramic stoves, etc. Even if these products have different names, it is best that the mobile phone operation interface has corresponding matching. This is just applicable to the local operation of the HTML-JS scripting language emphasized by the present invention. It can be edited with Notepad. It is very convenient to change a few names and directly run locally to see the results).

[0270] For end users: The settings before use are connected to a computer or mobile phone via wireless WIFI, and there are dynamic prompts on the computer or mobile phone for intuitive operation. After setting the working parameters, when you need to use it, power on or press the reset button to start working. At this time, it is completely unrelated to the computer or mobile phone. You can press buttons and several LED indicators to select work. To re-enter the WIFI connection computer or mobile phone settings, you can press a key or double-click or long press, or press two keys at the same time, or press and hold a key when powering on to enter.

[0271] For example, when a digital alarm clock is replaced with a battery, the date and time must be reset, and when a time-reserved rice cooker is powered off or the time is long, the time setting operation is very easy to forget, because there are only 3 to 4 buttons on the panel, which are realized by various short-press and long-press combinations. Many people are afraid to do this, especially the elderly. Even after finally adjusting the date and time, it is still unclear whether this is the current time or the alarm or the start and stop time. If you make a mistake, you have to start all over again! And using a computer or a mobile phone to do this is convenient and intuitive, and if you make a mistake, you just need to modify it. In particular, the HTML-JS language emphasized by the present invention itself has a date and time control, which makes the computer or mobile phone interface design very simple. On the other hand, it does not need to be connected to a computer or a mobile phone when using it, just press the start and stop button or the power switch, and the working status can be seen from several LED indicators. This is also suitable for the elderly at home. Usually, just press the start and stop button or the power switch, and the children use a computer or a mobile phone to set it when there are complex requirements. And this mode of home appliances has low production cost, simplicity and reliability.

[0272] This section actually provides a typical practical example of the present invention.

[0273] The full text contains a lot of content, which can be summarized as follows: By fully exploring the potential application characteristics of Cloud IoT MQTT combined with Nodemcu, a mobile terminal (referring to mobile phones or computers) Html-JS program localization operation mode based on full-range byte transparent transmission as the basis of network communication is established. In this mode, Cloud IoT MQTT is proposed to supplement the direct WeChat function and provide a local execution of IoT Html-JS general program, which not only reduces the user's programming workload and avoids low-level duplication, but also provides users with programming examples.

[0274] Because this mobile Html-JS program localization operation mode based on full-range byte transparent transmission is particularly suitable for combination with single-chip microcomputers, and there is no need for MQTT in the local area network (especially the rule engine that beginners are most afraid of), the local area network UDP communication form of this mode is also proposed, and the supporting program structure is proposed.

[0275] Also note that the Nodemcu LUA general program in the node module is usually large in size and can be put into FlashROM to run LFS, which can run large programs while taking up less RAM (see nodemcu.readthedocs.io / en / dev / lfs for details).

[0276] Before Tencent Cloud IoT MQTT adds the WeChat function, the mobile phone standby real-time alarm can temporarily use a third-party WeChat website, see step (8.3).

[0277] For the sake of intuitive expression, this article has been using "Tencent Cloud IoT MQTT". In fact, similar mainstream Internet cloud services include: Alibaba Cloud, Huawei Cloud, OneNet, etc. They are not standard MQTT, but MQTT with limited Topic to add rule engine (this article calls it device login MQTT). That is, for MQTT to send WeChat, it should be:

[0278] To log in to Alibaba Cloud by scanning the QR code, you can use the Alipay APP or the DingTalk APP. The recipients are the DingTalk groups, and the messages sent are DingTalk messages.

[0279] To log in to Huawei Cloud by scanning the QR code, use the Huawei mobile browser. The recipients are the Huawei mobile phone contacts, and the messages sent are Huawei Cloud messages.

Claims

1. A method for transparent transmission of Internet of Things bytes based on H5JS local programming, which is implemented on the Internet of Things structure, and Html-JS local running program on a mobile phone or computer, and the method for transparent transmission of Internet of Things bytes includes the following steps: (1) For the Internet wide area network, an Internet of Things structure is constructed, and the Internet of Things structure includes: Tencent Cloud IoT MQTT server, node module, mobile phone and / or computer, the node module and mobile phone and / or computer are all connected to the MQTT server to achieve two-way communication from mobile phone or computer to node module; (2) Select the ESP-12 series node module, install the Nodemcu firmware, and connect to the MQTT server through the MQTT module in the Nodemcu firmware; (3) As a network backend MQTT service, no user programming is required, and the user's workflow adjustment does not require changing its program; when creating a new product in Tencent Cloud IoT MQTT, the default JSON data format is changed to a custom data format, and the binary byte stream data transmission mode is selected through the LUA language programming of the node module and the JS language programming of the mobile phone or computer, so that each byte in the data transmission package is in the full range of 0-255, and the network communication between the mobile phone or computer and the node module through MQTT is a two-way direct byte transmission without encoding / decoding, referred to as full-range byte transparent transmission; (3.1) Define control commands based on full-range byte transparent transmission, including full-range byte file transmission from the mobile phone or computer end to the node module end; (3.2) According to the full-range byte transparent transmission, all data processing in the node module except for direct IO device driving is transmitted to the mobile phone or computer for processing through bidirectional full-range byte transparent transmission; (4) Control the operation permissions of n users on mobile phones or computers to control m node modules by setting the Tencent Cloud IoT MQTT rule engine; (5) The computer has a browser, and the browser runs the HTML-JS scripting language locally; the mobile phone runs the HTML-JS scripting language locally, and converts the HTML-JS program into a mobile app through HBuilderX; the connection between the mobile phone or computer and the MQTT server is realized through JS plus the plug-in mqtt.js; (5.1) Programs other than those that present the personalized needs of users will be uniformly programmed by professional companies and designed into the following general programs that can be executed separately and serve as programming demonstrations: mqttconnection.htm: Generate UserName and Password based on ProductID, device name, and Hmac signature algorithm, and generate login parameters and connection detection for Tencent Cloud IoT MQTT device on the computer; mqttcommunication.htm: Multiple computers run at the same time to test the data or Chinese characters sent between MQTT login devices; enduser.lua: node module connects to WIFI; get_mqtt.htm, get_mqtt.lua: The computer sets the MQTT device login parameters of the node module through HTTP to test whether the node module MQTT connection is successful; init.lua: the self-starting program after the node module is reset; Tencent mqtt.lua: node module working program, supporting user demonstration programs mqtt_wx.htm and mqtt_wx.apk; Simple push http.htm: test the automatic WeChat notification from the computer; Jiantui http.lua: node module automatically sends WeChat notification test; Provide demonstration programs for users to realize personalized control display interface or management process: mqtt_wx.htm: Tencent Cloud MQTT IoT operation control test and demonstration program on PC; mqtt_wx.apk: mobile Tencent Cloud MQTT IoT operation control test and demonstration program; usrprg.lua: user-defined program in the node module, mainly writes user-defined global function usrdfn(); (6) Perform initialization settings before the node module works normally, including the following steps: (6.1) When powered on or reset, the LED indicator of the node module flashes slowly. It is searching for WIFI during the slow flashing. The slow flashing will last for a long time. At this time, the user uses a computer to connect to the WIFI of the node module AP: NodeMCU_6-bit random number, and uses a browser to access 192.168.4.

1. The searched WIFI will be listed. The user selects the WIFI that he can access, enters the password, and then resets and restarts; (6.2) After the node module is restarted, the LED indicator of the node module flashes slowly for a few seconds, then flashes quickly, and the LED indicator becomes bright, indicating that the WIFI connection is successful, but the MQTT is not connected. At this time, the node module automatically enters get_mqtt.lua Device login parameter setting program, the user's computer is set back to the WIFI that he can access, double-click to start the get_mqtt.htm program in the computer, enter the device parameters and username / password settings for Tencent Cloud IoT MQTT login, fill in the device parameters ProductID, device name, and DeviceSceret set in Tencent Cloud IoT MQTT one by one, and the get_mqtt.htm program will automatically generate UserName and Password, and test whether the MQTT connection login of the node module is successful or not; if successful, click to keep, and the device login parameters ProductID, device name, UserName, and Password of the successful MQTT connection will be automatically written into the mqtt.txt file in the node module. After power-on or reset and restart, the node module will automatically enter the MQTT connection login success state; if it is always unsuccessful, the user double-clicks to start the mqtt connection.htm program in the computer. The program has the same Tencent Cloud IoT MQTT device login parameter setting interface as the get_mqtt.htm program. Use the computer browser to directly connect to Tencent Cloud IoT MQTT to verify the connectivity of each MQTT device login parameter; (6.3) Once the node module MQTT connection login is successful, the mqtt.txt file is generated. After that, whenever the node module is powered on or reset, it will automatically enter the Tencent mqtt.lua MQTT response program to realize the measurement and control of the node module of the Internet of Things. The LED indicator will flash slowly first, then quickly, and finally turn off, indicating that the MQTT connection is successful; (7) In the Tencent Cloud IoT MQTT protocol, the MQTT WeChat and alarm functions are added. The specific operations of the MQTT WeChat function are as follows: by adding a specified Topic, publish (topic, msg) to the Topic, that is, send the information msg to WeChat. The recipients of WeChat are determined by any of the following three settings: (7.1) The WeChat APP on the mobile phone of the person who manages the Tencent Cloud Service login account must be able to scan the code to log in to the Tencent Cloud Service and send WeChat messages. In this case, the WeChat ID of the person who manages the Tencent Cloud Service login account is the recipient of the WeChat message, Topic = Product ID / Device Name / WX1; (7.2) After logging in with the Tencent Cloud Service Management account, enter the MQTT work settings page and enter the WeChat ID number or group name of the WeChat sender or recipient. The individual or group name entered must be the individual or group to which WeChat can send in the WeChat address book of the account logged in with the Cloud Service Management account. Topic = product ID / device name / WX2; (7.3) After logging in with the cloud service management account, enter the MQTT work setting page. All the individuals in the WeChat address book of the cloud service management account that can be sent to by WeChat, use the WeChat APP on your mobile phone to scan the QR code on the MQTT work setting page. Those who pass the verification are the individuals who can be sent to by WeChat, Topic = product ID / device name / WX2; When MQTT sends WeChat to the recipient group Topic = product ID / device name / WX2, it means multiple groups of people, which are further subdivided into Topic = product ID / device name / WX2 / user 1; Topic = product ID / device name / WX2 / user 2; (7.4) When the Topic of MQTT WeChat is product ID / device name / WXA1, WXA2, not only WeChat is sent, but also an alarm is triggered; Also includes: Two-way transparent communication based on Html-JS running locally on mobile phones or computers within the local area network: (8) In the local area network, the two-way transparent communication between the mobile phone or computer and the node module adopts the UDP network protocol without backend service. Since the computer browser does not support UDP, a WS service conversion to UDP is added locally on the computer, and it is limited to an exe program that does not need to be installed. The computer browser accesses the WS service conversion to UDP through the WebSocket protocol; (8.1) The mobile terminal has introduced UDP support through java.net in the H5+APP project of HBuilderX. UDP communication is realized through Html5+JS programming and the mobile APP program is generated by HBuilderX, without the need to convert WS service to UDP; (8.2) Utilize UDP broadcast mode to solve the problem of unfixed WIFI connection IP, realize the named communication of multi-node modules in LAN, and simplify the whole system to only 4 programs: WS service to UDP.exe: computer program, WebSocket protocol WS service to UDP protocol, first started and always running; Naming program.htm: The computer browser Html5-JS runs locally to connect to the WS service program. When each node module is running, other node modules will be turned off. Only the node module currently being named is online. Enter the name in the naming program interface. The computer will record the unique number of this node module and the entered name in the local storage of the computer; it also includes setting WIFI and password; Test program.htm: The computer browser Html5-JS runs locally to connect to the WS service program. When multiple node modules are running online at the same time, the computer tests each node module by naming to confirm the two-way data communication, and observes whether the LED indicator of the node module is normal or not; it is also a programming demonstration program provided to users. The computer browser accesses the WS service through the WebSocket protocol; if there is only one node module, the above naming process is not required, and it can also be directly connected without a router, that is, the computer WIFI is directly connected to the AP of the node module; Node module.lua: This is the only supporting program for the node module. The operation of the above HTML-JS programs, including mobile phone APP, WIFI and password settings, are interpreted and executed by the LUA program through sending and receiving UDP data; the UDP data sending and receiving of the LUA program is the net.udpsocket operation of the net module in the nodemcu firmware; For mobile phones, the above named program.htm and test program.htm are changed to named program.apk and test program.apk, the operation method remains unchanged, and there is no need to convert the WS service to UDP.exe computer program; (8.3) The node module sends a real-time alarm to WeChat through a third party WeChat website. Specifically, nodemcu sends HTTP GET. When downloading nodemcu firmware, select http module, and LUA program uses http.get() to send. (9) The unified sending and receiving form of the full range byte transparent transmission is specifically: (9.1) Sending and receiving JS MQTT on mobile phone or computer: MQTT object.onMessageArrived=function (received object) {topic=received object.destinationName; data=received object.payloadBytes} Send object = new Paho.MQTT.Message(data); Send object.destinationName=topic MQTT object.send(sending object) or MQTT object.publish(topic, data, 1); (9.2) Node module end LUA MQTT sending and receiving: MQTT object: on("message", function(MQTT object, topic, data) end) MQTT object: publish(topic,data,1); (9.3) PC-side JS LAN WS sending and receiving: WS object = new WebSocket("ws: / / 127.0.0.1:8183") WS object.onopen=function() {Network connection notification} WS object.onmessage=function(ev){received data=new Uint8Array(ev.data) WS object.send (send data); (9.4) Mobile JS LAN UDP sending and receiving: UDP sending and receiving object = new DatagramSocket (local port) Send data packet = new DatagramPacket (send data, send data length, Addr.getByName (other party IP), other party port) UDP transceiver object.send (send data packet) Received datagram = new DatagramPacket(abf, abf.length) UDP send and receive object.receive (receive data packet) Received data packet.getData(); Received data packet.getLength(); The other party's port = received data packet.getPort(); The other party's IP = received data packet.getAddress(); (9.5) Node module end LUA LAN UDP sending and receiving: UDP connection object: on("receive", function(UDP connection object, received data, peer port, peer IP) end) UDP connection object: send (other party port, other party IP, send data); (10) Solve the problem of insufficient RAM when installing Nodemcu firmware on the ESP-12 node module. This step includes: splitting the LUA large program in the node module into small programs and running them separately. Recording the working status through the RTC User Memory Module or Flash file. After automatic reset and restart, init.lua decides to enter a corresponding small program and run it separately according to the working status recorded by the RTC User Memory Module or Flash file. After the operation is completed, reset and restart again to cycle this process. (11) Use the high-priority timer interrupt of the domestic STC15W408AS series microcontroller to perform high-speed sampling. When the sampled data accumulates to a certain amount, the data is transmitted to the node module at a low priority. After the node module receives the data, it forwards the centrally sent sampled data to the computer or mobile phone according to the above step (9) LAN UDP or Internet MQTT communication mode; (12) The method also includes establishing a mode for separating the microcontroller working parameter setting from the working, specifically: the node module and the microcontroller control system separate the wireless WIFI connection part of the computer or mobile phone from the specific microcontroller control application, which can be separated in both secondary development and end-user use; For the development process: only one or two HTML-JS programmers or professional companies who are familiar with the two-way transparent communication based on the local operation of Html-JS on mobile phones or computers and the unified sending and receiving form of full-range byte transparent transmission in the local area network are needed to set the application-related working parameters, so that the working parameter settings can be realized on the computer or mobile phone with intuitive dynamic operation prompts, and the set parameter data can be stored in the node module and the file or Flash EPROM of the microcontroller; the microcontroller developers who are not familiar with HTML-JS programming only need to make programming development directly for control according to the data in the file or Flash EPROM of the node module and the microcontroller, without worrying about the WIFI connection to the computer or mobile phone to set the working parameters; the node module operation solves the steps of insufficient RAM memory when the ESP-12 node module is installed with Nodemcu firmware; according to the data status in the file or FlashEPROM of the node module and the microcontroller, it will automatically select to enter the WIFI transparent communication program or the application program directly for control when the node module is reset; For end users: The settings before use are connected to the computer or mobile phone through wireless WIFI, and there are dynamic prompts on the computer or mobile phone for intuitive operation; after setting the working parameters, when you need to use it, power on or press the reset button to start the work. At this time, it has nothing to do with the computer or mobile phone. You can press buttons and several LED indicators to select work; to re-enter the WIFI connection to the computer or mobile phone settings, pressing a key, double-clicking, long pressing, or two keys at the same time, or holding down a key when powering on are all common entry methods.

2. The method according to claim 1, characterized in that Regarding the Nodemcu LUA program in the node module, put it in the Flash ROM and run it in LFS.

3. The method according to claim 1, characterized in that: Before adding the WeChat function to Tencent Cloud IoT MQTT, the mobile phone standby real-time alarm temporarily uses a third-party WeChat website to send messages, according to step (8.3).

4. The method according to claim 1, characterized in that: The Tencent Cloud IoT MQTT is replaced with the IoT MQTT of Alibaba Cloud, Huawei Cloud or OneNet.

Citation Information

Patent Citations

  • Method for applying TCP / IP protocol in Mesh network

    CN108092830A

  • Intranet penetration method and system based on websocket

    CN110661858A

  • The method of making dynamic internet IP addressedcomputers Web servers, FTP servers and motion pictureInternet ...

    KR1020010078466A

Cited By

  • Silicon controlled rectifier quasi-frequency conversion method and application of air conditioner fan single-phase asynchronous motor driving module

    CN115694312A

  • A silicon controlled quasi-frequency conversion method and a single-phase asynchronous motor driving module application of an air conditioner fan

    CN115694312B

  • Wireless serial Internet of Things and multipoint wireless linkage monitoring device only needing JS programming

    CN121441928A