Interaction method, device, computer equipment and storage medium of IoT devices

By implementing HTTP login in the IOT device, if the websocket login fails more than three times, the system switches to the tcpsocket method for data interaction, which solves the problem of abnormal network interaction between the IOT device and the server, and improves the success rate and compatibility of data interaction.

CN114598689BActive Publication Date: 2024-08-23SHENZHEN BOYUE DOMESTIC GOODS
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202210221181.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-03-08
Publication Date
2024-08-23
Estimated Expiration
2042-03-08

AI Technical Summary

Technical Problem

When IOT devices interact with servers, network anomalies are likely to occur due to routers filtering out websocket data packets. It is difficult for existing technologies to effectively improve the success rate of connection interactions.

Method used

After the IOT device successfully logs in through an HTTP connection request, if the websocket login fails more than three times, it switches to the tcpsocket mode for data interaction and uses the tcp protocol to establish a connection.

Benefits of technology

Improved the success rate and compatibility of network data interaction between IOT devices and servers, ensuring backup connection through tcpsocket when websocket login fails, ensuring the stability of data transmission.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114598689B
    Figure CN114598689B
Patent Text Reader

Abstract

The present invention provides an interaction method, device, computer equipment and storage medium for IOT devices. The method includes sending an HTTP connection request from an IOT device to a server, and after the server returns a connection response message indicating that the connection is successful, the HTTP login is successful; after the HTTP login is successful, the IOT device initiates a websocket login request to the server, and when the number of failed login requests does not exceed three times, the websocket login request will continue to be initiated, and after the login is successful, the IOT device and the server interact with each other in the form of websocket; when the number of failed websocket login requests initiated by the IOT device to the server is greater than three times, the IOT device initiates a login request to the server in the form of tcpsocket, and then establishes a connection with the server in the form of tcp for data interaction. The present invention can improve the success rate of network data interaction between IOT devices and servers, and improve the compatibility of device network interaction.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of device interaction technology, and in particular to an interaction method, device, computer equipment and storage medium for IoT devices. Background Art

[0002] The websocket protocol is an application layer protocol based on the HTTP protocol. Before the websocket protocol appeared, the connection established through the HTTP protocol was non-persistent and one-way. Therefore, when timely communication is required between the client and the server, in most cases, polling is used for communication, which consumes a lot of traffic and server resources.

[0003] IoT devices that use websocket as a network communication protocol generally use a single websocket login request method before interacting with the server. This method will cause network interaction abnormalities when encountering some routers that filter out websocket data packets. Summary of the invention

[0004] The technical problem to be solved by the present invention is to provide an interaction method, device, computer equipment and storage medium for IOT devices, aiming to improve the success rate of connection and interaction between IOT devices and servers.

[0005] In order to solve the above technical problems, the technical solution adopted by the present invention is: an interaction method of IOT devices, comprising the following steps:

[0006] The HTTP login is successful when the IOT device sends an HTTP connection request to the server and the server returns a connection response indicating that the connection is successful.

[0007] When HTTP login is successful, the IOT device initiates a websocket login request to the server. If the number of failed login requests does not exceed three times, the websocket login request will continue to be initiated. After the login is successful, the IOT device and the server will exchange data in the form of websocket.

[0008] When the number of failed websocket login requests initiated by the IoT device to the server is greater than three times, the IoT device will use tcpsocket to initiate a login request to the server, and then establish a connection with the server in the form of tcp for data exchange.

[0009] Furthermore, the IOT device sends an HTTP connection request to the server, and the server returns a connection response message indicating that the connection is successful. Then the steps for successful HTTP login specifically include:

[0010] The IoT device sends an HTTP connection request to the server;

[0011] After receiving the HTTP connection request sent by the IOT device, the server returns the connection response information of the server to the IOT device;

[0012] The IoT device parses the connection response information from the server to determine whether the connection is successful.

[0013] If the parsed connection response information indicates that the connection is successful, the HTTP login on the IOT device is successful.

[0014] Furthermore, the connection response information returned by the server includes the IP address and port number of the server.

[0015] Furthermore, when the number of failed websocket login requests initiated by the IoT device to the server is greater than three times, the IoT device initiates a login request to the server using TCPsocket, and then establishes a connection with the server in the form of TCP for data interaction. Specifically, the steps include:

