CN113992737A - Internet of things connection method, gateway server and gateway - Google Patents

Internet of things connection method, gateway server and gateway Download PDF

Info

Publication number
CN113992737A
CN113992737A CN202010655333.3A CN202010655333A CN113992737A CN 113992737 A CN113992737 A CN 113992737A CN 202010655333 A CN202010655333 A CN 202010655333A CN 113992737 A CN113992737 A CN 113992737A
Authority
CN
China
Prior art keywords
gateway
target
server
connection
target gateway
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202010655333.3A
Other languages
Chinese (zh)
Inventor
雷鹏
郭中磊
刘英光
王金鹏
于彦平
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Hisense Broadband Multimedia Technology Co Ltd
Original Assignee
Hisense Broadband Multimedia Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Hisense Broadband Multimedia Technology Co Ltd filed Critical Hisense Broadband Multimedia Technology Co Ltd
Priority to CN202010655333.3A priority Critical patent/CN113992737A/en
Publication of CN113992737A publication Critical patent/CN113992737A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/14Session management
    • H04L67/143Termination or inactivation of sessions, e.g. event-controlled end of session
    • H04L67/145Termination or inactivation of sessions, e.g. event-controlled end of session avoiding end of session, e.g. keep-alive, heartbeats, resumption message or wake-up for inactive or interrupted session
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L63/00Network architectures or network communication protocols for network security
    • H04L63/08Network architectures or network communication protocols for network security for authentication of entities
    • H04L63/0876Network architectures or network communication protocols for network security for authentication of entities based on the identity of the terminal or configuration, e.g. MAC address, hardware or software configuration or device fingerprint
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/01Protocols
    • H04L67/12Protocols specially adapted for proprietary or special-purpose networking environments, e.g. medical networks, sensor networks, networks in vehicles or remote metering networks
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/14Session management
    • H04L67/141Setup of application sessions
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/14Session management
    • H04L67/143Termination or inactivation of sessions, e.g. event-controlled end of session
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/14Session management
    • H04L67/148Migration or transfer of sessions

Abstract

The application provides an Internet of things connection method, a gateway server and a gateway, wherein the method comprises the following steps: receiving a short-connection heartbeat keep-alive message sent by a target gateway, wherein the target gateway in a short-connection state with the gateway server sends the short-connection heartbeat keep-alive message to the gateway server, and the target gateway is a gateway which needs to be configured by a target user; if a target gateway ID sent by an application server is received, replying a message to a target gateway corresponding to the target gateway ID according to the target gateway ID, wherein the application server acquires the target gateway ID according to login information of a target user and sends the target gateway ID to the gateway server; and receiving the long connection message sent by the target gateway. According to the Internet of things connection method, the gateway server and the gateway, occupation of the gateway server and network resources is reduced when the gateway and the gateway server are always in a connection state.

Description

