CN-122028249-A - Intelligent street lamp control method and system based on LoRa and ModBus
Abstract
The invention relates to the technical field of industrial process control, in particular to an intelligent street lamp control method and system based on LoRa and ModBus, wherein the method comprises the steps that an STM32 main controller sends a ModBus query frame through a UART interface to obtain sensor data; the method comprises the steps of packaging sensor data into a LoRa uplink data frame and sending the LoRa uplink data frame to a LoRa communication module through an SPI interface, receiving a LoRa downlink instruction frame from a LoRa gateway, analyzing the instruction frame and executing local control logic, wherein the method comprises the steps of calculating PWM output values according to illumination sensor data so as to adjust the brightness of an LED lamp. The system comprises an STM32 lamp control board, a LoRa gateway, a cloud platform and a sensor. The intelligent street lamp control system realizes a highly integrated hardware architecture, double-layer protocol fusion and edge intelligent control, and improves compatibility, expansibility and reliability of the intelligent street lamp control system.
Inventors
- XU XIANSHENG
- ZANG YANHUI
- Zheng Jiashuo
- LIANG JINYI
- Lei Guobao
- LUO JIADONG
Assignees
- 佛山职业技术学院
Dates
- Publication Date
- 20260512
- Application Date
- 20260209
Claims (10)
- 1. The intelligent street lamp control method based on LoRa and ModBus is characterized by comprising the following steps of: S100, an STM32 main controller sends a query frame conforming to a ModBus-RTU protocol to an RS485 bus through a UART interface, receives a response frame returned by a sensor, and analyzes the response frame after CRC check to obtain sensor data; s200, packaging sensor data into a LoRa uplink data frame containing a frame head, a local address, a data load and a frame tail, transmitting the LoRa uplink data frame to a LoRa communication module through an SPI interface, converting the LoRa uplink data frame into a LoRa wireless signal, and transmitting the LoRa wireless signal to a LoRa gateway; S300, receiving a LoRa wireless signal from the LoRa gateway through a LoRa communication module and converting the LoRa wireless signal into a LoRa downlink instruction frame containing a command word, a target address and control parameters; s400, analyzing the LoRa downlink instruction frame to obtain a command word and control parameters, determining a target mode according to the control parameters when the command word indicates the light mode to switch, sending a ModBus query frame to an illumination sensor to obtain a real-time illumination intensity value, calculating a PWM output value according to the real-time illumination intensity value, and outputting the PWM output value to a light driving circuit to adjust the brightness of the LED lamp.
- 2. The method of claim 1, wherein in S100, the STM32 main controller sends a query frame conforming to a ModBus-RTU protocol to the RS485 bus through a UART interface, receives a response frame returned by the sensor, and parses the response frame after CRC check to obtain sensor data, including: s110, the STM32 main controller generates a ModBus query frame comprising a sensor address, a function code, a starting register address, the number of registers and a CRC check code, wherein the ModBus query frame conforms to a ModBus-RTU protocol format; s120, the STM32 main controller sends the ModBus query frame to an RS485 bus through a UART interface; s130, the sensor receives the ModBus query frame and returns a ModBus response frame containing a sensor address, a function code, a data byte number, a data load and a CRC check code; S140, the STM32 main controller receives the ModBus response frame and performs CRC check; And S150, after the verification is passed, the STM32 main controller extracts the sensor data from the data load field of the ModBus response frame.
- 3. The method according to claim 1, wherein in S200, the encapsulating the sensor data into a LoRa uplink data frame including a frame header, a local address, a data payload and a frame tail, transmitting the LoRa uplink data frame to a LoRa communication module through an SPI interface, converting the LoRa uplink data frame into a LoRa wireless signal, and transmitting the LoRa wireless signal to a LoRa gateway, includes: S210, the STM32 main controller encapsulates the sensor data into a LoRa uplink data frame, wherein a frame header of the LoRa uplink data frame identifies a frame starting position, a local address field identifies a unique address of a sending node, a data load field carries the sensor data, and a frame tail identifies a frame ending position; s220, the STM32 main controller sends the LoRa uplink data frame to a LoRa communication module through an SPI interface; s230, the LoRa communication module converts the LoRa uplink data frame into a LoRa wireless signal; S240, the LoRa communication module sends the LoRa wireless signal to a LoRa gateway.
- 4. The method of claim 1, wherein in S300, the step of receiving, by the LoRa communication module, the LoRa wireless signal from the LoRa gateway and converting the received LoRa wireless signal into a LoRa downlink command frame including a command word, a destination address, and a control parameter, comprises: S310, the STM32 main controller receives the LoRa wireless signal from the LoRa gateway through the LoRa communication module; S320, the LoRa communication module converts the received LoRa wireless signal into a LoRa downlink instruction frame; S330, the LoRa communication module transmits the LoRa downlink instruction frame to the STM32 main controller through the SPI interface, wherein the LoRa downlink instruction frame comprises a command word, a target address and control parameters, the command word is used for distinguishing instruction types, the target address field is used for designating a node for receiving an instruction, and the control parameter field is used for transmitting specific control instruction contents.
- 5. The method according to claim 1, wherein in S400, the sending a ModBus query frame to the illumination sensor to obtain a real-time illumination intensity value, calculating a PWM output value according to the real-time illumination intensity value, and outputting the PWM output value to the light driving circuit to adjust the brightness of the LED lamp includes: S410, the STM32 main controller sends the ModBus query frame to an illumination sensor through the UART interface; s420, returning the ModBus response frame containing the real-time illumination intensity value by the illumination sensor, and receiving and analyzing the ModBus response frame by the STM32 main controller to obtain the real-time illumination intensity value; S430, dividing the real-time illumination intensity value by a pre-stored maximum illumination intensity value by the STM32 main controller to normalize the illumination intensity value; s440, the STM32 main controller calculates the difference value between the 1 and the normalized illumination intensity value to obtain a reverse illumination intensity value; S450, the STM32 main controller multiplies the reverse illumination intensity value by 1000 to obtain the PWM output value; s460, the STM32 main controller outputs the PWM output value to the light driving circuit, and the light driving circuit adjusts the brightness of the LED lamp according to the PWM output value.
- 6. The method according to claim 1, wherein the method further comprises: when the command word indicates direct control, the STM32 main controller directly generates the PWM output value according to the control parameter and outputs the PWM output value to the lamplight driving circuit so as to adjust the brightness of the LED lamp.
- 7. The method according to claim 1, wherein the method further comprises: The STM32 main controller periodically performs S100 to S200 to report the sensor data to the LoRa gateway at regular time.
- 8. Intelligent street lamp control system based on loRa and ModBus, characterized in that, the system includes: STM32 lamp accuse board, STM32 lamp accuse board includes STM32 main control unit, loRa communication module, sensor interface circuit and light drive circuit, STM32 main control unit pass through the SPI interface with LoRa communication module is connected, STM32 main control unit pass through the UART interface with sensor interface circuit connects, STM32 main control unit pass through PWM output pin and GPIO pin with light drive circuit connects; the LoRa gateway is communicated with the STM32 lamp control board through LoRa wireless signals; The cloud platform is connected with the LoRa gateway through a network; The sensor is connected with the sensor interface circuit through an RS485 bus, and the sensor conforms to a ModBus-RTU protocol; Wherein the STM32 host controller performs a method as claimed in any one of claims 1 to 7.
- 9. The system of claim 8, wherein the sensor interface circuit includes an RS485 conversion chip that converts UART signals of the STM32 host controller to RS485 differential signals.
- 10. The system of claim 8, wherein the light driving circuit comprises a PWM driving unit and a switch control unit, the PWM driving unit receives a PWM signal output by the STM32 main controller to adjust LED lamp brightness, and the switch control unit receives a GPIO signal output by the STM32 main controller to control LED lamp switching.
Description
Intelligent street lamp control method and system based on LoRa and ModBus Technical Field The invention relates to the technical field of communication of the Internet of things, in particular to a control method and a system of intelligent street lamps based on LoRa and ModBus. Background With the continuous development of smart cities and internet of things, intelligent management of urban public infrastructure has become a necessary trend. As one of the most widely distributed and highest density municipal facilities in cities, intelligent modification of traditional street lamps is an important component for constructing smart cities. The intelligent street lamp is not only a single lighting tool, but is upgraded to an internet of things node integrating functions of intelligent lighting management, environment information acquisition, fault automatic monitoring and the like. Under the background, the energy consumption management, the operation and maintenance efficiency and the diversification of functions of the road lamp are required to be higher. At present, the problem of pain faced by the traditional street lamp industry is how to furthest reduce the energy consumption and operation and maintenance cost generated by a huge street lamp system on the premise of ensuring public safety and illumination quality, and enable the street lamp system to meet the application requirements of diversification of smart cities. The prior art mainly comprises three types, namely a timing dimming scheme, a fixed time table is preset in a main control board of the street lamp, and a controller automatically executes a switch and a dimming instruction according to an internal clock. The second type is a single photosensor dimming scheme, which controls the street lamp switch by detecting the ambient illuminance in real time, but lacks fine light adjustment capability. The third type is a traditional wired or short-distance wireless lamp control scheme, wherein the wired scheme such as DALI and KNX requires complex wiring, the construction cost is high, the short-distance wireless scheme such as ZigBee and Bluetooth Mesh omits wiring, but the single-hop transmission distance is short, a large number of relay nodes are required to be deployed in the scene of wide and large number of street lamps, and the cost and the network complexity are increased. The technical problems of high hardware redundancy, non-uniform communication protocol, complex system integration, poor expansibility and the like exist in the scheme, and the requirements of an intelligent street lamp system on standardization, low power consumption, long-distance communication and intelligent edge control are difficult to meet. Disclosure of Invention The embodiment of the invention provides a control method and a control system for intelligent street lamps based on LoRa and ModBus, which aim to solve the technical problems of high hardware integration complexity, non-uniform communication protocol, poor system expansibility and low reliability caused by centralized control logic in the existing intelligent street lamp control system. In a first aspect, an embodiment of the present invention provides a method for controlling an intelligent street lamp based on LoRa and ModBus, the method including the following steps: S100, an STM32 main controller sends a query frame conforming to a ModBus-RTU protocol to an RS485 bus through a UART interface, receives a response frame returned by a sensor, and analyzes the response frame after CRC check to obtain sensor data; s200, packaging sensor data into a LoRa uplink data frame containing a frame head, a local address, a data load and a frame tail, transmitting the LoRa uplink data frame to a LoRa communication module through an SPI interface, converting the LoRa uplink data frame into a LoRa wireless signal, and transmitting the LoRa wireless signal to a LoRa gateway; S300, receiving a LoRa wireless signal from the LoRa gateway through a LoRa communication module and converting the LoRa wireless signal into a LoRa downlink instruction frame containing a command word, a target address and control parameters; S400, analyzing the LoRa downlink instruction frame to obtain a command word and control parameters, determining a target mode according to the control parameters when the command word indicates the light mode to switch, and executing local control logic, namely sending a ModBus query frame to an illumination sensor to obtain a real-time illumination intensity value, calculating a PWM output value according to the real-time illumination intensity value, and outputting the PWM output value to a light driving circuit to adjust the brightness of an LED lamp. Optionally, in S100, the STM32 main controller sends a query frame conforming to a ModBus-RTU protocol to an RS485 bus through a UART interface, receives a response frame returned by a sensor, and parses the response frame after CRC check to obtain sensor