MCU-based loraWAN class a full-duplex gateway communication method and system
Through the MCU-based LoRaWAN Class A full-duplex gateway communication method, the MCU is used to control multiple LoRa chips to achieve low-cost, low-power multi-channel parallel uplink communication, which solves the high cost and high power consumption problems of LoRaWAN gateways in sparse terminal device scenarios and realizes the efficiency and economy of full-duplex communication.
Patent Information
- Application Number
- CN202310106857.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-02-14
- Publication Date
- 2025-10-17
- Estimated Expiration
- 2043-02-14
AI Technical Summary
When implementing multi-channel, full-duplex communication, existing LoRaWAN gateways have high system deployment costs, high power consumption, low timing real-time performance, and serious resource waste in sparse terminal device scenarios.
The MCU-based LoRaWAN Class A full-duplex gateway communication method is adopted. The MCU is used to control multiple LoRa chips to achieve multi-channel, full-duplex communication. The LoRa channels are controlled by an object-oriented method. Combined with the RTOS low-power operating system, low-cost, low-power multi-channel parallel uplink communication is achieved.
It realizes low-cost, low-power, multi-channel, full-duplex LoRaWAN gateway communication, which is suitable for sparse terminal device scenarios, improves the input-output ratio of the system, and meets the LoRaWAN Class A\Class C communication requirements.
Smart Images

Figure CN116723591B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of LoRa communication, and in particular relates to a LoRaWAN Class A full-duplex gateway communication method and system based on an MCU. BACKGROUND
[0002] The LoRaWAN gateway in the current market LoRaWAN system is mainly realized through a hardware platform based on a Cortex-A, ARM9, etc. high-performance CPU and a software platform based on a Linux operating system, the radio frequency hardware adopts 1-n LoRa gateway chips SX130x chips and their supporting radio frequency front-end chips SX125x (such as SX1250), etc. to realize an 8*n channel half-duplex LoRaWAN gateway.
[0003] However, the high-performance CPU processor is used, the gateway cost is high, the radio frequency chip and the front-end chip are used, and the chip cost is high. Moreover, the half-duplex LoRaWAN gateway has a large discount in the downlink communication performance in a scene where the bidirectional communication is relatively concentrated, and the LoRaWAN network overall performance is obviously reduced. However, since the SX130x chip only supports half-duplex communication by default, a full-duplex LoRaWAN gateway needs to use the SX130x in cooperation with an additional radio frequency duplexer to realize, and the cost is high, and the volume is also relatively large. The high-performance multi-channel LoRaWAN gateway also means that a higher power consumption is needed, and the typical power consumption is about 5W.
[0004] In addition, although the half-duplex\full-duplex LoRaWAN gateway based on the Linux operating system and the SX130x has good processing performance, more uplink channels, and higher capacity, for some LoRaWAN terminal device access less or relatively sparse application scenarios, or network coverage edge zone, deploying a high-performance, multi-channel LoRaWAN gateway based on the Linux operating system, the system resources are excessive, and ultimately lead to the system deployment cost is high.
[0005] On the other hand, compared with the LoRaWAN gateway based on Linux, the single-channel half-duplex LoRaWAN gateway scheme based on Raspberry Pi, Arduino and LoRa chip SX127x has a much lower cost, but only supports single-channel, half-duplex communication mode, and the network performance is low. The system mainly adopts a polling mechanism, a non-low-power hardware design, a low timing real-time performance, and a relatively high power consumption. SUMMARY
[0006] The purpose of the present application is to overcome the problems of high system deployment cost, high power consumption and low timing real-time performance in the prior art when a high-performance multi-channel LoRa WAN gateway implements multi-channel and full-duplex communication, and to provide a LoRaWAN Class A full-duplex gateway communication method based on MCU, which utilizes multiple LoRa chips to implement a multi-channel, full-duplex, low-cost and low-power LoRaWAN gateway communication mechanism, and supports reliable communication of LoRaWAN Class A\Class C devices with fixed rate and multiple LoRa channels. Based on the present application, a single-rate, multi-channel and full-duplex LoRaWAN gateway can be designed and implemented to meet the LoRaWAN network communication Class A\Class C requirements of the specified channel.
[0007] To achieve the above-mentioned purpose, the present application adopts the following technical solution: a LoRaWAN Class A full-duplex gateway communication method based on MCU, comprising the following steps:
[0008] S1: Set the operating parameters of N LoRa channels, use MCU to control N LoRa chips to be in a real-time receiving state, trigger or wake up the MCU interrupt according to the LoRa chip data receiving condition, record the LoRa data packet receiving time t1, and assemble the current data packet header information. After the LoRa data receiving is completed, wake up the gateway uplink data processing thread;
[0009] S2: The gateway uplink data processing thread extracts the received LoRa data packet and packet header, and converts the data packet into a JSON packet according to the GWMP protocol;
[0010] S3: The gateway downlink data processing thread processes the JSON packet to obtain the gateway downlink data packet, and checks the validity of the data packet;
[0011] S4: Sort the valid data packets periodically, judge whether the difference between the minimum time of the downlink data packet and the current time is less than the downlink delay value, and according to the judgment result, start the LoRa data sending operation, and select the downlink sending channel according to the downlink channel priority.
[0012] The header information of the current data packet contains frequency, rate, encoding, bandwidth, data packet length, data packet RSSI, data packet snr, etc. All received LoRa data packets and packet headers are extracted from the lora data receiving queue rxq, and the data packets are converted into JSON packets according to the GWMP protocol, and then sent to the LoRaWAN server through the backhaul network (CAT1\WIFI). After processing, the gateway uplink data processing thread is suspended again; the gateway downlink data processing thread periodically queries and receives the JSON packets issued by the server, and converts the valid JSON packets into gateway downlink data packets according to the GWMP protocol, and checks the validity of the downlink data.
[0013] The main purpose of the present application is to realize a low-cost, low-power, multi-channel and full-duplex LoRaWAN Class A gateway communication mechanism based on MCU and RTOS (RT-Thread), which is compatible with the multi-channel and single-rate application scenarios of the standard LoRaWAN network. The method can be used to realize a low-cost, low-power, multi-channel and full-duplex single-rate LoRaWAN gateway, which has the characteristics of multi-channel parallel uplink communication, full-duplex communication, low BOM cost and low power consumption, and supports standard LoRaWAN network Class A\Class C communication, and can be used to connect standard LoRaWAN terminal devices to the specified channel of the LoRaWAN network.
[0014] Compared with the Linux-based high-performance multi-channel gateway, the gateway realized by the method has quasi-multi-channel communication capability while meeting full-duplex communication, and is particularly suitable for application scenarios where the number of terminal devices is not large, the devices are distributed sparsely, the LoRaWAN network coverage is blind, and the outdoor solar power supply is used, and the number of LoRa channels can be flexibly configured according to the actual application scenario, which has a higher input-output ratio.
[0015] As a preferred, the step S1 is further represented as:
[0016] S1.1: using an object-oriented method, constructing a lora radio object structure and a lora radio operation method, and accessing and controlling the target lora channel according to the input lora radio object;
[0017] S1.2: setting the running parameters of N LoRa channels, and enabling the LoRa channel reception completion interrupt and the data header reception interrupt;
[0018] S1.3: the MCU accesses the LoRa chip through SPI, controls N LoRa chips to be in a real-time receiving state, and suspends the gateway uplink data processing thread when there is no LoRa data communication;
[0019] S1.4: If the LoRa chip receives lora data, the LoRa chip triggers the MCU interrupt, after the LoRa data reception is completed, the LoRa chip wakes up the MCU, records the accurate reception time t1 of the lora data packet, and assembles the header information of the current data packet, and caches the received lora data packet and the header information to the lora data reception queue rxq, sends the LoRa reception completion event, and wakes up the gateway uplink data processing thread.
[0020] The lora radio object structure includes LoRa chip interface (spi device, nss, reset, busy, dio1, etc.), radio frequency data packet parameters, radio frequency modulation parameters, etc. The lora radio operation method accesses and controls the target lora channel according to the incoming lora radio object, and through this method, N LoRa channel control can be easily realized, and multi-channel lora communication function can be simplified. In S1.2, for example, when N=2, one LoRa channel is set to work in CH1 channel (frequency f1 and rate SF7, BW125), and the other LoRa channel is set to work in CH2 channel (frequency f2 and rate SF8, BW125). The LoRa chip notifies the MCU of the completion of data transmission or the reception of new LoRa data through the DIO pin. In the case of no LoRa data communication (transmission and reception), the gateway uplink data processing thread is suspended, waiting for the lora reception completion event to trigger and wake up the thread, and further process the data, so as to reduce the system power consumption as much as possible. S1.4 maximizes the interrupt processing event, effectively improves the processing concurrent data capability.
[0021] As a preferred, the step S1.4 is further represented as:
[0022] A1: LoRa DIO interrupt trigger, judge whether the LoRa channel LoRa data transmission is completed interrupt, if yes, send completion event, LoRa interrupt return, if not complete interrupt, execute step A2;
[0023] A2: judge whether the LoRa channel Header reception is interrupted, if yes, mark the LoRa channel as RXING, LoRa interrupt return, if the reception is not interrupted, execute step A3;
[0024] A3: judge whether the LoRa channel LoRa data reception is completed interrupt, if not, LoRa interrupt return, if yes, execute step A4;
[0025] A4: get the received lora data packet timestamp t1, judge whether the LoRa data packet crc check is qualified, if not, send error event, LoRa interrupt return, if qualified, execute step A5;
[0026] A5: According to the LoRa object information, the LoRa channel number is obtained, the LoRa data packet header information is assembled, the received data packet length is resolved, and the cache is dynamically allocated from the rxq queue;
[0027] A6: It is judged whether the rxq queue cache application is successful. If not, the error event is received, the LoRa interrupt is returned, and if successful, step A7 is executed;
[0028] A7: The packet header and data are inserted into the tail of the rxq queue, the system LoRa reception event is sent, and the LoRa interrupt is returned.
[0029] If the LoRa chip starts to receive lora data, the LoRa chip is set to trigger the MCU IO interrupt through DIO1 IRQ_HEADER first, and the LoRa channel is marked as RXING. After the LoRa data reception is completed, the LoRa chip is set to wake up the MCU through DIO1 IRQ_RXDONE interrupt, and the accurate reception time t1 of the data packet is recorded, and the time accuracy is us. Then the header information of the current data packet (including frequency freq, rate dr, encoding cr, bandwidth bw, data packet length size, data packet RSSI, data packet snr, etc.) is assembled, and the received LoRa data packet and the header information are cached together to the lora data reception queue (rxq), and then the LoRa reception completion event is sent, and the gateway uplink data processing thread is woken up. To maximize the reduction of interrupt processing events, effectively improve the processing concurrent data capability.
[0030] As a preferred, the step S2 is further represented as:
[0031] S2.1: Start the timer and set the continuous operation mode, set tick=1us;
[0032] S2.2: Register all channel LoRa modules and their working parameters, and set all channel LoRa modules to work in continuous reception state;
[0033] S2.3: It is judged whether the LoRa channel receives the completion event. If not, it is judged whether the LoRa channel sends the completion event. If the LoRa channel does not send the completion event, it is judged whether the LoRa channel has an error event, and then the LoRa channel reenters the reception. If the LoRa channel sends the completion event, the LoRa channel reenters the reception;
[0034] S2.4: If the LoRa channel receives a completion event, query the rxq queue for data. If there is no data, suspend the task. If there is data, take the valid data from the rxq queue, delete the data from the rxq queue, extract the header information and the data packet, recombine the data packet into a JSON data packet that meets the GWMP protocol, send the JSON data packet to the LoRaWAN server, and then query the rxq queue for data again. Repeat step S2.4.
[0035] After the gateway uplink data processing thread is awakened, all received LoRa data packets and packet headers are extracted from the lora data reception queue (rxq), and the data packets are converted into JSON packets according to the GWMP protocol, and then sent to the LoRaWAN server through the backhaul network (CAT1\WIFI). After processing is completed, the system is suspended again.
[0036] As a preferred embodiment, the step S3 further comprises:
[0037] S3.1: Start receiving server downlink tasks and regularly listen to the server downlink port;
[0038] S3.2: Determine whether valid downlink ISON data from the server is received. If yes, return to step S3.1. If no, execute step S3.3;
[0039] S3.3: Determine whether the downlink data packet time t2 is greater than the first threshold value. If yes, return to step S3.1. If no, execute step S3.4;
[0040] S3.4: Determine whether the downlink data packet time t2 is less than the second threshold value. If yes, return to step S3.1. If no, execute step S3.5;
[0041] S3.5: Determine whether the downlink data packet time t2 overlaps with the time t2 of the already pending downlink data packet. If yes, return to step S3.1. If no, execute step S3.6;
[0042] S3.6: Convert the GWMP JSON data packet into a local downlink data packet and store it in the downlink queue txq. Suspend for a delay and return to step S3.1.
[0043] The first threshold value is used to determine whether the downlink time t2 is too late to issue. The second threshold value is used to determine whether the downlink time t2 is too early to issue.
[0044] As a preferred embodiment, the step S4 further comprises:
[0045] S4.1: judging whether there is downlink data packet in the downlink txq queue, if yes, periodically arranging the valid data packets in ascending order of time t2, when the difference between the minimum time in the downlink data packet and the current time is less than the downlink delay value, extracting the downlink data packet from the downlink txq queue, deleting the downlink data packet from the downlink txq queue, and then starting the sending operation;
[0046] S4.2: according to the downlink channel priority, finding and selecting the LoRa channel which is not currently in the valid data receiving process, if all LoRa channels are in the data receiving process, selecting the last LoRa channel as the downlink sending channel.
[0047] For example, CH0 is in the valid data receiving process, judging whether CH1 is in the data receiving process, if all LoRa channels are in the data receiving process, selecting the last LoRa channel as the downlink sending channel.
[0048] As a preferred, the step method further comprises realizing LoRaWAN Class A accurate communication through microsecond level time management:
[0049] B1: first power-on, setting the MCU timer to work in continuous mode, and initializing;
[0050] B2: judging whether the LoRa chip receives air interface LoRa data, if yes, triggering the LoRa receiving interrupt processing function through DIO interrupt, and recording the receiving data timestamp t1, at the same time, recombining the packet header of the current data packet, storing the packet header information and the receiving data into the rxq queue;
[0051] B3: according to the Class A communication requirement, the lorawan server will increase the receiving delay time according to the timestamp of each uplink data packet, to obtain the downlink timestamp value t2;
[0052] B4: taking out the valid downlink data packet from the sending queue txq, obtaining the time t2 in each data packet header and the radio frequency communication parameters, and writing the radio frequency parameters and the to-be-downloaded data packet into the registers of the selected downlink lora channel in advance;
[0053] B:5: writing t2 into the comparison register of the MCU timer, starting the comparison timing interrupt, after the comparison timer interrupt of the timer is triggered, executing the sending command of the LoRa chip, and immediately sending the downlink LoRa data packet to the LoRaWAN terminal device.
[0054] The microsecond-level time management is implemented to meet the accurate timing requirements of LoRaWAN Class A communication. The packet header of the current data packet is reorganized to include radio frequency parameters, a receiving timestamp t1, etc. The lorawan server, according to the requirements of Class A communication, adds a receiving delay time (1s by default, and 15s at most) according to the timestamp of each uplink data packet to obtain a downlink timestamp value t2, i.e. t2 = t1 + 1000000. The radio frequency communication parameters include a frequency freq, a rate dr, a code cr, a bandwidth bw, a data packet content, and a data packet length size.
[0055] As preferred, the method further comprises:
[0056] If the gateway receives the LoRaWAN terminal data, the gateway forwards the data to the LoRaWAN server through an Ethernet or WIFI network.
[0057] If the gateway receives the downlink data packet of the LoRaWAN server, the gateway sends the data packet to the LoRaWAN terminal device through a LoRa chip.
[0058] If an AP6212 WIFI module is used, the SDIO interface is used to communicate with the MCU to provide WIFI communication; if an ESP32 WIFI module or a CAT1 module is used, the serial port interface is used to communicate with the MCU to provide WIFI communication or cellular network communication.
[0059] The backhaul network accesses a public network, and the LoRaWAN server and the gateway perform data interaction through a GWMP-UDP protocol.
[0060] A LoRaWAN Class A full-duplex gateway communication system based on an MCU comprises:
[0061] A host MCU is connected with a radio frequency front end comprising N LoRa transceiver modules through SPI peripheral pins and GPIOs, and the host MCU is further connected with a backhaul network and a debugging interface.
[0062] The host MCU can be a low-power MCU such as STM32H or STM32L4 or STM32WL. The radio frequency front end adopts N LoRa chips, and the number N can be configured as a multiple according to system capacity requirements. Alternatively, the host MCU uses a LoRa SoC module, which can save one LoRa chip.
[0063] The application supports 1 to N LoRa channels, which can be flexibly configured, and supports multi-channel and single-rate communication of standard LoRaWAN network communication, and supports LoRaWAN Class A and Class C device types.
[0064] As preferred, the backhaul network adopts an AP6212 WiFi module or an ESP32 WiFi module, a CAT1 module, the master MCU is connected with the AP6212 WiFi module through an SDIO interface, and the master MCU is connected with the ESP32 WiFi module or the CAT1 module through a serial port.
[0065] The gateway receives and processes the LoRaWAN terminal device forwarded to the LoRaWAN server in real time on the designated N channels, and the gateway receives and processes the LoRaWAN server data in real time on the designated N channels and forwards it to the LoRaWAN terminal.
[0066] Therefore, the present application has the following beneficial effects: 1. It can be used to realize a low-cost, low-power, multi-channel, full-duplex single-rate LoRaWAN gateway, which has the characteristics of multi-channel parallel uplink communication, full-duplex communication, low BOM cost, low power consumption, etc., supports standard LoRaWAN network Class A\Class C communication, and can be used to connect standard LoRaWAN terminal devices to the LoRaWAN network of the designated channel; 2. Compared with the Linux-based high-performance multi-channel gateway, it has quasi-multi-channel communication capability while meeting full-duplex communication, and is particularly suitable for application scenarios where the number of terminal devices is not large, the devices are distributed sparsely, the LoRaWAN network coverage is blind, and the outdoor solar power supply is used, and the number of LoRa channels can be flexibly configured according to the actual application scenario, which has a higher input-output ratio. BRIEF DESCRIPTION OF DRAWINGS
[0067] Figure 1 The step flowchart of the method of the present application.
[0068] Figure 2 The interrupt step flowchart of the method of the present application.
[0069] Figure 3 The uplink data processing step flowchart of the method of the present application.
[0070] Figure 4 The downlink data processing step flowchart of the method of the present application.
[0071] Figure 5 The LoRa data sending step flowchart of the method of the present application.
[0072] Figure 6 The architecture diagram of the system of the present application.
[0073] Figure 7 The design schematic diagram of the dual-channel LoRaWAN gateway of the system of the present application.
[0074] Figure 8 The connection schematic diagram of the master MCU of the system of the present application.
[0075] Figure 9 This is a design diagram of the 2-way LoRa chip module interface circuit of the system of the present invention.
[0076] In the figure: 1. Main control MCU; 2. LED module; 3. KEY module 3; 4. Jlink SWD debugging interface; 5. SD circuit; 6. Power management module; 7. RF front end; 8. Backhaul network; 9. LoRa transceiver module. DETAILED DESCRIPTION
[0077] The present invention is further described in detail below with reference to the accompanying drawings and specific embodiments:
[0078] like Figure 1 In the illustrated embodiment, a LoRaWAN Class A full-duplex gateway communication method based on an MCU can be seen, and its operation process is as follows: Step 1, the operating parameters of N LoRa channels are set, and the MCU is used to control the N-way LoRa chip to be in a real-time receiving state. According to the data received by the LoRa chip, the MCU interrupt is triggered or awakened, and the reception time t1 of the LoRa data packet is recorded, and the header information of the current data packet is formed. After the LoRa data is received, the gateway uplink data processing thread is awakened; Step 2, the gateway uplink data processing thread extracts the received LoRa data packet and header, and converts the data packet into a JSON packet according to the GWMP protocol; Step 3, the gateway downlink data processing thread processes the JSON packet to obtain a gateway downlink data packet and verifies the validity of the data packet; Step 4, periodically sorting the valid data packets, judging whether the difference between the minimum time of the downlink data packet and the current time is less than the downlink delay value, starting the LoRa data sending operation according to the judgment result, and selecting the downlink sending channel according to the downlink channel priority.
[0079] LoRa is a linear spread spectrum modulation scheme with low power consumption and long communication distance. LoRaWAN is a low-power wide area network communication technology. LoRaWAN Class A devices are defined by LoRaWAN. GWMP is the first-generation communication protocol between LoRaWAN servers and LoRaWAN gateways.
[0080] This method can be used to implement a low-cost, low-power, multi-channel, full-duplex, single-rate LoRaWAN gateway with the characteristics of multi-channel parallel uplink communication, full-duplex communication, low BOM cost, low power consumption, etc. It supports standard LoRaWAN network Class A\Class C communication and can be used to connect standard LoRaWAN terminal devices to the LoRaWAN network of a specified channel.
[0081] Compared with the Linux-based high-performance multi-channel gateway, the gateway realized by the method has quasi-multi-channel communication capability while meeting full-duplex communication, is particularly suitable for application scenarios such as small amount of terminal device access, sparse device distribution, LoRaWAN network coverage blind filling, outdoor solar power supply, and can flexibly configure the number of LoRa channels according to the actual application scenario needs, has a higher input-output ratio.
[0082] To further illustrate the technical solutions of the present application, the implementation method of the double-channel, full-duplex LoRaWAN gateway communication mechanism is further described with N=2:
[0083] One: power on the system, initialize N LoRa chips and backhaul network, and connect to the public network.
[0084] After the system is powered on, initialize the LoRa chip (the embodiment uses SX126x chip), backhaul network, etc., and control the WIFI\CAT1 module to connect to the public network.
[0085] After the system is powered on, initialize N LoRa chips (the embodiment uses SX126x chip, such as SX1268), backhaul network, etc., and control the WIFI\CAT1 module to connect to the public network.
[0086] The gateway receives and processes LoRaWAN terminal device data forwarded to the LoRaWAN server in real time on the specified N channels.
[0087] The gateway receives and processes LoRaWAN server data in real time on the specified N channels and forwards it to the LoRaWAN terminal.
[0088] Two: lora multi-channel, full-duplex, low-power operation mechanism.
[0089] Specifically:
[0090] First step: set the running parameters of N LoRa channels, use MCU to control N LoRa chips to be in real-time receiving state, trigger or wake up MCU interrupt according to the LoRa chip data receiving situation, record the receiving time t1 of the LoRa data packet, and assemble the packet header information of the current data packet. After the LoRa receives the data, wake up the gateway uplink data processing thread.
[0091] The specific process is:
[0092] 1. Use object-oriented method to build lora radio object structure and lora radio operation method, and access and control the target lora channel according to the input lora radio object.
[0093] The lora radio object structure includes LoRa chip interface (spi device, nss, reset, busy, dio1, etc.), radio frequency data packet parameters, radio frequency modulation parameters, etc. The lora radio operation method accesses and controls the target lora channel according to the incoming lora radio object, and through the method, N LoRa channel control can be conveniently realized, and multi-channel lora communication function can be simplified.
[0094] 2. Set the running parameters of N LoRa channels, and enable the LoRa channel reception completion interrupt and the data header reception interrupt. For example, when N=2, set one LoRa channel to work in CH1 channel (frequency f1 and rate SF7, BW125), and set another LoRa channel to work in CH2 channel (frequency f2 and rate SF8, BW125).
[0095] 3. The MCU accesses the LoRa chip (such as SX1268) through SPI to control N LoRa chips to be in a real-time receiving state. The LoRa chip notifies the MCU of the completion of data transmission or the reception of new LoRa data through the DIO pin.
[0096] 4. In the case of no LoRa data communication (transmission and reception), the gateway uplink data processing thread is suspended, waiting for the lora reception completion event to trigger and wake up the thread, and further process the data to reduce system power consumption as much as possible.
[0097] 5. If the LoRa chip starts to receive lora data, set the LoRa chip to first trigger the MCU IO interrupt through DIO1 IRQ_HEADER, and mark the LoRa channel as RXING. After the LoRa data reception is completed, set the LoRa chip to wake up the MCU through DIO1 IRQ_RXDONE interrupt, record the accurate reception time t1 of the data packet, and the time accuracy is us. Then, the header information of the current data packet (including frequency freq, rate dr, encoding cr, bandwidth bw, data packet length size, data packet RSSI, data packet snr, etc.) is assembled, and the received LoRa data packet and the header information are cached together in the lora data reception queue (rxq), and then the LoRa reception completion event is sent to wake up the gateway uplink data processing thread. To maximize the reduction of interrupt processing events and effectively improve the processing concurrent data capability.
[0098] The specific process of triggering the interrupt is as shown in Figure 2
[0099] (1) LoRa DIO interrupt trigger, judge LoRa channel LoRa data transmission whether complete interrupt, if yes, system LoRa sends complete event, LoRa interrupt returns, if not complete interrupt then execute (2);
[0100] (2) judge LoRa channel Header receives whether interrupt, if yes then mark this judge LoRa channel as RXING, LoRa interrupt returns, if receive not interrupt then execute (3);
[0101] (3) judge LoRa channel LoRa data reception whether complete interrupt, if not, LoRa interrupt returns, if yes, execute (4);
[0102] (4) get receive timestamp t1, judge LoRa data package crc check whether eligible, if not, system LoRa receives error event, LoRa interrupt returns, if eligible then execute (6);
[0103] (5) according to LoRa object information, get LoRa channel number, build LoRa data package header information, decompose received data package length, from rxq queue dynamic allocation cache;
[0104] (6) judge rxq queue cache application whether successful, if not successful, system LoRa receives error event, LoRa interrupt returns, if successful then execute (8);
[0105] (7) insert header and data to rxq queue tail, send system LoRa receives event, LoRa interrupt returns.
[0106] Second step: gateway uplink data processing thread extracts received LoRa data package and header, and converts data package into JSON package according to GWMP protocol.
[0107] Gateway uplink data processing thread wakes up, extracts all received LoRa data package and header from lora data receiving queue (rxq), and converts data package into JSON package according to GWMP protocol, then sends to LoRaWAN server through backhaul network (CAT1\WIFI), after processing, the system is suspended again.
[0108] The specific steps of processing uplink data are as shown in Figure 3
[0109] Start timer and set continuous operation mode, set tick=1us;
[0110] Register all channel LoRa modules and their working parameters, and set all channel LoRa modules to work in continuous reception state;
[0111] If the LoRa channel receives a complete event, it is determined whether the rxq queue has data. If so, valid data is taken from the rxq queue, the data is deleted from the rxq queue, the header information is extracted, and the data packet is reassembled into a JSON data packet that meets the GWMP protocol. The JSON data packet is sent to the LoRaWAN server, and the queue is queried again to determine whether there is data.
[0112] If the LoRa channel receives a complete event, it is determined whether the rxq queue has data. If so, valid data is taken from the rxq queue, the data is deleted from the rxq queue, the header information is extracted, and the data packet is reassembled into a JSON data packet that meets the GWMP protocol. The JSON data packet is sent to the LoRaWAN server, and the queue is queried again to determine whether there is data.
[0113] Step 3: The gateway downlink data processing thread processes the JSON packet to obtain the gateway downlink data packet and checks the validity of the data packet.
[0114] The gateway downlink data processing task (lora_gw_thread_dn) periodically queries and receives the JSON packet sent by the server. Valid JSON packets are converted into gateway downlink data packets according to the GWMP protocol. The validity of the downlink data packet is checked, and it is checked whether the downlink time t2 is too late to be sent, whether it is too early to be sent, and whether the downlink data packet time has been selected to overlap.
[0115] The specific steps for processing downlink data are as shown in Figure 4
[0116] (1) The server downlink task starts, and the server downlink port is periodically monitored;
[0117] (2) It is determined whether valid downlink ISON data from the server is received. If so, return to (1), and if not, perform (3);
[0118] (3) It is determined whether the downlink data packet time t2 is greater than the first threshold. If so, return to (1), and if not, perform (4);
[0119] (4) It is determined whether the downlink data packet time t2 is less than the second threshold. If so, return to (1), and if not, perform (5);
[0120] (5) It is determined whether the downlink data packet time t2 overlaps with the already pending downlink data t2 time. If so, return to (1), and if not, perform (6);
[0121] (6) Convert the GWMP JSON data packet into a local downlink data and store it in the downlink queue txq. Delay and suspend, and return to (1).
[0122] Fourth step: periodically sort the valid data packets, judge whether the difference between the minimum time of downlink data packet and current time is less than the downlink delay value, start the LoRa data sending operation according to the judgment result, and select the downlink sending channel according to the downlink channel priority.
[0123] The LoRa data sending process is as shown in Figure 5
[0124] First, suspend the delay, judge whether there is downlink data packet in the txq queue, if yes, periodically sort the valid data packets in ascending order according to time t2, if no, suspend the delay and rejudge whether there is valid data packet.
[0125] After sorting, judge whether the difference between the minimum time of downlink data packet and current system time is less than the downlink delay value (Tdelay), extract the downlink data from the downlink txq queue, and then start the sending operation; suspend the delay and rejudge.
[0126] According to the downlink channel priority, find and select the LoRa channel (available LoRa channel) which is not currently in the process of receiving data, for example, CH0 is in the process of receiving data, judge whether CH1 is in the process of receiving data, if all LoRa channels are in the process of receiving data, select the last LoRa channel as the downlink sending channel.
[0127] After obtaining the available LoRa channel, write the downlink radio frequency parameters (freq\dr\bw…) and downlink data data into the current LoRa chip register in advance. Write t2daomcu comparison timing register (CCM) to enable comparison interrupt and mark the LoRa channel as busy.
[0128] Perform the above steps to realize the LoRaWAN multi-channel uplink and full-duplex Class A communication function.
[0129] Three: LoRaWAN Class A precise communication mechanism implementation.
[0130] Implement microsecond-level time management to meet the precise timing requirements of LoRaWAN Class A communication:
[0131] 1. First power on, set the MCU hardware 32-bit timer timer to work in continuous mode, and initialize it once.
[0132] 2. After the LoRa chip receives the air interface LoRa data, it will trigger the LoRa receive interrupt processing function through the DIO interrupt, immediately record the data reception timestamp t1 with a precision of us, and reassemble the packet header (radio frequency parameters, reception timestamp t1, etc.) of the current data packet, store the packet header information and received data into the rxq queue together.
[0133] 3, Lorawan server according to Class A communication requirements, will be based on the timestamp of each uplink data packet, increase RX1DELAY time (default 1s, maximum 15s), get downlink timestamp value t2, that is, t2 = t1 + 1000000.
[0134] 4, from the sending queue txq take out the effective downlink data packet, get the time t2 and radio frequency communication parameters (including frequency, rate, coding, bandwidth, data packet content, data packet length size) in each data packet header.
[0135] 5, the radio frequency parameters, the data packet to be issued in advance are written into the register of the selected downlink lora channel.
[0136] 6, write t2 into the comparison register of mcu 32 bit timer timer2, start the comparison timer interrupt.
[0137] 7, after the comparison timer interrupt of the timer is triggered, execute the sending command of LoRa chip, immediately send downlink LoRa data packet to LoRaWAN terminal device.
[0138] Repeat the above steps to realize LoRaWAN Class A precise communication timing.
[0139] Four: backhaul network uses low-cost WiFi module (AP6212\ESP8266) \CAT1 module (L610) to access public network, and interacts with LoRaWAN server through GWMP-UDP protocol.
[0140] Specifically, it includes:
[0141] (1) after the gateway receives the LoRaWAN terminal data, the gateway transmits the data to the LoRaWAN server through Ethernet or WIFI network;
[0142] (2) after the gateway receives the downlink data packet of LoRaWAN server, it is sent to LoRaWAN terminal device through SX126x LoRa chip;
[0143] (3) AP6212 WiFi module is used, which communicates with MCU through SDIO interface and provides WiFi communication service;
[0144] (4) ESP32 WiFi module \ CAT1 module (L610) is used, which communicates with MCU through serial interface and provides WiFi communication service or cellular network communication service.
[0145] The gateway product realized by the method has duplex capability, smaller volume, is convenient to carry and install on site, and can be used for early development and debugging of LoRaWAN standard terminal products, LoRaWAN system teaching, and the like. The gateway complete machine realized by the method has low BOM cost and has a significant cost advantage. The method provides an economically feasible solution for a small number of LoRaWAN terminal products to access a specified channel and a specified rate of a standard LoRaWAN server platform. The gateway realized by the method has lower power consumption and can be used in remote outdoor scenarios such as solar power supply.
[0146] The embodiment also includes a low-power, multi-channel, full-duplex gateway communication system based on an MCU, as shown in Figure 6 , which includes:
[0147] The main control MCU 1 is connected with an LED module 2, a KEY module 3, a Jlink SWD debugging interface 4, an SD circuit 5, a power management module 6, and a radio frequency front end 7 and backhaul network 8, respectively.
[0148] In the embodiment, the main control MCU can use an STM32H or STM32L4 or STM32WL low-power MCU, which can be selected according to system power consumption requirements. Alternatively, the main control MCU uses a LoRa SoC module, which can save a LoRa chip.
[0149] The radio frequency front end uses N LoRa transceiver modules (LoRa chips) 9, as shown in Figure 6 , which are connected with the main control MCU through an SPI interface, and the number of N can be configured according to system capacity requirements. The number of N is taken as 2 in the following description of the implementation of the double-channel receiving and full-duplex LoRaWAN communication mechanism.
[0150] The LoRa transceiver module can use a LoRa chip to reduce the power consumption of radio frequency transmission and reception.
[0151] As shown in Figure 7 , it is a design schematic diagram of a double-channel LoRaWAN gateway:
[0152] On the basis of Figure 6 , the main control MCU is connected with one LoRa transceiver module through an SPI2, and transmits and receives through a LoRa TX / RX.
[0153] As shown in Figure 8 , it is a design scheme using N=2:
[0154] The MCU is connected with SPI pins (MISO\MOSI\SCK), NSS, BUSY, DIO1, RESET and the like of two LoRa chips through two-way SPI peripheral pins and GPIOs. Figure 9
[0155] The backhaul network adopts an AP6212 WiFi module or an ESP32 WiFi module or a CAT1 module, a main control MCU is connected with the AP6212 WiFi module through an SDIO interface, and the main control MCU is connected with the ESP32 WiFi module or the CAT1 module through a serial port.
[0156] The application supports 1~N LoRa channels, can be flexibly configured, supports multi-channel and single rate communication of standard LoRaWAN network communication, and supports LoRaWAN Class A\Class C device types.
[0157] The above-mentioned embodiments are only a preferred scheme of the application, and do not limit the application in any form, and other variants and modifications can be made without exceeding the technical scheme recorded in the claims.
Claims
1. A LoRaWAN Class A full-duplex gateway communication method based on MCU, characterized in that: It includes the following steps: S1: Using object-oriented methods, construct the LoRa radio object structure and LoRa radio operation method, access and control the target LoRa channel according to the incoming LoRa radio object; set the operating parameters of N LoRa channels, use MCU to control N LoRa chips to be in real-time receiving state, and suspend the gateway uplink data processing thread when there is no LoRa data communication; trigger or wake up the MCU interrupt according to the data received by the LoRa chip. After the LoRa data is received, wake up the MCU, record the reception time t1 of the LoRa data packet, build the header information of the current data packet, cache the received LoRa data packet and the header information together in the LoRa data receiving queue, and wake up the gateway uplink data processing thread; S2: The gateway uplink data processing thread extracts the received LoRa data packet and packet header, and converts the data packet into a JSON packet according to the GWMP protocol; S3: The gateway downlink data processing thread processes the JSON packet, obtains the gateway downlink data packet, and verifies the validity of the data packet; S4: Periodically sort the valid data packets, determine whether the difference between the minimum time of the downlink data packet and the current time is less than the downlink delay value, start the LoRa data sending operation based on the judgment result, and select the downlink sending channel according to the downlink channel priority.
2. A LoRaWAN Class A full-duplex gateway communication method based on MCU according to claim 1, characterized in that, The step S1 is further expressed as: S1.1: Set the operating parameters of N LoRa channels and enable the LoRa channel reception completion interrupt and data header reception interrupt; S1.2: The MCU accesses the LoRa chip through SPI and controls the N-channel LoRa chips to be in real-time receiving state. When there is no LoRa data communication, the gateway uplink data processing thread is suspended; S1.3: If the LoRa chip receives LoRa data, the LoRa chip triggers an MCU interrupt through DIO1 IRQ_RXDONE. After the LoRa data reception is completed, the LoRa chip wakes up the MCU, records the exact reception time t1 of the LoRa data packet, and assembles the header information of the current data packet. The header information includes frequency, rate, coding and bandwidth, and caches the received LoRa data packet and header information to the LoRa data receiving queue rxq, sends a LoRa reception completion event, and wakes up the gateway uplink data processing thread.
3. A LoRaWAN Class A full-duplex gateway communication method based on MCU according to claim 2, characterized in that, The step S1.3 is further expressed as: A1: LoRa DIO interrupt is triggered to determine whether the LoRa channel LoRa data transmission interrupt is completed. If so, the sending completion event is returned and the LoRa interrupt is returned. If the interrupt is not completed, execute step A2; A2: Determine whether the LoRa channel Header reception is interrupted. If so, mark the LoRa channel as RXING and return the LoRa interrupt. If reception is not interrupted, execute step A3. A3: Determine whether the LoRa channel LoRa data reception is interrupted. If not, the LoRa interrupt returns. If so, execute step A4. A4: Get the timestamp t1 of the received LoRa data packet and determine whether the LoRa data packet CRC check is qualified. If not, an error event is received and the LoRa interrupt is returned. If qualified, execute step A5. A5: According to the LoRa object information, obtain the LoRa channel number, construct the LoRa data packet header information, decompose the received data packet length, and dynamically allocate buffer from the rxq queue; A6: Determine whether the rxq queue buffer application is successful. If not, an error event is received and the LoRa interrupt is returned. If successful, execute step A7. A7: Insert the packet header and data to the end of the rxq queue, send the system LoRa receive event, and the LoRa interrupt returns.
4. A LoRaWAN Class A full-duplex gateway communication method based on MCU according to claim 1, 2 or 3, characterized in that, The step S2 is further expressed as: S2.1: Start the timer and set it to continuous working mode, setting tick=1us; S2.2: Register all channel LoRa modules and their operating parameters, and set all channel LoRa modules to work in continuous receiving state; S2.3: Determine whether the LoRa channel has received a completion event. If not, determine whether the LoRa channel has sent a completion event. If the LoRa channel has not sent a completion event, determine whether the LoRa channel has an error event and then re-enter the receiving state. If the LoRa channel sends a completion event, then re-enter the receiving state. S2.4: If the LoRa channel receives a completion event, it queries the rxq queue for data. If not, it suspends the task. If so, it takes out the valid data from the rxq queue and deletes the data in the rxq queue. It extracts the header information and reassembles the data packet into a JSON data packet that meets the GWMP protocol. After sending the JSON data packet to the LoRaWAN server, it queries the rxq queue again for data and repeats step S2.
4.
5. A LoRaWAN Class A full-duplex gateway communication method based on MCU according to claim 1 or 2, characterized in that, The step S3 further comprises: S3.1: The receiving server downlink task starts and the server downlink port is monitored regularly; S3.2: Determine whether valid downlink ISON data from the server has been received. If so, return to step S3.1; if not, proceed to step S3.
3. S3.3: Determine whether the downlink data packet time t2 is greater than the first threshold. If so, return to step S3.1; if not, proceed to step S3.4; S3.4: Determine whether the downlink data packet time t2 is less than the second threshold. If so, return to step S3.1; if not, proceed to step S3.
5. S3.5: Determine whether the downlink data packet time t2 overlaps with the pending downlink data packet time t2. If so, return to step S3.1; if not, proceed to step S3.
6. S3.6: Convert the GWMP JSON data packet into local downlink data and store it in the downlink queue txq, suspend it for a while, and return to step S3.
1.
6. A LoRaWAN Class A full-duplex gateway communication method based on MCU according to claim 1, 2 or 3, characterized in that: The step S4 further comprises: S4.1: Determine whether there is a downlink data packet in the downlink txq queue. If so, periodically sort the valid data packets in ascending order according to time t2. When the difference between the minimum time in the downlink data packet and the current time is less than the downlink delay value, extract the downlink data packet from the downlink txq queue, delete the downlink data packet from the downlink txq queue, and then start the sending operation. S4.2: According to the downlink channel priority, search and select the LoRa channel that is not currently receiving valid data. If all LoRa channels are receiving data, select the last LoRa channel as the downlink sending channel.
7. The MCU-based LoRaWAN Class A full-duplex gateway communication method according to claim 1, wherein: The method also includes achieving LoRaWAN Class A precision communication through microsecond-level time management: B1: When powered on for the first time, set the MCU timer to continuous working mode and initialize it; B2: Determine whether the LoRa chip has received air interface LoRa data. If so, the LoRa receive interrupt processing function is triggered through the DIO interrupt, and the received data timestamp t1 is recorded. At the same time, the header of the current data packet is reassembled and the header information and the received data are stored in the rxq queue together; B3: In accordance with Class A communication requirements, the loRaWAN server will add the receiving delay time to the timestamp of each uplink data packet to obtain the downlink timestamp value t2; B4: Take out valid downlink data packets from the transmit queue txq, obtain the time t2 and RF communication parameters in each data packet header, and write the RF parameters and the data packets to be sent into the register of the selected downlink LoRa channel in advance; B:5: Write t2 into the comparison register of the MCU timer and start the comparison timer interrupt. After the comparison timer interrupt of the timer is triggered, execute the sending command of the LoRa chip and immediately send the downlink LoRa data packet to the LoRaWAN terminal device.
8. A LoRaWAN Class A full-duplex gateway communication method based on MCU according to claim 1 or 7, characterized in that: The method further comprises: If the gateway receives LoRaWAN terminal data, it forwards it to the LoRaWAN server via Ethernet or WIFI network; If the gateway receives the downlink data packet from the LoRaWAN server, it will be sent to the LoRaWAN terminal device through the LoRa chip; Among them, if the AP6212 WIFI module is used, it communicates with the MCU through the SDIO interface to provide WIFI communication; if the ESP32 WIFI module or CAT1 module is used, it communicates with the MCU through the serial port interface to provide WIFI communication or cellular network communication.
9. A LoRaWAN Class A full-duplex gateway communication system based on an MCU, adopting the LoRaWAN Class A full-duplex gateway communication method based on an MCU according to any one of claims 1 to 8, characterized in that: include: A main control MCU is connected to a radio frequency front end including N LoRa transceiver modules through SPI peripheral pins and GPIO. The main control MCU is also connected to a backhaul network and a debugging interface.
10. The MCU-based LoRaWAN Class A full-duplex gateway communication system according to claim 9, characterized in that: The backhaul network uses an AP6212 WiFi module or an ESP32 WiFi module or a CAT1 module. The main control MCU is connected to the AP6212 WiFi module through an SDIO interface, and the main control MCU is connected to the ESP32 WiFi module or the CAT1 module through a serial port.
Citation Information
Patent Citations
Gateway, LoRa (Long Range) network system, gateway running method and storage medium
CN109412937A
Multi-access management service packet classification and prioritization techniques
US20210409335A1