Disclosure of Invention
In view of the above drawbacks of the prior art, an object of the present invention is to provide a communication system and method based on LoRaWAN, which are used to solve the problems of traffic charges generated by data interaction between a gateway and a network server during communication and insecurity of data transmission in the prior art, and do not need the network server, thereby saving networking cost.
To achieve the above and other related objects, the present invention provides a LoRaWAN-based communication system, including: the system comprises terminal equipment, gateway equipment and an application server; the terminal device is used for sending a network access request to the gateway device and sending first encrypted data to the gateway device when receiving a request reply of the gateway device that the access is allowed; receiving and decrypting second encrypted data sent by the gateway equipment; the gateway device is used for receiving a network access request of the terminal device, receiving and decrypting the first encrypted data sent by the terminal device after sending a request reply to the terminal device, and sending the decrypted first data to the application server; receiving and encrypting second data sent by the application server to obtain second encrypted data, and sending the second encrypted data to the terminal equipment; the application server is used for receiving first data sent by the gateway equipment and executing an operation instruction corresponding to the first data; and sending the second data before encryption to the gateway device.
In order to achieve the above objects and other related objects, the present invention provides a communication method based on LoRaWAN, applied to a gateway device, the method including the steps of: (21) receiving a network access request sent by terminal equipment, and sending a return request message to the terminal equipment under the condition of judging that the network access is allowed; (22) receiving encrypted first encrypted data sent by terminal equipment, and decrypting the first encrypted data to obtain decrypted first data, wherein the first data is data collected by the terminal equipment; (23) sending the first data to the application server; (24) receiving second data sent by the application server, and encrypting the second data to obtain encrypted second encrypted data, wherein the second data is transmission data corresponding to an instruction issued by the application server, and the instruction is an instruction sent based on the first data, or an instruction actively sent by the application server; (25) and sending the second encrypted data to the terminal equipment so that the terminal equipment executes the instruction after decrypting the second encrypted data.
In an embodiment of the present invention, the step of sending the second encrypted data to the terminal device, so that the terminal device executes the instruction after decrypting the second encrypted data, includes: and sending the second encrypted data to the terminal equipment during the window opening period of the terminal equipment according to preset issuing delay time so that the terminal equipment executes the instruction after decrypting the second encrypted data.
In an embodiment of the present invention, the terminal device is a wireless sensor.
In an embodiment of the present invention, the gateway device includes a gateway and a web server installation software.
In an embodiment of the present invention, based on the TCP/IP transport protocol, the data transmission direction of the gateway points to the own IP address of the gateway.
In an embodiment of the present invention, the step of receiving the second data sent by the application server and encrypting the second data to obtain encrypted second encrypted data includes: and receiving second data sent by the application server, and encrypting the second data to obtain encrypted second encrypted data, wherein the second data is sent by the application server based on a message queue telemetry transport protocol MQTT or a hypertext transfer protocol HTTP.
In an embodiment of the present invention, the method further includes: judging whether the free memory in the gateway equipment is smaller than a preset value or not; and if so, deleting the data in the gateway equipment according to the storage time of the data in the gateway equipment until the free memory is larger than a preset value.
In an embodiment of the present invention, the step of sending the first data to the application server includes: sending the first data to the application server so that the application server stores the first data; and deleting the first data from the gateway equipment after judging that the first data is successfully sent.
In an embodiment of the present invention, the network access request is represented by an MType message type character.
In addition, the invention also discloses a computer-readable storage medium, on which a computer program is stored, which program, when being executed by a processor, realizes the steps of the LoRaWAN-based communication method.
As described above, the communication system and method based on LoRaWAN of the present invention have the following advantages:
(1) the problems of the prior art that the cost is caused by the fact that the gateway transmits data to the network server through the Ethernet or the operator and the data is stolen possibly caused by the process are solved. Therefore, the flow cost generated by data interaction of the gateway and the network server in the communication process and the insecurity of data transmission are avoided, the network server is not needed, and the networking cost is saved;
(2) by setting the issuing delay time, data loss caused by congestion of a data transmission queue can be effectively avoided, and the data congestion can be avoided by setting the issuing delay time, so that data transmission delay is avoided;
(3) in the embodiment of the invention, the terminal equipment is a wireless sensor, the acquired data is sent to the gateway equipment through the wireless sensor, and is transmitted to the application server through the gateway equipment, and the instruction sent by the application server is received through the gateway equipment, so that the management of the wireless sensor is realized.
Detailed Description
The following embodiments of the present invention are provided by way of specific examples, and other advantages and effects of the present invention will be readily apparent to those skilled in the art from the disclosure herein. The invention is capable of other and different embodiments and of being practiced or of being carried out in various ways, and its several details are capable of modification in various respects, all without departing from the spirit and scope of the present invention. It is to be noted that the features in the following embodiments and examples may be combined with each other without conflict.
It should be noted that the drawings provided in the following embodiments are only for illustrating the basic idea of the present invention, and the components related to the present invention are only shown in the drawings rather than drawn according to the number, shape and size of the components in actual implementation, and the type, quantity and proportion of the components in actual implementation may be changed freely, and the layout of the components may be more complicated.
Referring to fig. 1, the present invention provides a schematic structural diagram of a communication system 100 based on LoRaWAN, where the uplink data transmission direction of the communication system 100 is: the terminal equipment 1 is transmitted to the gateway equipment 2, and the gateway equipment 2 is transmitted to the application server 3; the downlink data transmission direction is as follows: the application server 3 transmits to the gateway device 2 and the gateway device 2 transmits to the terminal device 1.
The terminal device 1 is configured to send a network access request to the gateway device 2, and send first encrypted data to the gateway device 2 when receiving a request reply of the gateway device 2 that is an access permission request; receiving and decrypting second encrypted data sent by the gateway device 2;
the gateway device 2 is used for receiving the network access request of the terminal device 1, receiving and decrypting the first encrypted data sent by the terminal device 1 after sending the request reply to the terminal device 1, and sending the decrypted first data to the application server 3; receiving and encrypting second data sent by the application server 3 to obtain second encrypted data, and sending the second encrypted data to the terminal device 1;
the application server 3 is configured to receive the first data sent by the gateway device 2, and execute an operation instruction corresponding to the first data; and sending the second data before encryption to the gateway apparatus 2.
In the embodiment of the invention, after the gateway equipment is powered on, the gateway program installed in the gateway equipment and the LoRaWAN network server installation software are automatically started, and specifically, the software installed in the gateway can be services such as Mysql, redis, Mqtt and the like.
After the terminal is powered on, the terminal sends a Join network access request to the gateway equipment, and after the gateway equipment receives the network access request, the gateway equipment directly transfers the request to a network server for installing software; and after receiving the Join request, the gateway equipment replies the request, after receiving the replied request message, the terminal equipment starts to acquire data and send the data to the gateway equipment according to the service requirement, and the gateway equipment decrypts the data through the installed server software and uploads the data to the application server.
Referring to fig. 2 and 3, an uplink data communication process of the communication method based on LoRaWAN includes the steps of:
s201, receiving a network access request sent by a terminal device, and sending a return request message to the terminal device under the condition of judging that the network access is allowed;
s202, receiving encrypted first encrypted data sent by the terminal equipment, and decrypting the first encrypted data to obtain decrypted first data, wherein the first data is data collected by the terminal equipment;
s203, the first data is sent to an application server.
After the terminal device sends the acquired data to the application server through the gateway device by applying the uplink communication process, the application server responds according to the first data or sends an execution instruction to the terminal device, and the process of sending the instruction to the terminal device is a downlink data transmission process.
The downlink data transmission process comprises the following steps:
s204, receiving second data sent by an application server, and encrypting the second data to obtain encrypted second encrypted data, wherein the second data is transmission data corresponding to an instruction issued by the application server, and the instruction is an instruction sent based on the first data, or an instruction actively sent by the application server;
and S205, sending the second encrypted data to the terminal equipment so that the terminal equipment executes the instruction after decrypting the second encrypted data.
With the embodiments of fig. 2 and fig. 3 of the present invention, the uplink data transmission process is as follows: after requesting to join the gateway equipment, the terminal equipment sends encrypted data to the gateway equipment and sends the encrypted data to the application server through the gateway equipment, and the downlink data transmission process comprises the following steps: the application server sends an instruction to the gateway equipment, the instruction is encrypted by the gateway equipment and then is transmitted to the terminal equipment, and the instruction is executed. Therefore, the cost caused by sending the gateway to the network server through the Ethernet or the operator data in the prior art and the problem of data theft possibly caused by the process are avoided. Therefore, the flow cost generated by data interaction of the gateway and the network server in the communication process and the insecurity of data transmission are avoided, the network server is not needed, and the networking cost is saved.
In one implementation manner of the present invention, the step of sending the second encrypted data to the terminal device so that the terminal device executes the instruction after decrypting the second encrypted data includes: and sending second encrypted data to the terminal equipment during the window opening period of the terminal equipment according to preset issuing delay time so that the terminal equipment executes an instruction after decrypting the second encrypted data.
For example, after receiving the second encrypted data, the gateway device puts the second encrypted data into the data transmission queue, judges the transmission time of other data in the queue, and puts the second encrypted data into the queue, and when the transmission time is 0.05S, the transmission delay time of the second encrypted data is set to 0.05S, so that the congestion of the data can be avoided, and the data transmission delay is avoided.
Therefore, by applying the embodiment provided by the invention, the issuing delay time is set by the gateway equipment, and the data is sent to the terminal equipment, so that the terminal equipment receives and executes the data in sequence, and the loss of the data received by the terminal equipment is avoided.
In one implementation, the terminal device is a wireless sensor. The wireless sensor sends the acquired data to the gateway equipment, the data is transmitted to the application server through the gateway equipment, and the instruction sent by the application server is received through the gateway equipment, so that the management of the wireless sensor is realized.
In the embodiment of the invention, the gateway equipment comprises a gateway and network server installation software, and the data transmission direction of the gateway points to the IP address of the gateway based on a TCP/IP transmission protocol. The gateway and the network server installation software run in the same system, the possibility of packet loss in the network transmission process is avoided, the data transmission speed is high, and the method is suitable for erecting a local internet of things in a small local area network.
In the embodiment of the invention, the gateway is powered off and then powered on again, and the gateway and the network server are started automatically; the gateway can also be pointed to 127.0.0.1 (namely the gateway itself) by logging in the gateway page, so that the transmission of data in the gateway is realized, and the way that the gateway and a network server transmit data flow or wirelessly in the prior art is avoided. In addition, the page of a network server built in the gateway can be logged in, and the connection of a registration gateway and the terminal equipment can be increased. By following the TCP/IP transmission protocol, the transmission required to be transmitted by the gateway is directed to the gateway, so that the installation software of the network server in the gateway equipment can encrypt and decrypt the data, and then the data is transmitted.
Preferably, the step of receiving the second data sent by the application server and encrypting the second data to obtain encrypted second encrypted data includes: and receiving second data sent by the application server, and encrypting the second data to obtain encrypted second encrypted data, wherein the second data is data sent by the application server based on a message queue telemetry transport protocol (MQTT) or a hypertext transfer protocol (HTTP). The application server can send data to the gateway device through the MQTT or HTTP protocol, and the communication protocol suitable for sending the data can be improved.
In an implementation manner of the present invention, the method further includes: judging whether the free memory in the gateway equipment is smaller than a preset value or not; and if so, deleting the data in the gateway equipment according to the storage time of the data in the gateway equipment until the free memory is larger than a preset value. The data is deleted by judging the size of the free memory in the gateway equipment, so that the condition that the free memory is larger than a preset value is ensured, and the normal operation of the gateway equipment is ensured.
In another implementation manner of the present invention, the step of sending the first data to the application server includes: sending the first data to an application server so that the application server stores the first data; and deleting the first data from the gateway equipment after judging that the first data is successfully sent. The received data are sent to the application server through the gateway equipment for storage, so that the memory of the gateway equipment can be saved, and the hooking and communication of the terminal equipment cannot be influenced due to the fact that the memory occupies too much.
Specifically, in one implementation, the network access request is represented by an MType message type character. As shown in table 1, the message type character Mtype is represented by 3 bits. In the LoRaWAN specification, 8 message types are defined. That is, the packet types are limited to the following eight types.
TABLE 1
In addition, the invention also discloses a computer-readable storage medium, on which a computer program is stored, which program, when being executed by a processor, realizes the steps of the LoRaWAN-based communication method.
In summary, the communication system and method based on LoRaWAN of the present invention avoid the cost caused by the gateway sending the data to the network server through ethernet or the operator in the prior art, and the problem of data theft possibly caused by the process. Therefore, the flow charge generated by data interaction between the gateway and the network server in the communication process and the insecurity of data transmission are avoided, the network server is not needed, and the networking cost is saved. Therefore, the invention effectively overcomes various defects in the prior art and has high industrial utilization value.
The foregoing embodiments are merely illustrative of the principles and utilities of the present invention and are not intended to limit the invention. Any person skilled in the art can modify or change the above-mentioned embodiments without departing from the spirit and scope of the present invention. Accordingly, it is intended that all equivalent modifications or changes which can be made by those skilled in the art without departing from the spirit and technical spirit of the present invention be covered by the claims of the present invention.