Internet of things connection method, gateway server and gateway
Technical Field
The application relates to the technical field of internet of things, in particular to a connection method of internet of things, a gateway server and a gateway.
Background
The wave of the internet of things affects all aspects of society and life. The Internet of things is used for solving the existing life problems by people by utilizing an informatization technology. For example, in a modern home, there are multiple terminals, such as a mobile phone, a tablet computer, a television, an air conditioner, and the like. The interfaces of the terminals are various, and the terminals cannot be interconnected with each other, so that data and information cannot be effectively shared.
With the popularization of intelligent terminals, terminals generally have a networking function, and different terminals are accessed to a public network, so that information interaction and control between different preset terminals (such as a mobile phone and a television) can be realized through the public network. For example, terminals such as a tablet computer, a television, and an air conditioner are connected to a gateway server through a gateway, and a mobile phone terminal controls the gateway through a mobile phone APP (Application), adjusts or sets gateway parameters, and controls a gateway access terminal. In order to ensure that the mobile phone terminal can control the gateway quickly and effectively, the gateway and the gateway server need to be always kept in a connection state. With the increasing number of the connection gateways connected to the gateway server, if the gateway and the gateway server are always in a connection state, a large amount of gateway servers and network resources are occupied.
Disclosure of Invention
The application provides an Internet of things connection method, a gateway server and a gateway, so that when the gateway and the gateway server are always in a connection state, occupation of the gateway server and network resources is reduced.
In a first aspect, the internet of things connection method provided by the present application is applied to a gateway server, and includes:
receiving a short-connection heartbeat keep-alive message sent by a target gateway, wherein the target gateway in a short-connection state with the gateway server sends the short-connection heartbeat keep-alive message to the gateway server, and the target gateway is a gateway which needs to be configured by a target user;
if a target gateway ID sent by an application server is received, replying a message to a target gateway corresponding to the target gateway ID according to the target gateway ID, wherein the application server acquires the target gateway ID according to login information of a target user and sends the target gateway ID to the gateway server;
and receiving the long connection message sent by the target gateway.
In a second aspect, the internet of things connection method provided by the present application is applied to a gateway, and includes:
sending a short-connection heartbeat keep-alive message to a gateway server;
and if the reply message of the gateway server is received, when the message needs to be sent to the gateway server, sending a long connection message to the gateway server.
In a third aspect, the present application provides a gateway server configured to:
receiving a short-connection heartbeat keep-alive message sent by a target gateway, wherein the target gateway in a short-connection state with the gateway server sends the short-connection heartbeat keep-alive message to the gateway server, and the target gateway is a gateway which needs to be configured by a target user;
if a target gateway ID sent by an application server is received, replying a message to a target gateway corresponding to the target gateway ID according to the target gateway ID, wherein the application server acquires the target gateway ID according to login information of a target user and sends the target gateway ID to the gateway server;
and receiving the long connection message sent by the target gateway.
In a fourth aspect, the present application provides a gateway configured to: sending a short-connection heartbeat keep-alive message to a gateway server;
and if the reply message of the gateway server is received, when the message needs to be sent to the gateway server, sending a long connection message to the gateway server.
According to the Internet of things connection method, the gateway server and the gateway, when a target user does not perform target gateway configuration operation, the target gateway and the gateway server are in a short connection state, and the target gateway sends a short connection heartbeat keep-alive message to the gateway server; when a target user needs to perform target gateway configuration operation, the target user logs in an application server, the application server receives login information of the target user, acquires a target user ID according to the login information of the target user, acquires a target gateway ID bound by the target user ID according to the target user ID, and sends the target gateway ID of the target user to a gateway server; the gateway server receives a target gateway ID sent by the application server; the gateway server replies a message to the target gateway according to the ID of the target gateway; and the target gateway receives the reply message of the gateway server, switches the connection state with the gateway server, and sends a long connection message to the gateway server when the message needs to be sent to the gateway server. The gateway server informs the application server that the gateway server has established long connection with a target gateway bound by a target user; the application server receives the notification to inform the target user that the target gateway bound by the application server is ready to be finished, and then the target user can initiate operation control to the target gateway to carry out gateway configuration operation. Therefore, in the internet of things connection method, the gateway server and the gateway provided by the application, switching between short connection and long connection between the gateway server and the gateway is realized, when a target user logs in the application server, the gateway server is in long connection with the target gateway, and when the target user does not log in the application server, the gateway server releases the long connection with the target gateway, so that the situation that the gateway server and network resources are occupied by keeping the long connection state between the gateway server and the target gateway all the time is avoided.
Drawings
In order to more clearly illustrate the technical solution of the present invention, the drawings needed to be used in the embodiments will be briefly described below, and it is obvious to those skilled in the art that other drawings can be obtained according to the drawings without any inventive exercise.
Fig. 1 is a timing diagram of an internet of things connection provided in an embodiment of the present application;
fig. 2 is a timing diagram of another internet of things connection provided in the embodiment of the present application;
fig. 3 is a schematic flow chart of a method for connecting an internet of things according to an embodiment of the present disclosure;
fig. 4 is a timing diagram of another internet of things connection provided in the embodiment of the present application.
Detailed Description
The technical solutions in the embodiments will be described clearly and completely with reference to the drawings in the embodiments, and it is obvious that the described embodiments are only a part of the embodiments of the present invention, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
The internet of things comprises an application server, a mobile terminal, a gateway server and a gateway, wherein the gateway is in communication connection with the gateway server, the application server is in communication connection with the gateway server, and a lower-hanging device in the internet of things is in communication connection with the gateway. The mobile terminal is provided with an APP (Application), a user logs in and accesses the Application server through the APP in the mobile terminal, and the user can initiate operation to the gateway through the Application server and the gateway server, such as inquiring equipment connected with the gateway internet of things, controlling equipment connected with the gateway internet of things and the like.
Fig. 1 is a timing diagram of an internet of things connection according to an embodiment of the present application. Taking the inquiry of the gateway drop device as an example, as shown in fig. 1: a user logs in an APP on a mobile terminal, the mobile terminal is connected with and logs in an application server through an HTTP protocol, and a control message is sent to the application server, wherein the message format is { gateway ID, OPTION, param }; the application server analyzes the message, judges the validity of the message and distributes the message to the gateway server according to the request; the gateway server receives the message distributed by the application server, analyzes the meaning of the message, and sends the operation message to a corresponding gateway, such as inquiring whether the corresponding gateway is on-line according to the gateway ID, inquiring a gateway connecting channel according to the login state and the like, and sending the related message to the related gateway through the connecting channel; the gateway receives the message sent by the gateway server, analyzes the message and executes the message, and sends an execution result, a return state and the like to the gateway server; the gateway server receives the execution result, the return state and the like sent by the gateway and returns the execution result, the return state and the like to the application server, the application server returns the received execution result, the return state and the like to the corresponding mobile terminal, and the user checks the execution result, the return state and the like after the gateway executes the operation through the APP on the mobile terminal.
In the embodiment of the application, a CoAP protocol is used between the gateway and the gateway server for mutual information transmission. In order to ensure the timely response of the user to the execution of the gateway operation, the gateway and the gateway server keep a connection state. Optionally, the gateway and the gateway server maintain a long connection state or a short connection state. The connection mode of the gateway and the gateway server comprises UDP, DTLS, TLS and TCP connection, and further the gateway and the gateway server can be connected through UDP, DTLS, TLS or TCP. Wherein UDP is an unreliable connection, DTLS is an encrypted unreliable connection, TCP is a reliable connection, TLS is an encrypted reliable connection, UDP and DTLS belong to short connections, TLS and TCP belong to long connections. A long connection is a connection in which a plurality of packets can be transmitted continuously, and if no packet is transmitted during the connection holding period, both ends of the connection need to transmit a detection packet to maintain the connection. Further, when both ends require a long connection without data communication, it is necessary to transmit a packet at a timing to maintain the connection state. The short connection is a connection established when both communication parties have data interaction, and is disconnected after data transmission is completed. The short connections are managed more conveniently without additional control.
With the increasing number of gateways in the internet of things, the connection between the gateways and the gateway server occupies a large amount of resources of the gateway server and the network. Although the short connections are convenient to manage, the reliability of the connection between the gateway and the gateway server cannot be guaranteed by using a large number of short connections, for example, it may be difficult to maintain the call-back channel, so that the sent instruction cannot be executed in time, however, if a large number of long connections are used, a large number of resources of the gateway server and the network will be occupied, and the connection performance between the gateway and the gateway server will be reduced.
In the embodiment of the present application, the gateway server may include one server, and may further include a plurality of servers, where the servers cooperate with each other to implement connection and operation of the gateway through distributed computing. For example, the gateway server includes two servers (gateway server a and gateway server B), and the gateway server a and the gateway server B cooperate to implement the connection and operation of the gateway through distributed computing.
In order to reduce occupation of gateway servers and network resources and ensure connection performance between gateways and gateway servers, the embodiment of the application provides a connection method of the internet of things. The internet of things connection method provided by the embodiment of the present application is described in detail below with reference to a specific form of a gateway server.
Fig. 2 is a timing diagram of another internet of things connection provided in the embodiment of the present application, and fig. 3 is a flowchart of a method for connecting internet of things provided in the embodiment of the present application. As shown in fig. 2 and fig. 3, the gateway server in this embodiment includes a server, and information interaction and data processing between the application server and the gateway are performed by one gateway server.
For convenience of description, a user in a login state is referred to as a target user, an ID of the user is referred to as a target user ID, a gateway to which the user binds is referred to as a target gateway, and an ID of the target gateway is referred to as a target gateway ID.
The internet of things connection method provided by the embodiment of the application is applied to a gateway server and comprises the following steps:
s100: receiving a short-connection heartbeat keep-alive message sent by a target gateway, wherein the target gateway in a short-connection state with the gateway server sends the short-connection heartbeat keep-alive message to the gateway server, and the target gateway is a gateway which needs to be configured by a target user.
In this embodiment of the present application, when the target gateway and the gateway server are in a short connection state, the target gateway needs to actively send a short connection heartbeat keep-alive message to the gateway server, so as to inform the gateway server that the gateway server is still online. And the gateway server receives the short-connection heartbeat keep-alive message sent by the target gateway, and if the gateway server receives the short-connection heartbeat keep-alive message of the gateway, the corresponding target gateway at the moment is considered to be in a short-connection state with the gateway server, namely the target gateway is in an online state.
Optionally, in order to ensure that the gateway server clearly knows whether the target gateway is online, the target gateway periodically sends a CoAP heartbeat keep-alive message to the gateway server, where the CoAP heartbeat keep-alive message may use UDP or TCP. Specifically, when the target gateway and the gateway server are in a short connection state, the target gateway periodically sends a short connection heartbeat keep-alive message, such as a UDP heartbeat keep-alive message; if the gateway and the gateway server are in a long connection state, the target gateway sends a long connection heartbeat keep-alive message, such as a TCP heartbeat keep-alive message or a TLS heartbeat keep-alive message, to the gateway server. Further, if the gateway sends the UDP heartbeat keep-alive message to the gateway server, the gateway server may or may not reply the message to the gateway. If the gateway server is adopted to not reply the message to the gateway, the load of the server can be relatively improved. The interval period of the CoAP heartbeat keep-alive messages sent by the gateway to the gateway server periodically can be 10S and the like.
In addition, in the embodiment of the present application, all gateways in a connection state with the gateway server need to send heartbeat keep-alive messages to the gateway server, so that the gateway server knows that the corresponding gateway is still in an online state.
In the embodiment of the application, the gateway server can monitor the online state of the gateway connected with the gateway server in real time. In order to facilitate the gateway server to monitor the online state of the gateway connected with the gateway in real time, the gateway server receives heartbeat keep-alive messages of all gateways, if the heartbeat keep-alive messages of a certain gateway are received, the online identifier of the gateway is set to be online in an online (online) table item in a gateway database, the online state of the corresponding gateway can be obtained by searching the online table item, and the gateway server can conveniently obtain the online state of the gateway. If the gateway server receives the heartbeat keep-alive message sent by the target gateway, the online identifier of the target gateway is set to be online in the online table entry in the gateway database, and then when the gateway server receives the target gateway ID, the online table entry is inquired according to the target gateway ID to know whether the target gateway corresponding to the target gateway ID is online or not, so that the gateway server can conveniently know the online state of the target gateway in time. In addition, the gateway server monitors the message of the gateway with online identification as online in the online table item according to the online table item.
S200: and if a target gateway ID sent by an application server is received, replying a message to a target gateway corresponding to the target gateway ID according to the target gateway ID, wherein the application server acquires the target gateway ID according to the login information of a target user and sends the target gateway ID to the gateway server.
When a user opens and logs in a corresponding APP on the mobile terminal, the mobile terminal sends login information of the user to the application server, and the application server receives the login information of the user, verifies the login information of the user and determines whether the user can be allowed to log in. In this embodiment, the mobile terminal may log in and connect to the application server using the HTTP protocol. If the application server verifies that the login information of the user meets the requirements, on one hand, the user is allowed to successfully log in the application server through the APP, on the other hand, the gateway ID bound by the user ID in the login information is obtained, one user ID can be used for pushing up a plurality of gateway IDs, and the user can be bound with more than one gateway. The login information of the user comprises a user ID and an ID of a user binding gateway, and the application server can acquire the ID of the user binding gateway according to the login information of the user.
Therefore, the application server receives the login information of the target user, and acquires the target user ID and the target gateway ID bound by the target user ID from the login information of the target user. When the application server obtains the target gateway ID bound by the target user ID, the target gateway ID bound by the target user ID is sent to the gateway server, and the gateway server receives the target gateway ID. In the embodiment of the application, the application server and the gateway server can transmit data through an HTTP (hyper text transport protocol), the application server sends a message carrying a target gateway ID to the gateway server through the HTTP, and the gateway server receives and analyzes the message through the HTTP to obtain the target gateway ID.
And if the gateway server receives the target gateway ID sent by the application server, the gateway server replies a message to a target gateway corresponding to the target gateway ID. The gateway server replies a message to the target gateway so that the message subsequently sent to the gateway server by the target gateway is a long connection message, and the connection between the target gateway and the gateway server is switched from short connection to long connection. The long connection in this embodiment may be a TLS connection, which is convenient for ensuring data security, but is not limited to the TLS connection and may also be a TCP connection.
Because there may be more than one target gateway corresponding to the target user and the target gateway may not be online, when the gateway server replies to the target gateway corresponding to the target gateway ID, it needs to determine the online status of the target gateway, and then replies to the target gateway in the online status.
In this embodiment of the present application, the gateway server replies a message to the target gateway corresponding to the target gateway ID according to the target gateway ID, specifically: the gateway server replies a heartbeat message to a target gateway corresponding to the target gateway ID according to the target gateway ID, the heartbeat message enables a message sent to the gateway server by the target gateway after the corresponding target gateway receives the heartbeat message to be a long connection message, namely the target gateway switches the short connection between the target gateway and the gateway server to be a long connection after receiving the reply heartbeat message of the gateway server, and the message sent to the gateway server by the target gateway is a long connection message.
In the embodiment of the application, the reply content of the gateway server replying the heartbeat message to the target gateway corresponding to the target gateway ID according to the target gateway ID may be null, so that the bandwidth occupied by the gateway server replying the heartbeat message to the target gateway corresponding to the target gateway ID may be reduced. However, if the heartbeat keep-alive message sent by the target gateway needs to be replied, the gateway server replies the heartbeat message to the target gateway, and the content needs to be added to the ACK message of the reply content.
In the embodiment of the application, the target gateway receives the reply message of the application server and sends a request for establishing long connection to the gateway server, the gateway server receives the request for establishing long connection sent by the target gateway, and the gateway server completes long connection with the target gateway according to the request for establishing long connection sent by the target gateway.
In the implementation of the application, if the gateway server requests the target gateway to establish the long connection by replying the UDP message, when the target gateway receives the reply UDP message of the gateway server, the target gateway requests the gateway server to establish the long connection, that is, initiates the long connection with the gateway server.
S300: and receiving the long connection message sent by the target gateway.
After the target gateway receives the message from the gateway server, the message sent to the gateway server by the target gateway is a long connection message, and the gateway server receives the long connection message sent by the target gateway. For example, the target gateway sends a long connection heartbeat keep-alive message to the gateway server.
Further, after the target gateway establishes long connection with the gateway server, the gateway server informs the application server that the target gateway bound by the target user has established long connection with the gateway server, the application server informs the mobile terminal that the target gateway bound by the target user has established long connection with the gateway server, and the preparation can be initiated, so that the user can control the APP to send a control message to the application server.
If the user controls the APP of the mobile terminal to send a control message to the application server, the application server analyzes the message, judges the validity of the message and sends the message to the gateway server according to the request; the gateway server receives the message distributed by the application server, analyzes the meaning of the message and sends the operation message to a target gateway; the target gateway receives the message sent by the gateway server, analyzes the message and executes the message, and sends an execution result, a return state and the like to the gateway server; the gateway server receives the execution result, the return state and the like sent by the target gateway and returns the execution result, the return state and the like to the application server, the application server returns the received execution result, the return state and the like to the mobile terminal of the corresponding target user, and the user checks the execution result, the return state and the like after the gateway executes the operation through the APP on the mobile terminal.
In the internet of things connection method provided by the embodiment of the application, switching between short connection and long connection between the gateway server and the gateway is realized, when a target user logs in the application server, the gateway server establishes long connection with the target gateway, and then when the target user does not log in the application server, the gateway server releases the long connection with the target gateway, so that occupation of the gateway server and network resources due to the fact that the long connection state between the gateway server and the target gateway is kept all the time is avoided, idle resources of the gateway server are released, and reasonable utilization of resources of the gateway server is facilitated.
In the internet of things connection method provided by the embodiment of the application, the method further includes: and if receiving a target user offline notification corresponding to the target gateway sent by the application server, releasing the long connection with the target gateway and establishing the short connection with the target gateway.
If the target user of the mobile terminal logs out, the application server is informed of the target user logging out when logging out, and when the application server receives the notice that the target user logs out, the application server sends a target user offline notice to the gateway server. The gateway server receives the target user offline notification sent by the application server, releases the long connection with the target gateway corresponding to the target user according to the target user offline notification, and switches the long connection between the target gateway and the gateway server to the short connection. In this example, the gateway server actively switches the long connection between the target gateway and the gateway server to the short connection, so that the target gateway and the gateway server are prevented from occupying too many network resources in the long connection state, the idle resources of the gateway server are released, and the reasonable utilization of the gateway server resources is facilitated.
Optionally, if the gateway server receives a target user offline notification sent by the application server, the TLS connection with the target gateway corresponding to the target user is released according to the target user offline notification, the TLS connection is switched to the UDP connection, the gateway terminates the TLS connection with the gateway server, the UDP connection with the gateway server is established, and the heartbeat keep-alive messages used for keep-alive are switched from the TLS heartbeat keep-alive messages to the UDP heartbeat keep-alive messages.
The internet of things connection method provided by the embodiment of the application further comprises the following steps: receiving a disconnection long connection request sent by the target gateway, wherein if the target gateway does not receive an operation instruction within a first threshold time, the target gateway sends the disconnection long connection request to the gateway server; and according to the long connection disconnection request, disconnecting the long connection with the target gateway and establishing the short connection with the target gateway.
If the target gateway does not receive the operation instruction within the first threshold time, the target user on the mobile terminal is considered to be offline or the target user is switched to the background, and the target gateway sends a disconnection long connection request to the gateway server so that the active target gateway is disconnected from the gateway server for long connection. The gateway server receives a long connection disconnection request sent by a target gateway, and the gateway server disconnects the long connection with the target gateway according to the long connection disconnection request, establishes short connection with the target gateway, releases idle resources of the gateway server, and is convenient for realizing reasonable utilization of gateway server resources.
If the first threshold time is 10min, when the target gateway does not receive the operation instruction within 10min, the target gateway sends a disconnection long connection request to the gateway server, and the gateway server receives the disconnection long connection request sent by the target gateway, disconnects the long connection of the target gateway according to the disconnection long connection request, and establishes a short connection with the target gateway. Optionally, a timer is set inside the gateway, and timing is started from the last operation instruction of the APP received; if the next operation instruction is not received when the first threshold time is counted, the operation instruction is not received within the first threshold time; and if the next operation instruction is received after the first threshold value time is counted, timing again.
In the embodiment of the present application, the first threshold time may be set as needed, and is not limited to 10 min. Correspondingly, in the embodiment of the application, if the user of the mobile terminal operates the APP within the first threshold time, the APP logs out, and if the user continues to operate the APP, the APP needs to log in again.
The internet of things connection method provided by the embodiment of the application further comprises the following steps: and if the long connection heartbeat keep-alive message sent by the target gateway is not received within the second threshold time, releasing the long connection with the target gateway and establishing the short connection with the target gateway.
In this embodiment of the application, when the target gateway and the gateway server are in a long connection state, the target gateway should periodically send a long-connection heartbeat keep-alive message to the gateway server, and if the gateway server does not receive the long-connection heartbeat keep-alive message sent by the target gateway to the gateway server in a plurality of consecutive periods, the gateway may be offline. Therefore, in this embodiment, a second threshold time is set, and if the gateway server does not receive the long connection heartbeat keep-alive message sent by the target gateway within the second threshold time, the gateway server releases the long connection with the target gateway, and releases the idle resources, thereby facilitating the reasonable utilization of the gateway server resources. Optionally, if the gateway server can also establish a short connection with the target gateway, the gateway server establishes a short connection with the target gateway.
Based on the internet of things connection method provided by the embodiment of the application, the embodiment of the application also provides a gateway server. The gateway server provided by the embodiment of the application is configured to:
receiving a short-connection heartbeat keep-alive message sent by a target gateway, wherein the target gateway in a short-connection state with the gateway server sends the short-connection heartbeat keep-alive message to the gateway server, and the target gateway is a gateway which needs to be configured by a target user;
if a target gateway ID sent by an application server is received, replying a message to a target gateway corresponding to the target gateway ID according to the target gateway ID, wherein the application server acquires the target gateway ID according to login information of a target user and sends the target gateway ID to the gateway server;
and receiving the long connection message sent by the target gateway.
Fig. 4 is a timing diagram of another internet of things connection provided in the embodiment of the present application. As shown in fig. 4, the gateway server in this embodiment includes two servers (a gateway server a and a gateway server B), and the gateway server a and the gateway server B cooperate to complete information interaction and data processing between the application server and the gateway. The distributed computation of the gateway server is realized through the cooperation of the gateway server A and the gateway server B, and the distributed computation method is suitable for the condition that the user amount is increased, such as millions of users.
Optionally, the gateway server a is responsible for processing the heartbeat keep-alive message initiated by the gateway and notifying the gateway server B of initiating the long connection with the gateway, and the gateway server B is responsible for maintaining the long connection with the gateway. The gateway server A is responsible for short-circuit connection of the gateway and processing the keep-alive of the gateway, and is a server for keeping connection; the gateway server B maintains gateway login, long connection, and data exchange, and is a server for processing services.
Specifically, the method comprises the following steps:
when a user opens and logs in a corresponding APP on the mobile terminal, the mobile terminal sends login information of a target user to the application server, the application server receives the login information of the target user, verifies the login information of the target user and determines whether the target user can be allowed to log in. In this embodiment, the mobile terminal may log in and connect to the application server using the HTTP protocol. If the application server verifies that the login information of the target user meets the requirement, on one hand, the user is allowed to successfully login the application server through the APP, on the other hand, the gateway ID bound by the target user ID in the login information is obtained, and then the target gateway ID bound by the target user ID is sent to the gateway server A.
And the gateway server A receives the ID of the target gateway, and receives heartbeat keep-alive messages sent by gateways such as the target gateway and the like. If the gateway server A receives the heartbeat keep-alive message of the target gateway, the corresponding target gateway at the moment is considered to be in an online state, and the gateway server A replies a message to the corresponding target gateway according to the target gateway ID, so that the corresponding target gateway establishes long connection to the gateway server B, and if the target gateway sends the long-connection keep-alive heartbeat, an operation reply result and the like to the gateway server B.
And the target gateway receives the reply message of the gateway server A, sends a request for establishing long connection to the gateway server B according to the received reply message, and the gateway server B receives the request for establishing long connection sent by the target gateway, so that the establishment of the long connection between the gateway server B and the target gateway is completed. And the target gateway sends a long connection keep-alive heartbeat, a long connection operation reply result and the like to the gateway server B.
When the gateway server B receives a request for establishing long connection sent by a target gateway and after the long connection with the target gateway is established, the gateway server B informs an application server that the target gateway bound by a target user has established long connection with the gateway server B, the application server informs a mobile terminal that the target gateway bound by the target user has established long connection with the gateway server B, the target gateway bound by the target user has established long connection with the gateway server B and can initiate operation after preparation, and then the user can control the APP to send a control message to the application server, wherein the control message reaches the target gateway through the application server and the gateway server B. Meanwhile, the gateway server B synchronizes information with the gateway server A, the gateway server A stops monitoring for requesting the target gateway to establish the long connection, and the monitoring of the gateway server A for the target gateway is released, so that the request for establishing the long connection, which is repeatedly sent to the target gateway by the gateway server A, can be avoided.
When the gateway server B is disconnected from the long connection with the target gateway, the gateway server B sends a notification that the long connection between the gateway server B and the target gateway is disconnected to the gateway server A, and the gateway server A continues to monitor the target gateway and recovers to receive the short-connection heartbeat keep-alive message sent by the target gateway; and meanwhile, the gateway server B sends a notification that the long connection between the gateway server B and the target gateway is disconnected to the application server, and informs the target user that the target gateway bound by the target user is disconnected from the long connection between the gateway server B and the target gateway.
In the present embodiment, when the gateway server establishes a long connection with the target gateway, the target address specifies the gateway server B, and the URL of the target address of the gateway server B is different from that of the gateway server a. The target gateway establishes a long connection with the gateway server B, and the gateway server B starts to process the connection service of the target gateway. According to the leg calculation of a network model where the Internet of things products are located, the gateway is in a short connection (keep-alive) state for more than 99% of time, and is in a long connection (specific service processing) state for less than 1% of time. Therefore, for the gateway server, the overhead of processing the service behavior on the CPU and the I/O at one time is hundreds of times of the overhead of processing the keep-alive messages, and the two servers are further used for being beneficial to balancing the load. And in addition, the cost of doubling the performance of the server is far more than that of maintaining two same servers in terms of hardware cost, and the system maintenance is more convenient due to the separation of connection and service from the service perspective.
The embodiment of the application provides a connection method of the Internet of things, and the embodiment of the application also provides a gateway. The gateway provided by the embodiment of the application is configured to: sending a short-connection heartbeat keep-alive message to a gateway server;
and if the reply message of the gateway server is received, when the message needs to be sent to the gateway server, sending a long connection message to the gateway server.
In the gateway, when the gateway and a gateway server are in a short connection state, the gateway sends a short connection heartbeat keep-alive message to the gateway server; and when the gateway and the gateway server are in a long connection state, the gateway sends a long connection heartbeat keep-alive message to the gateway server. If the gateway receives the reply message of the gateway server, the heartbeat keep-alive message sent to the gateway server by the gateway has a short connection keep-alive message converted into a long connection heartbeat keep-alive message.
Optionally, in the gateway provided in this embodiment of the present application, if the reply message of the gateway server is received, the gateway sends a request for establishing a long connection to the gateway server. When the gateway establishes a long connection with the gateway server, the message sent by the gateway to the gateway server is a long connection message.
Finally, it should be noted that: the embodiment is described in a progressive manner, and different parts can be mutually referred; in addition, the above embodiments are only used to illustrate the technical solution of the present invention, and not to limit the same; although the present invention has been described in detail with reference to the foregoing embodiments, it will be understood by those of ordinary skill in the art that: the technical solutions described in the foregoing embodiments may still be modified, or some technical features may be equivalently replaced; and such modifications or substitutions do not depart from the spirit and scope of the corresponding technical solutions of the embodiments of the present invention.

