LoRa data forwarding server adopting libuv and libubox
By using C language to develop the LoRa data forwarding server, libuv and libubox are used to simplify the architecture of the LoRa solution, solve the problems of complexity and high cost in the existing technology, and achieve high performance, flexibility and low cost of LoRa data forwarding. , suitable for embedded devices.
Patent Information
- Application Number
- CN202311136817.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-09-05
- Publication Date
- 2024-08-20
AI Technical Summary
The software architecture of the existing open source LoRa solution is too complex and relies on a variety of open source technology stacks and languages, resulting in high development difficulty, complex logic, difficulty in expansion and high cost. It is also not flexible enough to meet the secondary development needs of enterprises.
The LoRa data forwarding server is developed using C language. It uses libuv as a high-performance network framework and the ubus interface provided by libubox. It forwards data through the TCP protocol, simplifying the components and logical structure. It provides a data interface in JSON format and a doubly linked list structure to implement data. Forwarding and control, supporting the forwarding interface of LoRa terminal data.
It reduces the cost of the overall solution, improves market competitiveness, simplifies development and logic, improves CPU utilization and flexibility, can be deployed on embedded devices, and reduces memory usage and development complexity.
Smart Images

Figure CN118519623A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to a LoRa data forwarding server adopting libuv and libubox. Background Art
[0002] At present, the overall solution of open source LoRa generally adopts ChirpStack. The software architecture of this solution is as follows Figure 1 As shown in the figure, its overall architecture is relatively complex and difficult for general developers to master. It relies on components such as MQTT broker, PostgreSQL, and Redis. It provides HTTP, TCP, UDP, MQTT, RabbitMQ and other protocol interfaces.
[0003] The existing software architecture has the following defects: 1. The components are complex and use a lot of open source technology stacks, requiring developers to master multiple development languages and multiple software frameworks. It is not easy to master.
[0004] 2. The logic is complex. The coupling between components makes the code logic more complex and the program is not easy to expand.
[0005] 3. It is not flexible enough and not pure enough. Because it integrates many functions, when the enterprise needs to carry out secondary development, it must fully understand the design plan. When using and deploying, the overall functions must be packaged and shipped out of the factory. The additional functions increase the efficiency of CPU and memory use. Summary of the invention
[0006] The purpose of the present invention is to provide a LoRa data forwarding server using libuv and libubox. On an expensive cloud server, a high-performance LoRa data forwarding server is developed using C language network libraries libuv and libubox, the number of gateway and client access is increased, the forwarding efficiency is optimized, the overall solution cost is greatly reduced, and the market competitiveness of the overall solution is improved.
[0007] To achieve the above-mentioned purpose, the technical solution of the present invention is: a LoRa data forwarding server using libuv and libubox, using C language network libraries libuv and libubox to develop the LoRa data forwarding server, wherein libuv is used as a network framework, the control interface uses the ubus interface provided by libubox, and the operating system platform is ubuntu or debian; a forwarding interface for LoRa terminal data is also provided.
[0008] In one embodiment of the present invention, the LoRa terminal communicates with the LoRa data forwarding server through a LoRa gateway.
[0009] In one embodiment of the present invention, the LoRa data forwarding server uses TCP communication for communication between the LoRa gateway and the server, that is, the data in JSON format is directly encapsulated in the TCP message, and the communication format is: the first byte is the type code and the command code, the second and third bytes are the check code, and the subsequent data is the string data in JSON format, the last byte is 0, and the message type is a data message or a keep-alive message.
[0010] In one embodiment of the present invention, libuv monitors the data of the LoRa gateway through port 8899 and the data accessed by the third-party APP through port 8866. The data of the LoRa gateway monitored by port 8899 is directly forwarded to port 8866 to realize data forwarding. Data reception and forwarding trigger an event in the main thread when the TCP connection or TCP data comes in, and the TCP long connection is processed in the TCP connection callback, and the data reception and forwarding are processed in the data callback.
[0011] In one embodiment of the present invention, the LoRa gateway and the third-party APP are both marked with account attributes to achieve data forwarding between the same accounts. All LoRa gateways in the program are connected in series using a bidirectional linked list structure in C language, and the third-party APPs corresponding to each LoRa gateway are connected in series using a linked list, and the client of the third-party APP is simultaneously mounted under the linked list head pointer of the corresponding LoRa gateway.
[0012] In one embodiment of the present invention, the forwarding interface of the LoRa terminal data includes a TCP interface, a shell command interface, and a web interface, and the TCP interface adopts a json format.
[0013] Compared with the prior art, the present invention has the following beneficial effects: 1. The present invention is written in C language, and only requires familiarity with C language. Libuv is used as a high-performance network framework. Libuv is a high-performance, event-driven I / O library, and provides a cross-platform (such as Windows, Linux) API interface. The control interface (relative to the data interface, without restarting the program, controls the startup of certain functions, or queries certain current states of the program) uses the UBUS interface provided by libubox. UBUS provides a general framework for inter-process communication in the development of the OpenWRT platform. It makes the implementation of inter-process communication very simple. The operating system platform of the present invention is Ubuntu or Debian, and the UBUS library used by OpenWRT can be directly transplanted to Ubuntu or Debian.
[0014] 2. The present invention provides a forwarding interface for LoRa terminal data, so a TCP interface is sufficient, and the json format is adopted. In this way, development is simple, data visualization is simple (similar to a RESTful interface), and the libubox library can also provide a web api interface to control the switches of certain flags of the system, data collection frequency, etc., and can also provide a data display interface and implement a ubus interface, that is, a shell command interface and a web interface. Therefore, development can be done once and used everywhere, which simplifies the logic.
[0015] 3. The solution of the present invention is simple to develop and has clear logic. The key is to use C language. The compiled executable file occupies less FLASH space. The execution efficiency is high using C language, and the CPU utilization rate can be greatly improved. Compared with high-level languages such as JAVA and PYTHON that require the use of virtual machines, this solution can reduce the use of a large amount of memory and can even be deployed on embedded devices, thus bringing about an improvement in flexibility. BRIEF DESCRIPTION OF THE DRAWINGS
[0016] Figure 1 Software architecture for existing solutions.
[0017] Figure 2 It is the overall framework of the present invention.
[0018] Figure 3 For communication format.
[0019] Figure 4 Listening code for Libuv.
[0020] Figure 5 Initializes program for Libuv listening code.
[0021] Figure 6 Design code for the structure of gateway and APP.
[0022] Figure 7 The external interface program code provided by Libubox. DETAILED DESCRIPTION
[0023] The technical solution of the present invention is described in detail below in conjunction with the accompanying drawings.
[0024] The invention provides a LoRa data forwarding server adopting libuv and libubox. The LoRa data forwarding server is developed by using C language network libraries libuv and libubox, wherein libuv is used as a network framework, a control interface uses a ubus interface provided by libubox, and an operating system platform is ubuntu or debian; and a forwarding interface for LoRa terminal data is also provided.
[0025] The following is the specific implementation process of the present invention.
[0026] like Figure 2 As shown, it is the overall framework of the present invention, and the overall scheme is designed as follows: 1. The communication between LoRa terminal and LoRa gateway does not require any modification; 2. For the communication between the Lora gateway and the server, if the open source LoRa server component is used, the data format and communication protocol of the Lora gateway must comply with the protocol specifications of the open source solution. Here, a self-developed protocol is used, using TCP communication, and the data in JSON format is directly encapsulated in the TCP message. Commonly used MQTT, COAP and other protocols are not used here. These two are also commonly used data interaction protocols in the Internet of Things. In order to improve the overall concurrency, throughput, and subsequent engineering maintenance, a self-developed communication solution is used, which further reduces the performance requirements of the LoRa gateway. The communication format is as follows: Figure 3 As shown in the figure: the first byte is the type code and command code, the second and third bytes are the checksum, the subsequent data is a string data in json format, and the last byte is 0. The last byte 0 is to solve the problem of sticky packets that will inevitably appear in TCP communication, because TCP is a streaming communication method, it is impossible to distinguish a complete message, and the distinction between messages must be increased, so the number 0 is added, similar to the \r\n of HTTP messages to distinguish http messages. There are currently two types of message types, one is a data message, and the other is a keep-alive message. The keep-alive message only needs 4 bytes.
[0027] 3. Libuv high-performance forwarding program design Listen to two ports separately, such as Figure 4 As shown, port 8899 monitors the data of LoRa gateway, and port 8866 monitors the data of third-party access. The process is as follows: The data from port 8899 is directly forwarded to port 8866, thus achieving data forwarding. Figure 5 Initialize the program and listen to ports 8899 and 8866 respectively. libuv is an asynchronous network communication framework. When there is a TCP connection or TCP data comes in, an event will be triggered in the main thread. The TCP long connection will be processed in the TCP connection callback, and the data reception and forwarding will be processed in the data callback.
[0028] 4. The logic of Lora gateway and data forwarding will have the following problems in actual applications. The data of a certain customer's gateway can only be forwarded to the corresponding customer's APP. The third party is not expected to see the data. This problem is the ownership of the data. Therefore, the concept of account is used in the actual project. Each gateway and each third-party APP is marked with account attributes, so that data can only be forwarded between the same accounts. All gateways in the program are connected in series using a bidirectional linked list structure in C language. The third-party APP corresponding to each gateway is also connected in series with a linked list, and the third-party client is simultaneously mounted under the linked list head pointer of the gateway. The structural design of the gateway and APP is as follows: Figure 6 .
[0029] 5. External interfaces provided by Libubox, such as Figure 7 As shown, this interface can view which clients a gateway is currently connected to and how much data is forwarded.
[0030] The above are preferred embodiments of the present invention. Any changes made according to the technical solution of the present invention, as long as the resulting functions do not exceed the scope of the technical solution of the present invention, belong to the protection scope of the present invention.
Claims
1. A LoRa data forwarding server using libuv and libubox, characterized in that: The LoRa data forwarding server is developed using the C language network libraries libuv and libubox. Libuv is used as the network framework, the control interface uses the ubus interface provided by libubox, and the operating system platform is ubuntu or debian. A forwarding interface for LoRa terminal data is also provided.
2. A LoRa data forwarding server using libuv and libubox according to claim 1, characterized in that: The LoRa terminal communicates with the LoRa data forwarding server through a LoRa gateway.
3. A LoRa data forwarding server using libuv and libubox according to claim 1, characterized in that, The LoRa data forwarding server uses TCP communication to communicate with the LoRa gateway, that is, the data in JSON format is directly encapsulated in the TCP message. The communication format is: the first byte is the type code and command code, the second and third bytes are the check code, and the subsequent data is the string data in JSON format. The last byte is 0, and the message type uses a data message or a keep-alive message.
4. A LoRa data forwarding server using libuv and libubox according to claim 1, characterized in that: libuv listens to the data of LoRa gateway through port 8899 and the data accessed by third-party APP through port 8866. The data of LoRa gateway monitored by port 8899 is directly forwarded to port 8866 to realize data forwarding. Data reception and forwarding trigger an event in the main thread when TCP connection or TCP data comes in, handles TCP long connection in TCP connection callback, and handles data reception and forwarding in data callback.
5. A LoRa data forwarding server using libuv and libubox according to claim 4, characterized in that: LoRa gateways and third-party apps are marked with account attributes to enable data forwarding between the same accounts. All LoRa gateways in the program are connected in series using a bidirectional linked list structure in C language. The third-party apps corresponding to each LoRa gateway are connected in series using a linked list, and the client of the third-party app is simultaneously attached to the linked list head pointer of the corresponding LoRa gateway.
6. A LoRa data forwarding server using libuv and libubox according to claim 1, characterized in that: The forwarding interface of LoRa terminal data includes TCP interface, shell command interface, and web interface. The TCP interface uses json format.