[0016] When the number of failed websocket login requests initiated by the IoT device to the server is greater than three times, the server's IP address and port number are parsed from the connection response information of the server;

[0017] According to the server's IP address and port number, the IOT device uses TCP socket to initiate a login request to the server.

[0018] After successful login, the IOT device establishes a connection with the server in the form of TCP for data exchange.

[0019] The present invention also provides an interactive device for IOT devices, comprising:

[0020] HTTP login module, used to send HTTP connection request to server through IOT device. When server returns connection response information indicating successful connection, HTTP login is successful.

[0021] Websocket login module, used for when HTTP login is successful, the IOT device side initiates a websocket login request to the server side. If the number of login requests fails to exceed three times, the websocket login request will continue to be initiated. After the login is successful, the IOT device side and the server will exchange data in the form of websocket;

[0022] The Tcpsocket login module is used when the IOT device fails to initiate a websocket login request to the server for more than three times. In this case, the IOT device will use the tcpsocket method to initiate a login request to the server, and then establish a connection with the server in the form of tcp for data exchange.

[0023] Furthermore, the HTTP login module is specifically used to:

[0024] The IoT device sends an HTTP connection request to the server;

[0025] After receiving the HTTP connection request sent by the IOT device, the server returns the connection response information of the server to the IOT device;

[0026] The IoT device parses the connection response information from the server to determine whether the connection is successful.

[0027] If the parsed connection response information indicates that the connection is successful, the HTTP login on the IOT device is successful.

[0028] Furthermore, in the HTTP login module, the connection response information returned by the server includes the IP address and port number of the server.

[0029] Furthermore, the Tcpsocket login module is specifically used for:

[0030] When the number of failed websocket login requests initiated by the IoT device to the server is greater than three times, the server's IP address and port number are parsed from the connection response information of the server;

[0031] According to the server's IP address and port number, the IOT device uses TCP socket to initiate a login request to the server.

[0032] After successful login, the IOT device establishes a connection with the server in the form of TCP for data exchange.

[0033] The present invention also provides a computer device, which includes a memory and a processor. The memory stores a computer program, and the processor implements the above-mentioned IOT device interaction method when executing the computer program.

[0034] The present invention also provides a storage medium, wherein the storage medium stores a computer program, and when the computer program is executed by a processor, the above-mentioned IOT device interaction method can be implemented.

[0035] The beneficial effect of the present invention is that after the IOT device successfully performs HTTP login to the server, websocket login is performed. After the websocket login is successful, the IOT device can interact with the server through the websocket protocol. If three websocket logins fail, Tcpsocket login is selected. After the Tcpsocket login is successful, the IOT device interacts with the server through TCP, thereby improving the success rate of network data interaction between the IOT device and the server and improving the compatibility of device network interaction. BRIEF DESCRIPTION OF THE DRAWINGS

[0036] The specific structure of the present invention is described in detail below in conjunction with the accompanying drawings.

[0037] Figure 1 A flow chart of an interaction method of an IOT device according to an embodiment of the present invention;

[0038] Figure 2 This is a flow chart of HTTP login in an embodiment of the present invention;

[0039] Figure 3 This is a Tcpsocket login flow chart of an embodiment of the present invention;

[0040] Figure 4 It is a block diagram of an interaction module of an IOT device according to an embodiment of the present invention;

[0041] Figure 5 A schematic block diagram of a computer device according to an embodiment of the present invention. DETAILED DESCRIPTION

[0042] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0043] It should be understood that when used in this specification and the appended claims, the terms "include" and "comprises" indicate the presence of described features, integers, steps, operations, elements and / or components, but do not exclude the presence or addition of one or more other features, integers, steps, operations, elements, components and / or combinations thereof.

[0044] It should also be understood that the terms used in this specification of the present invention are only for the purpose of describing specific embodiments and are not intended to limit the present invention. As used in the specification of the present invention and the appended claims, unless the context clearly indicates otherwise, the singular forms "a", "an" and "the" are intended to include plural forms.

[0045] It should be further understood that the term "and / or" used in the present description and the appended claims refers to any and all possible combinations of one or more of the associated listed items, and includes these combinations.