Claims (10)

1. An Internet of things connection method is applied to a gateway server, and is characterized by comprising the following steps:
receiving a short-connection heartbeat keep-alive message sent by a target gateway, wherein the target gateway in a short-connection state with the gateway server sends the short-connection heartbeat keep-alive message to the gateway server, and the target gateway is a gateway which needs to be configured by a target user;
if a target gateway ID sent by an application server is received, replying a message to a target gateway corresponding to the target gateway ID according to the target gateway ID, wherein the application server acquires the target gateway ID according to login information of a target user and sends the target gateway ID to the gateway server;
and receiving the long connection message sent by the target gateway.
2. The internet of things connection method of claim 1, wherein replying a message to a target gateway corresponding to the target gateway ID according to the target gateway ID comprises:
and replying a heartbeat message to a target gateway corresponding to the target gateway ID according to the target gateway ID, wherein the heartbeat message enables the target gateway to send a long connection message to the gateway server after receiving the heartbeat message.
3. The internet of things connection method according to claim 2, wherein receiving the short-connection heartbeat keep-alive message sent by the target gateway includes:
if receiving a heartbeat keep-alive message sent by a target gateway, setting an online identifier of the target gateway to be online in an online table entry in a gateway database;
if the target gateway ID is received, inquiring whether the online identification of the target gateway corresponding to the target gateway ID is online;
replying a heartbeat message to a target gateway corresponding to the target gateway ID according to the target gateway ID, wherein the replying comprises the following steps:
and if the online identification of the target gateway corresponding to the target gateway ID is online, replying a heartbeat message to the target gateway according to the target gateway ID.
4. The internet of things connection method of claim 1, further comprising:
receiving a long-connection heartbeat keep-alive message sent by the target gateway, wherein if the target gateway and the gateway server are in a long-connection state, the target gateway sends the long-connection heartbeat keep-alive message to the gateway server, and the long-connection heartbeat keep-alive message comprises a TLS heartbeat keep-alive message.
5. The internet of things connection method of claim 1, further comprising:
and if receiving a target user offline notification corresponding to the target gateway sent by the application server, releasing a long connection with the target gateway, and establishing a short connection with the target gateway, wherein the long connection is TLS or TCP connection, and the short connection is UDP or DTLS connection.
6. The internet of things connection method of claim 1, further comprising:
receiving a disconnection long connection request sent by the target gateway, wherein if the target gateway does not receive an operation instruction within a first threshold time, the target gateway sends the disconnection long connection request to the gateway server;
and establishing short connection with the target gateway according to the long connection disconnection request.
7. The internet of things connection method of claim 4, further comprising:
and if the long connection heartbeat keep-alive message sent by the target gateway is not received within the second threshold time, releasing the long connection with the target gateway and establishing the short connection with the target gateway.
8. An Internet of things connection method is applied to a gateway, and is characterized by comprising the following steps:
sending a short-connection heartbeat keep-alive message to a gateway server;
and if the reply message of the gateway server is received, when the message needs to be sent to the gateway server, sending a long connection message to the gateway server.
9. A gateway server, wherein the gateway server is configured to:
receiving a short-connection heartbeat keep-alive message sent by a target gateway, wherein the target gateway in a short-connection state with the gateway server sends the short-connection heartbeat keep-alive message to the gateway server, and the target gateway is a gateway which needs to be configured by a target user;
if a target gateway ID sent by an application server is received, replying a message to a target gateway corresponding to the target gateway ID according to the target gateway ID, wherein the application server acquires the target gateway ID according to login information of a target user and sends the target gateway ID to the gateway server;
and receiving the long connection message sent by the target gateway.
10. A gateway, characterized in that the gateway is configured to:
sending a short-connection heartbeat keep-alive message to a gateway server;
and if the reply message of the gateway server is received, when the message needs to be sent to the gateway server, sending a long connection message to the gateway server.
CN202010655333.3A 2020-07-09 2020-07-09 Internet of things connection method, gateway server and gateway Pending CN113992737A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202010655333.3A CN113992737A (en) 2020-07-09 2020-07-09 Internet of things connection method, gateway server and gateway

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202010655333.3A CN113992737A (en) 2020-07-09 2020-07-09 Internet of things connection method, gateway server and gateway

