Low-power-consumption Bluetooth information transmission method of electric energy meter
By designing the Bluetooth Low Energy protocol stack as a .NET assembly and using COM component registration and interface call, the compatibility and iteration problems of the Bluetooth Low Energy scheme of the power meter are solved, and efficient communication and simplified iteration of cross-language platforms are achieved.
Patent Information
- Application Number
- CN202510828872.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-06-20
- Publication Date
- 2025-08-15
AI Technical Summary
The existing low-power Bluetooth solution of power meter has compatibility problems when calling between different language platforms, and the entire application needs to be recompiled when it is iterated, resulting in inconvenience in development.
The Bluetooth low-power protocol stack is designed as a .NET assembly, and the type library file is generated through the COM interoperability tool, registered as a COM component, and the COM interface is called using the Pascal unit file to realize the low-power Bluetooth communication across language platforms, block the underlying logic, and only the functional modules that need to be modified are adjusted for iteration.
The Bluetooth version iteration process is simplified, the call efficiency of cross-language platforms is improved, compatibility issues are avoided, and the modular design and controllability of low-power Bluetooth communication is realized.
Smart Images

Figure CN120499635A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of electric energy meter data transmission, and in particular to a low-power Bluetooth information transmission method for an electric energy meter. Background Art
[0002] In existing Bluetooth low-power solutions for electricity meters, clients in different languages rely on specific third-party libraries or components when invoking Bluetooth communication. This not only makes information transmission cumbersome and inefficient, but can also lead to system compatibility issues. Furthermore, when Bluetooth protocol versions need to be updated, the entire application must be recompiled, causing significant inconvenience for developers. Summary of the Invention
[0003] The main purpose of the present invention is to provide a low-power Bluetooth information transmission method for an electric energy meter, aiming to solve the technical problems of low-power Bluetooth information transmission of an electric energy meter and the inconvenience of Bluetooth version iteration in related technologies.
[0004] To achieve the above object, the present invention provides a method for transmitting information via Bluetooth low energy for an electric energy meter, the method comprising the following steps:
[0005] S1, using the COM interoperability tool of Visual Studio, generating a type library file that complies with the COM specification based on a .NET assembly corresponding to Bluetooth Low Energy; the .NET assembly includes a functional module that implements the core functions of Bluetooth Low Energy;
[0006] S2, using the type library import tool to parse the type library file and generate a Pascal unit file that can be recognized by the target language based on the COM interface specification;
[0007] S3, register the .NET assembly as a COM component using the Regasm tool;
[0008] S4, calls the functional interface of the COM component through the Pascal unit file, and accesses the functional module of the corresponding functional interface in the .NET assembly to realize low-power Bluetooth information transmission.
[0009] The present invention designs the low-power Bluetooth protocol stack of the electric energy meter in the form of a .NET assembly to realize the modular design of the low-power Bluetooth communication function of the electric energy meter. On this basis, by registering the .NET assembly as a COM component, the low-power Bluetooth core function module in the .NET assembly is exposed as a COM interface, which makes it convenient for the user end to call the COM interface to access the low-power Bluetooth core function module through the Pascal unit file corresponding to the target language, thereby realizing the low-power Bluetooth communication of the electric energy meter. It can be seen that the present invention can shield the underlying logic of the low-power Bluetooth protocol stack, and complete Bluetooth communication only by calling the corresponding functional interface, thereby avoiding compatibility issues of different language platforms. Therefore, the present invention can realize cross-language platform calls of low-power Bluetooth more easily without relying on third-party components. In addition, when the Bluetooth version is iterated, adjustments can be made only to the functional modules that need to be modified, which greatly simplifies the iterative process. BRIEF DESCRIPTION OF THE DRAWINGS
[0010] Figure 1 This is a flow chart of a first embodiment of a method for transmitting information via Bluetooth low energy for an electric energy meter according to the present invention;
[0011] Figure 2 A schematic diagram of the GATT specification in the first embodiment of the low-power Bluetooth information transmission method for an electric energy meter of the present invention;
[0012] Figure 3 FIG2 is a flow chart of a second embodiment of a method for transmitting information via Bluetooth low energy for an electric energy meter according to the present invention.
[0013] The purpose, features and advantages of the present invention will be further described with reference to the accompanying drawings and in conjunction with the embodiments. DETAILED DESCRIPTION
[0014] It should be understood that the specific embodiments described herein are only used to explain the present invention and are not intended to limit the present invention.
[0015] The inventive concept of the present application is further described below with reference to some specific embodiments and implementation methods.
[0016] The embodiment of the present invention provides a method for transmitting information of electric energy meter via low power Bluetooth. Figure 1 , Figure 1 The figure is a flow chart of a first embodiment of a method for transmitting information via Bluetooth low energy for an electric energy meter according to the present invention.
[0017] In this embodiment, the low-power Bluetooth information transmission method of the electric energy meter includes the following steps:
[0018] Step S1: Generate a type library file that complies with the COM specification based on the .NET assembly corresponding to the low-power Bluetooth using the COM (Component Object Model) interoperability tool of Visual Studio; the .NET assembly includes a functional module that implements the core functions of the low-power Bluetooth.
[0019] Specifically, a .NET assembly is a managed library written in C# that encapsulates the core functionality of Bluetooth Low Energy (such as device discovery, GATT service reading and writing, and connection management). It contains managed types such as classes, interfaces, events, and delegates. However, COM cannot directly recognize it, and an interoperability tool must be used to generate a type library file that COM can understand.
[0020] In step S1, the Bluetooth low energy is designed in the form of a .NET assembly, which can realize the modular design of Bluetooth low energy communication and lay the foundation for the subsequent cross-language platform call of Bluetooth low energy.
[0021] Step S2: parse the type library file using a type library import tool, and generate a Pascal unit file recognizable by the target language based on the COM interface specification.
[0022] Among them, the type library file is the metadata carrier in the COM system. Its core function is to describe the interfaces, types, methods, constants and other information exposed by the COM component.
[0023] In step S2, by parsing the type library file and generating a Pascal unit file recognizable by the target language based on the COM interface specification, the metadata is converted into a code structure that can be directly used by the target language, ensuring that the target program can correctly call the functional interface of the COM component. This achieves efficient conversion of metadata to the target language, ensuring the correctness of cross-language calls and development efficiency.
[0024] Step S3: Register the .NET assembly as a COM component using the Regasm tool.
[0025] Regasm is a tool in the .NET Framework that is used to register a .NET assembly (usually a DLL file) in the Windows registry so that the COM interface can access the classes (also known as functional modules) in the .NET assembly.
[0026] Taking Delphi 7 as an example, run Regasm as an administrator. Specifically, open a command prompt, click the "Start" menu, search for "cmd," and then use the CD command to navigate to the directory where the Regasm.Exe file is located (you can also copy the Regasm.Exe file to the project path and use the CD command to navigate to the project directory). Execute the regasmXXX.dll command to register the XXX.dll file. If registration is successful, a message will appear indicating that the type has been successfully registered. If not, first check whether the Regasm.Exe file matches the operating system and try different versions of the Regasm tool.
[0027] In step S3, the Regasm tool is used to register the .NET assembly corresponding to the Bluetooth Low Energy as a COM component. This can expose the Bluetooth Low Energy core functional module in the .NET assembly as a COM interface. This is a necessary condition for the user end to access the Bluetooth Low Energy core module through the COM interface. It is also a key step in shielding the underlying logic of the Bluetooth Low Energy protocol stack.
[0028] Step S4: calling the functional interface of the COM component through the Pascal unit file, accessing the functional module of the corresponding functional interface in the .NET assembly, so as to realize the information transmission of the low-power Bluetooth.
[0029] The step S4 specifically includes the following steps:
[0030] Step S41: calling the device scanning interface, monitoring the broadcast information of surrounding devices, obtaining the unique identifiers and device information of surrounding devices from the broadcast information, and storing the device information.
[0031] Specifically, the two communicating parties in Bluetooth Low Energy are the host computer and the energy meter (also known as the peripheral device), with the host computer being the master and the energy meter being the slave. The slave sends the same broadcast message on channels 37, 38, and 39, sequentially, until all three channels have been sent. This process is called a broadcast event. The broadcast message includes the slave's unique identifier (MAC address) and device information. The time interval between two adjacent broadcast events is called the broadcast interval, which must be an integer multiple of 0.625ms. The broadcast interval ranges from 20ms to 10.24s. The longer the broadcast interval, the longer the communication connection time. The Bluetooth Low Energy link layer adds a random delay of 0-10ms between two broadcast events to ensure that broadcast collisions do not occur when multiple peripheral devices are broadcasting.
[0032] The host scans for broadcast information from slaves and obtains their unique identifiers. Scanning is divided into passive and active scanning. During passive scanning, the host monitors the broadcast channel and reports any broadcast information directly to the host. During active scanning, upon receiving a broadcast message, the host sends a scan request to the slave to obtain more information. After receiving the scan request, the slave sends a scan response packet.
[0033] Step S42: calling the connection management interface, pairing and connecting with surrounding devices based on the unique identifier, and storing pairing information and connected device information.
[0034] The pairing information may include a pairing preparation log and a pairing log, and the connection device information may include a service acquisition log, a feature acquisition log, and a subscription message log.
[0035] Specifically, the host first matches the known slave's MAC address with the MAC address of a slave in the device discovery list to complete pairing, and then authenticates the slave using a PIN. Next, the host and slave establish a GATT connection to ensure efficient and reliable data transmission between the devices. The host and slave then perform service discovery to determine each other's supported services and characteristics, and store the services, characteristics, and subscription messages locally.
[0036] like Figure 2 As shown in the figure, each Bluetooth slave may provide multiple services, and each service may contain multiple characteristics. A characteristic consists of a value and 0 to multiple descriptors. Bluetooth communication is mainly carried out by reading and writing the value of the characteristic.
[0037] Step S43: calling the information transmission interface, sending instructions to the connected peripheral devices, causing the peripheral devices to perform corresponding processing according to the instructions, and return the processing results and store the transmission information.
[0038] The transmission information may include a data transmission log.
[0039] Specifically, after a GATT connection is established, data is transmitted between the host and slave. The host controls the communication process, while the slave passively receives and responds. In other words, the host sends commands such as read, write, and subscribe to the slave, and the slave processes the commands accordingly and returns the results to the host.
[0040] When the Bluetooth protocol version needs to be iterated, you only need to recompile the module that needs to be modified to complete the version iteration.
[0041] In step S4, by calling different interfaces and accessing the corresponding functional modules, the corresponding low-power Bluetooth functions can be implemented, greatly improving the efficiency of calling low-power Bluetooth across language platforms. In addition, the information during each interface call process is stored, making the information during the communication process transparent, controllable, and traceable.
[0042] After step S43, the method further includes:
[0043] Step S44: collecting the reception time and data volume of each data packet during the information transmission process of the electric energy meter.
[0044] Step S45: Calculate the total data volume within a fixed time window based on the receiving time and data volume.
[0045] Step S46: Calculate the transmission rate based on the total data volume and the fixed time window.
[0046] Step S47: calling a chart drawing interface, drawing a dynamic chart based on the transmission rate and displaying it on the user interface, thereby realizing visualization of the data transmission rate and facilitating the user to intuitively monitor the communication rate.
[0047] In this embodiment, the low-power Bluetooth protocol stack of the electric energy meter is designed in the form of a .NET assembly to realize the modular design of the low-power Bluetooth communication function of the electric energy meter. On this basis, by registering the .NET assembly as a COM component, the low-power Bluetooth core function module in the .NET assembly is exposed as a COM interface, which makes it convenient for the user end to call the COM interface to access the low-power Bluetooth core function module through the Pascal unit file corresponding to the target language, thereby realizing the low-power Bluetooth communication of the electric energy meter. It can be seen that the present invention can shield the underlying logic of the low-power Bluetooth protocol stack, and complete Bluetooth communication only by calling the corresponding functional interface, thereby avoiding compatibility issues of different language platforms. Therefore, the present invention can realize cross-language platform calls of low-power Bluetooth more easily without relying on third-party components. In addition, when the Bluetooth version is iterated, adjustments can be made only for the functional modules that need to be modified, which greatly simplifies the iterative process.
[0048] Further, such as Figure 3 As shown, a second embodiment is proposed based on the first embodiment.
[0049] In this embodiment, the connection parameters of Bluetooth low energy include connection interval, slave delay, and monitoring timeout.
[0050] Connection interval: Bluetooth low energy devices connect using frequency modulation, sending and receiving data on a specific channel. The interval between switching between channels is called the connection interval. The connection interval is measured in 1.25ms increments and ranges from 7.5ms to 4s. If no data is exchanged between the two devices, link layer data (empty packets) will still be exchanged to maintain the connection.
[0051] Slave Delay: When a slave has no data to send, it can skip a certain number of connection events and does not need to reply to the master's data packets to save power. The setting range of slave delay is 0-499ms.
[0052] Monitoring timeout: If no communication occurs within the monitoring timeout period, the Bluetooth Low Energy connection will be automatically disconnected. The monitoring timeout period can be configured from 100ms to 32s.
[0053] After step S4, the method further includes:
[0054] Step S5: Establish a communication power consumption model based on the connection interval, slave delay, and monitoring timeout:
[0055] L = CI * 1.25 * (SL + 1);
[0056] Where P represents actual power consumption; CI represents the connection interval; SL represents the slave delay; ST represents the monitoring timeout; P1 represents the active state power consumption; P2 represents the sleep state power consumption; T1 represents the activation time of each connection event; and L represents the actual delay.
[0057] Step S6: Calculate the data transmission rate based on the number of data packets and the effective data load of each data packet:
[0058]
[0059] Where N1 represents the number of packets successfully transmitted per event; D1 represents the effective data load of a single packet; and R represents the data transmission rate.
[0060] Step S7: Based on the communication power consumption model, data transmission rate and parameter constraints, with the goal of balancing the lowest efficiency, the connection interval, slave delay and monitoring timeout are continuously updated through the gradient descent algorithm to achieve a balance between communication efficiency and communication power consumption.
[0061] The step S7 specifically includes the following steps:
[0062] Step S71: Establish parameter constraints based on the Bluetooth low energy communication protocol requirements:
[0063] 7.5ms≤CI≤4s;
[0064]
[0065] 100ms≤ST≤3200ms;
[0066] ST≥(2*CI*(SL+1)) / 10;
[0067] Among them, L max Indicates the maximum delay.
[0068] Step S72: Based on the power consumption weight, efficiency weight, delay weight, data transmission rate, data request rate, and communication power consumption model, with the goal of balancing the lowest efficiency, establish an objective function:
[0069]
[0070] Among them, α represents the power consumption weight; β represents the efficiency weight; γ represents the delay weight; R1 represents the data request rate (calculated based on the data packets used for successful and failed transmissions); J represents the balance efficiency. The lower the balance efficiency, the better the balance between communication efficiency and communication power consumption.
[0071] It is worth mentioning that the power consumption weight, efficiency weight, and delay weight in this embodiment can be obtained by collecting and analyzing the real-time transmission rate and real-time power consumption data during the communication process under the first embodiment. Then, the weights are adjusted according to the focus of different operating modes. For example, in low-power mode, it is necessary to focus on increasing the power consumption weight; in high-performance mode, it is necessary to focus on increasing the efficiency weight. Among them, the sum of the power consumption weight, efficiency weight, and delay weight is always 1.
[0072] Step S73: Based on the parameter constraints and the objective function, update the connection interval, slave delay, and monitoring timeout using a gradient descent algorithm:
[0073]
[0074] Where CI1 represents the updated connection interval; SL1 represents the updated slave delay; SL1 represents the updated monitoring timeout; and η represents the learning rate.
[0075] In this embodiment, a communication power consumption model is established based on the connection interval, slave delay, and monitoring timeout. This model accurately reflects the impact of these factors on communication power consumption during Bluetooth communication. Based on this, a gradient descent optimization algorithm is used to update these factors, aiming for the lowest balanced efficiency. This algorithm can then determine the optimal connection interval, slave delay, and monitoring timeout for different operating modes, thereby achieving a balance between communication efficiency and power consumption, significantly improving the energy efficiency of low-power Bluetooth communication in electricity meters.
[0076] The serial numbers of the above embodiments of the present invention are for description only and do not represent the advantages or disadvantages of the embodiments.
[0077] The above are only preferred embodiments of the present invention and are not intended to limit the patent scope of the present invention. Any equivalent structure or equivalent process transformation made using the contents of the present invention description and drawings, or directly or indirectly applied in other related technical fields, are also included in the patent protection scope of the present invention.
Claims
1. A method for transmitting information via low-power Bluetooth for an electric energy meter, characterized in that: The method comprises the following steps: S1, using the COM interoperability tool of Visual Studio, generating a type library file that complies with the COM specification based on a .NET assembly corresponding to Bluetooth Low Energy; the .NET assembly includes a functional module that implements the core functions of Bluetooth Low Energy; S2, using the type library import tool to parse the type library file and generate a Pascal unit file that can be recognized by the target language based on the COM interface specification; S3, register the .NET assembly as a COM component using the Regasm tool; S4, calls the functional interface of the COM component through the Pascal unit file, and accesses the functional module of the corresponding functional interface in the .NET assembly to realize low-power Bluetooth information transmission.
2. The method for transmitting information via Bluetooth low energy for an electric energy meter according to claim 1, wherein: The functional interface includes a device scanning interface, a connection management interface, and an information transmission interface. The S4 specifically includes: S41, calling the device scanning interface, monitoring the broadcast information of surrounding devices, obtaining the unique identifiers and device information of surrounding devices from the broadcast information, and storing the device information; S42, calling the connection management interface, pairing and connecting with surrounding devices based on the unique identifier, and storing pairing information and connected device information; S43, calling the information transmission interface, sending instructions to the connected peripheral devices, causing the peripheral devices to perform corresponding processing according to the instructions, and return the processing results and store the transmission information.
3. The low-power Bluetooth information transmission method for an electric energy meter according to claim 2, characterized in that: The functional interface further includes a chart drawing interface. After S43, the method further includes: S44, collecting the reception time and data volume of each data packet during the information transmission process of the electric energy meter; S45, calculating the total data volume within a fixed time window based on the reception time and data volume; S46, calculating a transmission rate based on the total data volume and the fixed time window; S47, calling a chart drawing interface, drawing a dynamic chart based on the transmission rate and displaying it on the user interface.
4. The method for transmitting information via Bluetooth low energy for an electric energy meter according to claim 2, wherein: After S4, the method further includes: S5, establishes a communication power consumption model based on connection interval, slave delay, and monitoring timeout: L=CI*1.25*(SL+1); Where P represents actual power consumption; CI represents connection interval; SL represents slave delay; ST represents monitoring timeout; P1 represents active state power consumption; P2 represents sleep state power consumption; T1 represents activation time of each connection event; L represents actual delay; S6, calculates the data transmission rate based on the number of packets and the effective data load of a single packet: Where N1 represents the number of packets successfully transmitted per event; D1 represents the effective data load of a single packet; R represents the data transmission rate; S7, based on the communication power consumption model, data transmission rate and parameter constraints, takes the lowest balance efficiency as the goal, and continuously updates the connection interval, slave delay and monitoring timeout through the gradient descent algorithm to achieve a balance between communication efficiency and communication power consumption.
5. The method for transmitting information via Bluetooth low energy for an electric energy meter according to claim 4, wherein: The S7 specifically includes: S71, establishing parameter constraints based on the Bluetooth low energy communication protocol requirements; S72, based on the power consumption weight, efficiency weight, delay weight, data transmission rate, data request rate, and communication power consumption model, with the goal of balancing the lowest efficiency, establish an objective function: Where α represents the power consumption weight; β represents the efficiency weight; γ represents the delay weight; R1 represents the data request rate (calculated based on the number of data packets used for successful and failed transmissions); J represents the balance efficiency; S73, based on the parameter constraints and the objective function, updates the connection interval, slave delay, and monitoring timeout using a gradient descent algorithm: Where CI1 represents the updated connection interval; SL1 represents the updated slave delay; ST1 represents the updated monitoring timeout; and η represents the learning rate.
Citation Information
Patent Citations
Low-power-consumption Bluetooth transmission rate testing method
CN107172639A
Method and device for calibrating electric energy meter based on low-power-consumption Bluetooth communication
CN111028495A