[0046] like Figure 1 As shown, the first embodiment of the present invention is: an interaction method of IOT devices, comprising the following steps:

[0047] S10, sending an HTTP connection request to the server through the IOT device, and after the server returns a connection response message indicating that the connection is successful, the HTTP login is successful;

[0048] S20. When HTTP login is successful, the IOT device initiates a websocket login request to the server. If the number of failed login requests does not exceed three times, the websocket login request will continue to be initiated. After the login is successful, the IOT device and the server will exchange data in the form of websocket.

[0049] S30. When the number of failed websocket login requests initiated by the IoT device to the server is greater than three times, the IoT device initiates a login request to the server using tcpsocket, and then establishes a connection with the server in the form of tcp for data exchange.

[0050] like Figure 2 As shown, in step S10, the IOT device sends an HTTP connection request to the server, and the server returns a connection response message indicating that the connection is successful. Then the steps for successful HTTP login specifically include:

[0051] S11, the IOT device sends an HTTP connection request to the server;

[0052] S12, after receiving the HTTP connection request sent by the IOT device, the server returns the connection response information of the server to the IOT device;

[0053] S13, the IOT device parses the connection response information of the server, and determines whether the parsed connection response information is successfully connected;

[0054] S14. If the parsed connection response information indicates that the connection is successful, the HTTP login on the IOT device is successful.

[0055] Furthermore, the connection response information returned by the server includes the IP address and port number of the server.

[0056] like Figure 3 As shown, in step S30, when the number of failed websocket login requests initiated by the IOT device to the server is greater than three times, the IOT device initiates a login request to the server using tcpsocket, and then establishes a connection with the server in the form of tcp for data interaction. Specifically, the steps include:

[0057] S31. When the number of failed websocket login requests initiated by the IoT device to the server is greater than three times, the IP address and port number of the server are parsed from the connection response information of the server.

[0058] S32. According to the IP address and port number of the server, the IOT device uses TCP socket to initiate a login request to the server.

[0059] S33. After successful login, the IOT device establishes a connection with the server in the form of TCP for data exchange.

[0060] The purpose of tcpsocket communication is to solve the problem that some IOT devices block websocket data packets, causing abnormal network interaction on the device side.

[0061] In TCP socket communication: TCP protocol is a connection-oriented communication protocol, that is, before transmitting data, a logical connection is established between the sender and the receiver, and then the data is transmitted. In the TCP connection process, the IOT device sends a connection request to the server. Each connection creation requires a "three-way handshake". After the "handshake" between the two parties, TCP will establish a full-duplex communication between the two applications. When communicating, both ends of the communication need to create a socket object. Socket is the basic operation unit of network communication that supports TCP / IP protocol, and contains five types of information necessary for network communication: the protocol used for the connection, the IP address of the local host, the IP address of the local host, the local remote protocol port, the IP address of the remote host, and the protocol port of the remote process.

[0062] The beneficial effect of the embodiment of the present invention is that after the IOT device successfully performs HTTP login to the server, websocket login is performed. After the websocket login is successful, the IOT device can interact with the server through the websocket protocol. If three websocket logins fail, Tcpsocket login is selected. After the Tcpsocket login is successful, the IOT device interacts with the server through TCP, thereby improving the success rate of network data interaction between the IOT device and the server, and improving the compatibility of device network interaction.

[0063] like Figure 4 As shown, another embodiment of the present invention is an interactive device for IOT devices, comprising:

[0064] HTTP login module 10, used to send HTTP connection request to server through IOT device, and when server returns connection response information indicating successful connection, HTTP login is successful;

[0065] Websocket login module 20, used for initiating a websocket login request from the IOT device to the server after HTTP login is successful. If the number of failed login requests does not exceed three times, the websocket login request will continue to be initiated. After successful login, data is exchanged between the IOT device and the server in the form of websocket;

[0066] The Tcpsocket login module 30 is used to, when the number of failed websocket login requests initiated by the IOT device to the server is greater than three times, the IOT device will use the tcpsocket method to initiate a login request to the server, and then establish a connection with the server in the form of tcp for data exchange.

[0067] Furthermore, the HTTP login module 10 is specifically used for:

[0068] The IoT device sends an HTTP connection request to the server;

[0069] After receiving the HTTP connection request sent by the IOT device, the server returns the connection response information of the server to the IOT device;

[0070] The IoT device parses the connection response information from the server to determine whether the connection is successful.

[0071] If the parsed connection response information indicates that the connection is successful, the HTTP login on the IOT device is successful.

[0072] Furthermore, in the HTTP login module 10, the connection response information returned by the server includes the IP address and port number of the server.

[0073] Furthermore, the Tcpsocket login module 30 is specifically used for:

[0074] When the number of failed websocket login requests initiated by the IoT device to the server is greater than three times, the server's IP address and port number are parsed from the connection response information of the server;

[0075] According to the server's IP address and port number, the IOT device uses TCP socket to initiate a login request to the server.

[0076] After successful login, the IOT device establishes a connection with the server in the form of TCP for data exchange.

[0077] It should be noted that those skilled in the art can clearly understand that the specific implementation process of the interaction device and each unit of the above-mentioned IOT device can refer to the corresponding description in the aforementioned method embodiment, and for the convenience and brevity of description, it will not be repeated here.

[0078] The above-mentioned IOT device interaction device can be implemented in the form of a computer program, which can be used in Figure 5 Runs on the computer device shown.

[0079] See also Figure 5 , Figure 5 5 is a schematic block diagram of a computer device provided in an embodiment of the present application. The computer device 500 may be a terminal or a server, wherein the terminal may be an electronic device with communication functions such as a smart phone, a tablet computer, a laptop computer, a desktop computer, a personal digital assistant, and a wearable device. The server may be an independent server or a server cluster composed of multiple servers.

[0080] See also Figure 5 The computer device 500 includes a processor 502 , a memory and a network interface 505 connected via a system bus 501 , wherein the memory may include a non-volatile storage medium 503 and an internal memory 504 .

[0081] The non-volatile storage medium 503 can store an operating system 5031 and a computer program 5032. The computer program 5032 includes program instructions, and when the program instructions are executed, the processor 502 can execute an interaction method of an IOT device.

[0082] The processor 502 is used to provide computing and control capabilities to support the operation of the entire computer device 500 .

[0083] The internal memory 504 provides an environment for the operation of the computer program 5032 in the non-volatile storage medium 503. When the computer program 5032 is executed by the processor 502, the processor 502 can execute an interaction method of an IOT device.

[0084] The network interface 505 is used to communicate with other devices over the network. Figure 5 The structure shown in the figure is merely a block diagram of a portion of the structure related to the solution of the present application, and does not constitute a limitation on the computer device 500 to which the solution of the present application is applied. The specific computer device 500 may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.

[0085] The processor 502 is used to run the computer program 5032 stored in the memory to implement the above-mentioned IOT device interaction method.

[0086] It should be understood that in the embodiment of the present application, the processor 502 may be a central processing unit (CPU), and the processor 502 may also be other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. Among them, the general-purpose processor may be a microprocessor or the processor may also be any conventional processor, etc.

[0087] It can be understood by those skilled in the art that all or part of the processes in the method for implementing the above embodiment can be completed by instructing the relevant hardware through a computer program. The computer program includes program instructions, and the computer program can be stored in a storage medium, which is a computer-readable storage medium. The program instructions are executed by at least one processor in the computer system to implement the process steps of the embodiment of the above method.

[0088] Therefore, the present invention also provides a storage medium. The storage medium may be a computer-readable storage medium. The storage medium stores a computer program, wherein the computer program includes program instructions. When the program instructions are executed by a processor, the processor executes the above-mentioned IOT device interaction method.

[0089] The storage medium may be a USB flash drive, a mobile hard disk, a read-only memory (ROM), a magnetic disk, or an optical disk, etc., which are computer-readable storage media that can store program codes.

[0090] Those of ordinary skill in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described in terms of function in the above description. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of the present invention.

[0091] In the several embodiments provided by the present invention, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of each unit is only a logical function division, and there may be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed.

[0092] The steps in the method of the embodiment of the present invention can be adjusted in order, combined and deleted according to actual needs. The units in the device of the embodiment of the present invention can be combined, divided and deleted according to actual needs. In addition, the functional units in the various embodiments of the present invention can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit.