Publications (1)

Publication Number Publication Date
CN113992737A true CN113992737A (en) 2022-01-28

Family

ID=79731232

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202010655333.3A Pending CN113992737A (en) 2020-07-09 2020-07-09 Internet of things connection method, gateway server and gateway

Country Status (1)

Country Link
CN (1) CN113992737A (en)

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2012024909A1 (en) * 2010-08-27 2012-03-01 中兴通讯股份有限公司 Long connection management apparatus and link resource management method for long connection communication
CN105530291A (en) * 2015-11-30 2016-04-27 深圳市元征软件开发有限公司 Method, device and system for obtaining diagnostic equipment state
CN105933435A (en) * 2015-06-20 2016-09-07 浙江网新合同能源管理有限公司 Real-time query method based on Internet of Things
WO2019119846A1 (en) * 2017-12-21 2019-06-27 深圳市力科威尔智能科技有限公司 Low power consumption device, keep-alive server, and message pushing method and system

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2012024909A1 (en) * 2010-08-27 2012-03-01 中兴通讯股份有限公司 Long connection management apparatus and link resource management method for long connection communication
CN105933435A (en) * 2015-06-20 2016-09-07 浙江网新合同能源管理有限公司 Real-time query method based on Internet of Things
CN105530291A (en) * 2015-11-30 2016-04-27 深圳市元征软件开发有限公司 Method, device and system for obtaining diagnostic equipment state
WO2019119846A1 (en) * 2017-12-21 2019-06-27 深圳市力科威尔智能科技有限公司 Low power consumption device, keep-alive server, and message pushing method and system

