Disclosure of Invention
The application aims to provide a LoRaWAN gateway node data interaction method based on a data unit, which is used for reducing the size of a transmission packet and ensuring the integrity of data, so that the data transmission and analysis are more stable, and the technical effect of reducing the transmission power consumption is realized.
The embodiment of the application provides a LoRaWAN gateway node data interaction method based on a data unit, which comprises the steps that a first terminal node constructs an uplink data unit according to a first channel number, data length, a first data type and first data to be transmitted of a sensor; the structure of the uplink data unit is 'first channel number + data length + first data type + first data';
the first terminal node performs base64 coding after adding head-to-tail verification to the uplink data unit to obtain a corresponding first data packet, and sends the first data packet to a gateway through an outer LoRaWAN protocol;
the gateway performs base64 decoding on the first data packet and then performs head and tail verification;
if the head and tail verification is passed, the gateway sends a control instruction to a corresponding second terminal node according to the first data; otherwise, the first data is discarded.
Further, the step of sending, by the gateway, a control instruction to the corresponding second terminal node according to the first data includes:
acquiring a second channel number, a second data type and second data to be transmitted of a second terminal node;
constructing a downlink data unit according to the second channel number, the second data type and the second data; the structure of the downlink data unit is 'second channel number + second data type + second data';
and after head and tail verification is added to the downlink data unit, base64 coding is carried out to obtain a second data packet corresponding to the control instruction, and the second data packet is sent to a second terminal node through an outer layer LoRaWAN protocol.
Further, the second channel number and the second data type occupy a fixed byte.
Further, the method further comprises: if the number of the data units is multiple, adding the data units, then adding head and tail verification, and performing base64 encoding.
Further, the first channel number and the data length in the uplink data unit occupy a fixed byte; the first data type occupies a fixed byte.
Further, the method further comprises: constructing a channel data type table according to the data type; converting the data type according to the channel data type table;
the channel data type table comprises a general channel data type table and a special channel data type table; the universal channel data type table comprises a channel type of a terminal node, a data type number, a conversion value corresponding to the data type number, data resolution and data size; the special channel data type table comprises a sensor acquisition period, a channel type of a terminal node corresponding time, a data type model, a conversion value corresponding to the data type number, data resolution and data size.
Further, the conversion value of the channel number is a 16-system conversion value.
The beneficial effect that this application can realize is: the method and the device improve the data structure of the Payload part in the LoRaWAN data frame, optimize the data structure, reduce the size of a transmission packet, reduce the data transmission amount between the LoRaWAN data frame and the transmission packet, and enable data transmission and analysis to be more stable, thereby reducing the power consumption of transmission.
Detailed Description
The technical solutions in the embodiments of the present application will be described below with reference to the drawings in the embodiments of the present application.
It should be noted that: like reference numbers and letters refer to like items in the following figures, and thus, once an item is defined in one figure, it need not be further defined and explained in subsequent figures. Meanwhile, in the description of the present application, the terms "first", "second", and the like are used only for distinguishing the description, and are not to be construed as indicating or implying relative importance.
Referring to fig. 1, fig. 2 and fig. 3, fig. 1 is a flowchart of a data unit-based LoRaWAN gateway node data interaction method according to an embodiment of the present application; fig. 2 is a schematic flow chart of a data unit combination according to an embodiment of the present application; fig. 3 is a schematic diagram of a data unit parsing process according to an embodiment of the present application.
The applicant researches and discovers that when data interaction is carried out between a terminal node and a gateway in the existing LoRaWAN, data of various sensors are combined in a non-specific format, and a data packet structure caused by different data types and data precision is disordered and complex and is inconvenient to interpret. Therefore, the LoRaWAN gateway node data interaction method based on the data unit is provided to optimize a data structure when the terminal node and the gateway interact, reduce the size of a transmission packet, reduce the data transmission amount between the terminal node and the gateway, enable data transmission and analysis to be more stable, and reduce the transmission power consumption. As shown in fig. 1, the method comprises the following specific steps:
step S101, a first terminal node constructs an uplink data unit according to a first channel number, a data length, a first data type and first data to be transmitted of a sensor; the structure of the uplink data unit is 'first channel number + data length + first data type + first data'.
As shown in fig. 2, when an uplink data unit is constructed, a terminal node first obtains information such as a channel number, a data length, a data type, data to be transmitted, and the like of a sensor, and then obtains a conversion value corresponding to the data type according to the data type and a general channel data type table; the general channel data type table is constructed in a manner shown in table 1, and the conversion value corresponding to the data type number may be a 16-system conversion value. The universal channel data type table comprises a channel type of the terminal node, a data type number (LPP), a conversion value corresponding to the data type number, data resolution and data size.
Table 1 general channel data type table
Furthermore, in order to control the acquisition period of the sensor and the response time of the terminal node conveniently, a dedicated data channel can be set and a corresponding dedicated channel data type table can be constructed during data transmission, and when a gateway sends a corresponding control instruction, the gateway can firstly convert the control instruction into a 16-system conversion value according to the dedicated channel data type table and then transmit the conversion value through the dedicated channel; specifically, as shown in table 2. The special channel data type table comprises a channel type, a data type number, a conversion value corresponding to the data type number, data resolution and data size of a sensor acquisition period and corresponding time of a terminal node.
TABLE 2 Special channel data type Table
And step S102, the first terminal node performs base64 coding to obtain a corresponding first data packet after adding head-to-tail verification to the uplink data unit, and sends the first data packet to a gateway through an outer-layer LoRaWAN protocol.
As shown in fig. 2, in an embodiment, after the uplink data unit is constructed, a header and footer verification (e.g., header and footer verifications aa and bb) may be added, and then base64 encoding is performed to obtain a corresponding data packet.
It should be noted that, if there are multiple data units, the data units may be added arbitrarily and then the head and tail verification may be added; the addition method is "data unit 1& data unit 2&. & data unit n".
And step S103, the gateway performs base64 decoding on the first data packet and then performs head and tail verification.
As shown in fig. 2, after receiving the data packet sent by the terminal node, the gateway first performs base64 decoding, and then performs head and tail verification to verify the head and tail aa and bb.
Step S104, if the head and tail verification is passed, the gateway sends a control instruction to a corresponding second terminal node according to the first data; otherwise, the first data is discarded.
As shown in fig. 2, if the head and the tail are qualified through verification, the gateway continues to convert the content of the data packet according to the general channel data type table corresponding to the data type, so as to obtain a corresponding data value. And if the head and the tail are not qualified through verification, discarding the data.
In order to better understand the method provided by the present application, the present application further provides the following several embodiments (in the embodiments, payload is actually sent data in a data frame of a LoRaWAN):
example one
Uplink (Uplink): and the air temperature and humidity sensor of the first channel transmits data to the gateway.
The transmission content after adding specific head and tail (aa, bb) and base64 codes is as follows: qhJlARASZgD/uw.
Example two
(downstream) Downlink: and the gateway sends a control command to close the electromagnetic valve of the third channel and open the electromagnetic valve of the fourth channel for 10min.
The transmission content after adding specific head and tail (aa, bb) and base64 codes is as follows: qjAAQQECWLs.
EXAMPLE III
(downstream) Downlink: the dedicated channel sets the response time to 1min.
The transmission content after adding specific head and tail (aa, bb) and base64 codes is as follows: qgAAPLs.
To sum up, an embodiment of the present application provides a data unit-based LoRaWAN gateway node data interaction method, including: the first terminal node constructs an uplink data unit according to a first channel number, a data length, a first data type and first data to be transmitted of the sensor; the structure of the uplink data unit is 'first channel number + data length + first data type + first data'; the first terminal node performs base64 coding to obtain a corresponding first data packet after adding head-to-tail verification to the uplink data unit, and sends the first data packet to the gateway through an outer LoRaWAN protocol; the gateway performs base64 decoding on the first data packet and then performs head and tail verification; if the head and tail verification is passed, the gateway sends a control instruction to the corresponding second terminal node according to the first data; otherwise, the first data is discarded. By the mode, the data structure is optimized, the size of a transmission packet is reduced, the data transmission amount between the transmission packet and the transmission packet is reduced, data transmission and analysis are more stable, and transmission power consumption is reduced.
The above description is only for the specific embodiments of the present application, but the scope of the present application is not limited thereto, and any person skilled in the art can easily conceive of the changes or substitutions within the technical scope of the present application, and shall be covered by the scope of the present application. Therefore, the protection scope of the present application shall be subject to the protection scope of the claims.