[0093] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a storage medium. Based on this understanding, the technical solution of the present invention is essentially or the part that contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions for a computer device (which can be a personal computer, terminal, or network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention.

[0094] The above is only a specific embodiment of the present invention, but the protection scope of the present invention is not limited thereto. Any technician familiar with the technical field can easily think of various equivalent modifications or replacements within the technical scope disclosed by the present invention, and these modifications or replacements should be included in the protection scope of the present invention. Therefore, the protection scope of the present invention shall be based on the protection scope of the claims.

Claims

1. An interactive method for IOT devices, characterized in that: The following steps are included: The HTTP login is successful when the IOT device sends an HTTP connection request to the server and the server returns a connection response indicating that the connection is successful. When HTTP login is successful, the IOT device initiates a websocket login request to the server. If the number of failed login requests does not exceed three times, the websocket login request will continue to be initiated. After the login is successful, the IOT device and the server will exchange data in the form of websocket. When the number of failed websocket login requests sent by the IoT device to the server is greater than three times, the IoT device will use tcpsocket to send a login request to the server, and then establish a connection with the server in the form of tcp for data exchange; The IoT device sends an HTTP connection request to the server. After the server returns a connection response message indicating a successful connection, the steps for successful HTTP login include: The IoT device sends an HTTP connection request to the server; After receiving the HTTP connection request sent by the IOT device, the server returns the connection response information of the server to the IOT device; The IoT device parses the connection response information from the server to determine whether the connection is successful. If the parsed connection response information indicates that the connection is successful, the HTTP login on the IOT device is successful.

2. The interactive method of IOT devices according to claim 1, characterized in that: The connection response information returned by the server includes the server's IP address and port number.

3. The interactive method of IOT devices according to claim 2, characterized in that: When the number of failed websocket login requests sent by the IoT device to the server is greater than three times, the IoT device will use TCPsocket to send a login request to the server, and then establish a connection with the server in TCP form for data interaction. The specific steps include: When the number of failed websocket login requests initiated by the IoT device to the server is greater than three times, the server's IP address and port number are parsed from the connection response information of the server; According to the server's IP address and port number, the IOT device uses TCP socket to initiate a login request to the server. After successful login, the IOT device establishes a connection with the server in the form of TCP for data exchange.

4. An interactive device for an IOT device, characterized in that: include, HTTP login module, used to send HTTP connection request to server through IOT device. When server returns connection response information indicating successful connection, HTTP login is successful. Websocket login module, used for when HTTP login is successful, the IOT device side initiates a websocket login request to the server side. If the number of login requests fails to exceed three times, the websocket login request will continue to be initiated. After the login is successful, the IOT device side and the server will exchange data in the form of websocket; Tcpsocket login module, when the number of failed websocket login requests sent by the IoT device to the server is greater than three times, the IoT device will use tcpsocket to send a login request to the server, and then establish a connection with the server in the form of tcp for data exchange; The HTTP login module is specifically used for: The IoT device sends an HTTP connection request to the server; After receiving the HTTP connection request sent by the IOT device, the server returns the connection response information of the server to the IOT device; The IoT device parses the connection response information from the server to determine whether the connection is successful. If the parsed connection response information indicates that the connection is successful, the HTTP login on the IOT device is successful.

5. The interactive device for IOT devices according to claim 4, characterized in that: In the HTTP login module, the connection response information returned by the server includes the server's IP address and port number.

6. The interactive device for IOT devices according to claim 5, characterized in that: The Tcpsocket login module is specifically used for: When the number of failed websocket login requests initiated by the IoT device to the server is greater than three times, the server's IP address and port number are parsed from the connection response information of the server; According to the server's IP address and port number, the IOT device uses TCP socket to initiate a login request to the server. After successful login, the IOT device establishes a connection with the server in the form of TCP for data exchange.

7. A computer device, characterized in that: The computer device includes a memory and a processor, the memory stores a computer program, and the processor implements the interaction method of the IOT device according to any one of claims 1 to 3 when executing the computer program.

8. A storage medium, characterized in that: The storage medium stores a computer program, and when the computer program is executed by a processor, the interactive method of the IOT device according to any one of claims 1 to 3 can be implemented.