Similar Documents

Publication Publication Date Title
CN107645529B (en) Heartbeat packet sending method and device
US8565801B2 (en) Methods and apparatus for managing group membership for group communications
CN111224999A (en) Transmission protocol switching method, device, equipment and storage medium
CN102469124B (en) Based on the implementation method of the mobile Internet business of AOG, gateway, agency and system
CN105610888A (en) Method of using socket to push message based on Android and system thereof
CN106453356B (en) The bilateral acceleration transmission method of wireless network and system
WO2010121528A1 (en) Mobile terminal and peer-to-peer mode based data transmission method thereof
CN108683653B (en) Active message pushing system based on WebSocket
US11337040B2 (en) Broadcast bearer management method and device thereof
CN103457985B (en) A kind of dual-channels communication method and system
CN105207949B (en) A kind of TCP optimization methods and system, SP servers
US7349664B2 (en) Communication system and method thereof
CN103516766A (en) Method and system of communication between client-side and application server
WO2013159492A1 (en) Method and system for reporting and downloading information
CN111555965B (en) Message pushing method and system suitable for iOS client
WO2010051739A1 (en) Method for mobile instant messaging and apparatus thereof
CN113992737A (en) Internet of things connection method, gateway server and gateway
WO2014179992A1 (en) User plane event processing method, pcrf entity, and af entity
KR101224557B1 (en) System, client device, and method for keep-alive communication
WO2022033083A1 (en) Decoding method, decoding system, electronic apparatus, and storage medium
JP3682439B2 (en) Data communication system and method, server device, client device, and program
US10581979B2 (en) Information transmission method and apparatus
US11503164B2 (en) Media interaction method in DECT network cluster
CN114390037A (en) Method and system for terminal to access home network equipment
CN112311759B (en) Equipment connection switching method and system under hybrid network

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination