Power consumption constraint Internet of Things program automatic generation method and system based on large language model

By constructing a power consumption knowledge base and a closed-loop feedback optimization mechanism, the problem of lack of power consumption constraints in IoT code generation of large language models is solved, realizing the automatic generation of low-power code that meets the energy budget, and improving development efficiency and code reliability.

CN121704895APending Publication Date: 2026-03-20NANJING UNIV OF POSTS & TELECOMM
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202511515613.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-10-22
Publication Date
2026-03-20

AI Technical Summary

Technical Problem

Existing IoT code generation frameworks based on large language models lack the ability to perceive and guarantee power consumption constraints, resulting in generated code that cannot run under strict energy budgets and is difficult to apply to actual IoT products with stringent power consumption requirements.

Method used

A power consumption knowledge base is constructed and a closed-loop feedback optimization mechanism is introduced. Power consumption constraint parameters are extracted through semantic analysis, and low-power strategies are generated by combining a large language model. Static analysis and iterative optimization are then performed until the generated code meets the energy budget.

Benefits of technology

It enables automated conversion from natural language to verifiable energy-efficient code, lowering the development threshold for low-power IoT applications and improving the energy reliability and development efficiency of the code.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121704895A_ABST
    Figure CN121704895A_ABST
Patent Text Reader

Abstract

The invention discloses a power consumption constraint Internet of Things program automatic generation method and system based on a large language model. The method comprises the following steps: automatically analyzing key parameters such as battery capacity and target life from a natural language demand, and determining an energy budget; using a special knowledge base containing a hardware power consumption file and a low-power-consumption design mode to guide a large language model to generate an initial code deeply fused with energy-saving strategies such as deep sleep and batch transmission; and performing energy efficiency verification on the code through static power consumption estimation, and if the budget is not met, automatically generating a targeted optimization prompt and iteratively reconstructing the code until deployable firmware conforming to the energy budget is generated. According to the method, a power consumption knowledge base and a closed-loop feedback optimization mechanism are introduced into an automatic programming framework driven by a large language model, the semantic gap problem between natural language requirements and underlying hardware power consumption characteristics is solved, the energy consumption reliability of generated codes is effectively guaranteed, and the development threshold and period of low-power-consumption Internet of Things application are remarkably reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of low-power IoT application development and automated programming technology, specifically to a method and system for automatically generating power-constrained IoT programs based on a large language model. Background Technology

[0002] With the widespread adoption of the Internet of Things (IoT) technology, battery-powered embedded devices are increasingly used in environmental monitoring, smart agriculture, smart cities, and many other fields. These devices are typically deployed in scenarios where battery replacement is difficult or where energy harvesting is crucial. Therefore, the core challenge in their software design lies in achieving predetermined long-term operational goals (e.g., continuous operation for several years) within an extremely limited energy budget. Even subtle differences in energy consumption can lead to vastly different product lifespans, making power consumption a critical performance indicator determining success or failure.

[0003] Currently, software development for these power-constrained IoT devices heavily relies on engineers manually optimizing for low power consumption. Developers must have a deep understanding of the underlying hardware's power consumption characteristics and meticulously configure dynamic power management strategies, such as adjusting processor sleep and wake-up cycles, peripheral on / off states, and wireless communication frequencies and protocols. This process is not only tedious and time-consuming but also highly dependent on in-depth knowledge of specific hardware platforms, resulting in long development cycles, low efficiency, and a high risk of the final product failing to meet expected battery life requirements due to insufficient experience or inadequate debugging. This highly manual, workshop-style development model has become a major obstacle to the industry's large-scale development.

[0004] In recent years, Large Language Models (LLMs) have demonstrated powerful capabilities in code generation, automatically generating functional code based on natural language descriptions. Existing research has begun exploring the use of LLMs for end-to-end program synthesis in IoT applications. However, current LLM-based automated programming frameworks primarily focus on the functional correctness of the code, generally lacking awareness and constraint capabilities regarding power consumption, a crucial non-functional attribute. These models utilize massive amounts of general-purpose code data during training but do not embed detailed power consumption knowledge specific to the hardware platform (such as current consumption under different operating states and energy overhead during state transitions). Furthermore, they fail to translate high-level lifetime goals, such as "two years of operation," proposed by users into concrete, executable power budgets and low-level code optimization strategies (such as deep sleep and batch transmission) during the code generation phase. Therefore, while the generated code may be functionally correct, it cannot be guaranteed to operate under strict energy budgets, making it difficult to directly apply to real-world IoT products with stringent power consumption requirements. Essentially, this reflects a disconnect between functional correctness and energy reliability.

[0005] Therefore, a significant "semantic-to-hardware gap" exists in existing technologies: there is a lack of effective automated bridge between the high-level power consumption targets expressed by users in natural language and the low-level code implementations that are closely related to specific hardware required to achieve those targets. This forces developers into an inefficient cycle of manual trial and error and physical testing, becoming a bottleneck restricting the rapid development of low-power IoT applications. The industry urgently needs an intelligent development tool that can automatically understand power consumption constraints and generate and verify energy efficiency code accordingly. Summary of the Invention

[0006] Purpose of the invention: In order to overcome the problem that the IoT code generated by LLM in the prior art lacks power constraint awareness and guarantee capabilities, the present invention provides a method and system for automatically generating power-constrained IoT programs based on a large language model, which is used to automatically convert natural language requirements into deployable low-power IoT firmware that meets strict energy budgets.

[0007] To achieve the above-mentioned objectives, the technical solution of the present invention is as follows: Firstly, a method for automatically generating power-constrained IoT programs based on a large language model includes the following steps:

[0008] 1) Receive IoT application requirements described in natural language and automatically extract key power consumption constraint parameters, including battery capacity, target operating life and task execution strategy, through semantic analysis; (2) Based on the key power consumption constraint parameters parsed in step (1), combined with the battery efficiency factor, calculate the average current budget of the device as the core quantitative target for code generation and optimization; (3) Access the pre-built power knowledge base, which contains hardware power profiles and low-power design patterns; construct highly contextualized prompt words based on the power knowledge base and the average current budget obtained in step (2), and drive the large language model to generate initial code that integrates low-power strategies such as deep sleep, periodic sampling, and batch communication. (4) Perform static analysis on the initial code, estimate its average power consumption over a complete cycle without using actual hardware, convert the average power consumption into average current and compare it with the average current budget calculated in step (2). (5) If the estimated average current exceeds the average current budget, the root cause of the power consumption exceeding the standard is analyzed, specific optimization prompts are generated and fed back to the large language model, triggering code regeneration; this generation-estimation-optimization loop iterates automatically until the generated code meets all power consumption constraints. (6) Once the code passes the power consumption verification, output the final low-power firmware code, detailed power consumption report and battery life prediction.

[0009] Secondly, a power-constrained IoT program automatic generation system based on a large language model includes: The power consumption requirement analysis module is used to receive IoT application requirements described in natural language and automatically extract key power consumption constraint parameters, including battery capacity, target operating life and task execution strategy, through semantic analysis. The energy budget calculation module is used to calculate the average current budget of the device based on the key power consumption constraint parameters parsed by the power consumption demand parsing module and the battery efficiency factor, which serves as the core quantitative target for code generation and optimization. The energy-aware code generation module accesses a pre-built power knowledge base containing hardware power profiles and low-power design patterns. Based on the power knowledge base and the average current budget derived from the energy budget calculation module, highly contextualized prompts are constructed to drive a large language model to generate initial code that incorporates low-power strategies such as deep sleep, periodic sampling, and batch communication. The static power consumption estimation module is used to perform static analysis on the initial code and estimate its average power consumption over a complete cycle without using actual hardware. The average power consumption is then converted into average current and compared with the average current budget calculated by the energy budget calculation module. The closed-loop feedback optimization module is used to analyze the root cause of power consumption exceeding the budget when the estimated average current exceeds the average current budget, generate specific optimization suggestions and feed them back to the large language model to trigger code regeneration; this generation-estimation-optimization loop iterates automatically until the generated code meets all power consumption constraints. The solution output module is used to output the final low-power firmware code, detailed energy consumption report and battery life prediction after the code passes power consumption verification.

[0010] Thirdly, the present invention also provides an electronic device, characterized in that it comprises: one or more processors; a memory; and one or more programs, wherein the one or more programs are stored in the memory and configured to be executed by the one or more processors, wherein when the programs are executed by the processors, they implement the steps of the power-constrained Internet of Things program automatic generation method based on a large language model as described in the first aspect.

[0011] Fourthly, the present invention also provides a computer-readable storage medium having a computer program stored thereon, wherein the computer program, when executed by a processor, implements the steps of the power-constrained Internet of Things program automatic generation method based on a large language model as described in the first aspect.

[0012] Fifthly, the present invention also provides a computer program product, including a computer program that, when executed by a processor, implements the steps of the power-constrained Internet of Things program automatic generation method based on a large language model as described in the first aspect.

[0013] Beneficial Effects: The power-constrained IoT program automatic generation method and system based on a large language model of the present invention, by constructing a power consumption knowledge base and introducing a closed-loop feedback optimization mechanism, combines the code generation capability of a large language model with the strict power consumption constraints of IoT devices for the first time, effectively bridging the gap between high-level semantic requirements and low-power implementation at the underlying level. The present invention realizes the automated conversion from natural language to verifiable energy-efficient code, significantly reducing the development threshold and cycle of low-power IoT applications and improving the energy consumption reliability of the code. The framework of the present invention is not limited to power consumption optimization, and its core method can be extended to constraint-driven code generation based on other non-functional attributes such as real-time performance and memory usage, demonstrating strong versatility and scalability. Attached Figure Description

[0014] Figure 1 This is a general workflow diagram of the GPowerT system described in this invention; Figure 2 This is a flowchart illustrating the process by which the power consumption demand analysis module parses natural language and calculates the energy budget in this invention. Figure 3 This is a schematic diagram illustrating the structure of the energy sensing code generation module in this invention and its interaction with the power consumption knowledge base; Figure 4 This is a schematic diagram of the "generation-estimation-feedback" iterative loop of the closed-loop feedback optimization module in this invention. Detailed Implementation

[0015] To make the objectives, technical solutions, and advantages of this invention clearer, the technical solutions of this invention will be clearly and completely described below in conjunction with specific embodiments and corresponding drawings. It should be understood that these embodiments are for illustrative purposes only and are not intended to limit the scope of this invention. After reading this invention, any modifications of this invention in various equivalent forms by those skilled in the art fall within the scope defined by the appended claims.

[0016] This invention proposes an automatic power-constrained IoT program generation system based on a large language model, referred to as GPowerT in this paper. The main core functions of this system include: parsing natural language requirements, extracting power constraints and calculating energy budgets; generating initial energy-sensing code based on a power knowledge base; and performing closed-loop optimization of the code through static estimation and feedback until the power budget is met.

[0017] Figure 1The overall workflow diagram of the GPowerT system is presented. This system bridges the gap between high-level semantic requirements and low-level hardware implementation by introducing a power consumption knowledge base and closed-loop optimization module into the traditional LLM code generation process. The system is built on the AutoIOT framework and uses large language models such as GPT-4 as the core engine for code generation.

[0018] Reference Figure 1 The GPowerT system includes: The power consumption requirement analysis module is used to receive IoT application requirements described in natural language and automatically extract key power consumption constraint parameters, including battery capacity, target operating life and task execution strategy, through semantic analysis. The energy budget calculation module is used to calculate the average current budget of the device based on the key power consumption constraint parameters parsed by the power consumption demand parsing module and the battery efficiency factor, which serves as the core quantitative target for code generation and optimization. The energy-aware code generation module accesses a pre-built power knowledge base containing hardware power profiles and low-power design patterns. Based on the power knowledge base and the average current budget derived from the energy budget calculation module, highly contextualized prompts are constructed to drive a large language model to generate initial code that incorporates low-power strategies such as deep sleep, periodic sampling, and batch communication. The static power consumption estimation module is used to perform static analysis on the initial code and estimate its average power consumption over a complete cycle without using actual hardware. The average power consumption is then converted into average current and compared with the average current budget calculated by the energy budget calculation module. The closed-loop feedback optimization module is used to analyze the root cause of power consumption exceeding the budget when the estimated average current exceeds the average current budget, generate specific optimization suggestions and feed them back to the large language model to trigger code regeneration; this generation-estimation-optimization loop iterates automatically until the generated code meets all power consumption constraints. The solution output module is used to output the final low-power firmware code, detailed energy consumption report and battery life prediction after the code passes power consumption verification.

[0019] Accordingly, based on the GPowerT system, a method for automatically generating power-constrained IoT programs based on a large language model includes the following steps: S1. Receive IoT application requirements described in natural language, and automatically extract key power consumption constraint parameters, including battery capacity, target operating life and task execution strategy, through semantic analysis. S2. Based on the key power consumption constraint parameters parsed in step S1, and combined with the battery efficiency factor, calculate the average current budget of the device as the core quantitative target for code generation and optimization. S3. Access a pre-built power knowledge base containing hardware power profiles and low-power design patterns; based on the power knowledge base and the average current budget obtained in step S2, construct highly contextualized prompt words to drive a large language model to generate initial code that incorporates low-power strategies such as deep sleep, periodic sampling, and batch communication. S4. Perform static analysis on the initial code to estimate its average power consumption over a complete cycle without using actual hardware. Convert the average power consumption into average current and compare it with the average current budget calculated in step S2. S5. If the estimated average current exceeds the average current budget, analyze the root cause of the power consumption exceeding the limit, generate specific optimization suggestions and feed them back to the large language model to trigger code regeneration; this generation-estimation-optimization loop iterates automatically until the generated code meets all power consumption constraints. S6. Once the code passes power consumption verification, the final low-power firmware code, detailed energy consumption report, and battery life prediction will be output.

[0020] It should be understood that the GPowerT system in this embodiment of the invention can implement all the technical solutions in the automatic generation method of power-constrained IoT programs based on large language models. The functions of each functional module of the system and the steps of the method are in a one-to-one correspondence. For the sake of convenience, the specific implementation process is described below from the perspective of the method. Each step of the method is executed by the corresponding module in the system or completed by the corresponding module.

[0021] The method of the present invention performs power consumption requirement analysis in step S1. In one embodiment, referring to... Figure 2 Developers interact with the system using natural language to define their IoT application requirements, which include functional and power consumption needs. For example: "Design a sensor node using a 3000mAh battery, measuring soil moisture every 30 minutes, transmitting data twice daily via LoRaWAN, with a target lifespan of 2 years." GPowerT's requirement parser (power consumption requirement parsing module) performs semantic analysis on this description, automatically extracting key parameters such as battery capacity. Target service life And the operation vector (O = {sensing interval: 30 minutes, number of transmissions: 2 times / day}).

[0022] Optionally, if the IoT application requirements include user-declared energy-saving preferences, such as "prefer Bluetooth Low Energy mode," then the energy-saving preferences can also be extracted from the application requirements and represented as... Based on these extracted key power consumption constraint parameters, a power demand tuple is defined. ,in, It's the battery capacity. It is the target operating life. It is an operation vector. Specify any energy-saving preferences. Battery capacity. and target operating life Used to calculate the energy budget. Operation vector These time parameters quantitatively describe the periodic behavior of the application and are used in subsequent static power consumption estimations to calculate the duration of each state. The foundation. Specify any explicitly declared energy-saving preferences used to filter and prioritize specific low-power design patterns from the knowledge base during code generation. In this paper, operation vectors and energy-saving preferences are collectively referred to as task execution strategies.

[0023] The method of this invention performs current budget calculation in step S2. The calculation formula is as follows: ,in The average current budget is a direct quantification of energy consumption constraints. This is a coefficient representing battery efficiency that takes into account self-discharge and conversion losses; it is also referred to as the battery efficiency factor in this paper (typically taken as 0.6 to 0.9 to account for self-discharge and conversion losses). In this embodiment of the invention, a strict average current budget of approximately 171 µA is calculated. This budget is a core constraint that must be adhered to in all subsequent code generation and optimization activities.

[0024] After obtaining the quantized current budget, the code generation stage begins. The method of this invention performs energy-sensing code generation in step S3. This process is driven by a dedicated power consumption knowledge base. (Refer to...) Figure 3 This knowledge base It consists of three parts: It is an optional set of hardware components (such as STM32L0 microcontroller, SHT31 sensor, and E22 LoRa module). For detailed power consumption profiles, the typical current consumption and energy overhead of state switching for each component under different operating states (such as running, sleep, deep sleep, transmit, receive) are recorded. It supports a range of proven low-power design patterns, such as "deep sleep loop", "event-driven sampling", and "data bulk transfer".

[0025] The power consumption knowledge base has self-evolving capabilities, and can automatically retrieve and parse the technical manuals of newly released hardware through the network to update its hardware power consumption profile, ensuring the timeliness of system knowledge.

[0026] This invention utilizes information from a power consumption knowledge base, combined with power consumption constraints, to construct a highly contextualized prompt word, the structure of which is as follows: , Provides a code framework for the target platform (such as Arduino); From the knowledge base Search for low-power design patterns that match the hardware; Current budget Energy efficiency strategies are embedded as hard constraints in the cue words. These cue words submit functional requirements, hardware constraints (171 µA), and implementation strategies (such as "the main loop should maximize deep sleep time") to the LLM. The LLM then generates the initial code based on this cue. It incorporates low-power features from the ground up. For example, it actively sets the MCU (microcontroller) to the lowest power mode during task breaks and manages peripheral power, rather than using simple delays.

[0027] The energy-sensing code generation process of this invention can be represented by a formal model, which is expressed as a function. ,in For power demand tuples, For power consumption knowledge base, The prompting strategy defines how contextual information is injected into the prompt words, including the base code template, relevant hardware patterns obtained from the knowledge base, and the injection of power budget constraints.

[0028] The generated initial code will enter an automated verification and optimization loop. The method of this invention completes closed-loop feedback and iterative optimization in steps S4 and S5. (Refer to...) Figure 4 In step S4, the static power consumption estimation module first analyzes the code. This module parses the code, identifies different operating states of the system, and defines a set of operating states during code execution. , This indicates that the microcontroller is in an active execution state. This indicates that the microcontroller is in a low-power sleep state. This indicates that the wireless communication module is in data transmission mode. This indicates that the wireless communication module is in a data receiving or listening state. This indicates whether the sensor is in a sampling or measurement state. A weighted average power consumption is calculated by combining the power consumption value and duration of each state, and taking into account the energy cost of state transitions. Specifically, a knowledge-based power consumption is assigned to each state. Power consumption value ( ) and the duration derived from the code logic ( ).in Values ​​directly from the knowledge base The corresponding hardware file was found in the database. Estimation is made by analyzing delay functions (such as delay()), loop cycles, and interrupt service routine execution times in the code. Then, the formula is applied... Calculate the estimated average power consumption over the entire duty cycle, and then use the power formula... Given the system operating voltage (e.g., 3.3V) under the premise that, Converted to average current Compare this estimate with the budgeted value (171 µA).

[0029] If the estimated value exceeds the budgeted value, an optimization loop is triggered. In step S5, the closed-loop feedback optimization module analyzes the main reasons for the power consumption overrun (e.g., "The LoRa radio's activation time is too long, consuming 85% of the energy") and generates a specific, actionable optimization suggestion to feed back to the LLM, such as: "The current code exceeds the power budget. Please modify the communication strategy, use a lower transmit power, or package the data to reduce the number of daily transmissions." The LLM then regenerates the code based on this feedback. This "generate-estimate-feedback-regenerate" loop continues until the code meets all constraints.

[0030] In extreme cases, during the closed-loop feedback optimization process, if the system determines after multiple iterations that it cannot achieve the power consumption target under the given hardware and performance requirements, it will initiate a negotiation dialogue to provide the user with quantitative diagnostics (e.g., "To achieve a 2-year lifespan, the LoRa transmission interval must be greater than 4 hours") and suggest replacing with lower power hardware or relaxing performance requirements.

[0031] like If the code passes verification, in step S6, the solution output module outputs the final deployable firmware, energy consumption report, and lifetime prediction.

[0032] The closed-loop feedback optimization process of this invention can be formally described as an optimization problem, the objective of which is to adjust the sleep duration and sampling frequency parameter vector θ to achieve the estimated average power consumption. Minimize, and satisfy Constraints. Power budget. From current budget With system voltage The product is multiplied to ensure consistency with the core current constraint. The system automatically approximates the solution to the optimization problem through a feedback loop.

[0033] To verify the robustness of this system, different large language models (including GPT-4, Gemini, etc.) were used as the underlying engine for testing, and the results are shown in Table 1. Experimental results show that under different LLM drivers, the code generated by GPowerT can meet or exceed the preset battery life target. This proves that the effectiveness of this invention stems from its overall architecture and knowledge base, rather than relying on the characteristics of a specific LLM.

[0034] Table 1 Comparison of system lifetime performance under different large language models Large Language Model (LLM) Average lifespan (in hours) Lifespan range (hours) Has the target operating life (200 hours) been achieved? ChatGPT5Mini 988 235-1978 yes ChatGPT4 847 302-1857 yes Grok3 749 213-1365 yes Gemini 2.5 824 205-2430 yes Deepseek 905 208-2379 yes Target service life 200 --- benchmark

[0035] This invention combines the powerful generation capabilities of large language models with domain-specific power consumption knowledge and automated verification processes to provide an end-to-end automated solution for the development of power-constrained IoT applications. This method and system significantly reduce the trial-and-error costs and reliance on expert experience required in traditional manual development, reliably generating embedded software that is both functionally correct and meets strict energy budgets, greatly improving development efficiency and product reliability.

[0036] The present invention also provides an electronic device, comprising: one or more processors; a memory; and one or more programs, wherein the one or more programs are stored in the memory and configured to be executed by the one or more processors, wherein when the programs are executed by the processors, they implement the steps of the power-constrained IoT program automatic generation method based on a large language model as described above.

[0037] The present invention also provides a computer-readable storage medium having a computer program stored thereon, wherein the computer program, when executed by a processor, implements the steps of the power-constrained Internet of Things program automatic generation method based on a large language model as described above.

[0038] The present invention also provides a computer program product, including a computer program that, when executed by a processor, implements the steps of the power-constrained Internet of Things program automatic generation method based on a large language model as described above.

[0039] Those skilled in the art will understand that embodiments of the present invention can be provided as methods, apparatus (systems), electronic devices, or computer program products. Therefore, the present invention can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, the present invention can take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0040] This invention is described with reference to a flowchart of a method according to embodiments of the invention. It should be understood that each step in the flowchart and combinations thereof can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing device to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing device, generate instructions for implementing the process. Figure 1A device for performing a specified function in one or more processes. The processor involved in each embodiment may be a general-purpose processor, a central processing unit, a graphics processing unit, a digital signal processor, a programmable logic device, a quantum computing-based data processing logic device, an artificial intelligence processor, etc., and is not limited thereto.

[0041] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 The function specified in one or more processes.

[0042] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 Steps of a specified function in one or more processes.

Claims

1. A method for automatically generating power-constrained IoT programs based on a large language model, characterized in that, The method includes the following steps: (1) Receive IoT application requirements described in natural language and automatically extract key power consumption constraint parameters, including battery capacity, target operating life and task execution strategy, through semantic analysis; (2) Based on the key power consumption constraint parameters parsed in step (1), combined with the battery efficiency factor, calculate the average current budget of the device as the core quantitative target for code generation and optimization; (3) Access the pre-built power knowledge base, which contains hardware power profiles and low-power design patterns; construct highly contextualized prompt words based on the power knowledge base and the average current budget obtained in step (2), and drive the large language model to generate initial code that integrates low-power strategies such as deep sleep, periodic sampling, and batch communication. (4) Perform static analysis on the initial code, estimate its average power consumption over a complete cycle without using actual hardware, convert the average power consumption into average current and compare it with the average current budget calculated in step (2). (5) If the estimated average current exceeds the average current budget, the root cause of the power consumption exceeding the standard is analyzed, specific optimization prompts are generated and fed back to the large language model, triggering code regeneration; this generation-estimation-optimization loop iterates automatically until the generated code meets all power consumption constraints. (6) Once the code passes the power consumption verification, output the final low-power firmware code, detailed power consumption report and battery life prediction.

2. The method according to claim 1, characterized in that, In step (2), the formula for calculating the average current budget is: , in, It's the battery capacity. It is the target operating life. It is the battery efficiency factor.

3. The method according to claim 1, characterized in that, In step (3), the power consumption knowledge base is formalized as a triple. ,in: A collection of available hardware components; It serves as a power consumption archive, recording in detail the current consumption and energy expenditure of each hardware component under different operating states and state switching conditions. It is a low-power design pattern library that includes a series of proven software power-saving strategies.

4. The method according to claim 1, characterized in that, In step (3), the code generation process is formally represented as a function. ,in This is a power demand tuple, composed of key power consumption constraint parameters; A power consumption knowledge base; The prompting strategy defines how contextual information is injected into the prompt words, including the base code template, relevant hardware patterns obtained from the knowledge base, and the injection of current budget constraints.

5. The method according to claim 1, characterized in that, In step (5), the average power consumption is estimated using the following method: Define a set of operation states during code execution. , This indicates that the microcontroller is in an active execution state. This indicates that the microcontroller is in a low-power sleep state. This indicates that the wireless communication module is in data transmission mode. This indicates that the wireless communication module is in a data receiving or listening state. This indicates that the sensor is in a sampling or measurement state. To represent any state, we have state. Assigning known power consumption based on a power consumption knowledge base and duration derived from code analysis Through formula Calculate the average power consumption, where Energy overhead for state transitions.

6. The method according to claim 1, characterized in that, In step (5), the closed-loop feedback optimization process is constructed as an optimization problem, the goal of which is to adjust the sleep duration and sampling frequency parameter vector θ to make the estimated average power consumption... Minimize, and satisfy The constraints, including the power budget Budgeted from average current With system voltage By multiplying the results, the system automatically approximates the solution to the optimization problem through a feedback loop.

7. A power-constrained IoT program automatic generation system based on a large language model, characterized in that, The system includes: The power consumption requirement analysis module is used to receive IoT application requirements described in natural language and automatically extract key power consumption constraint parameters, including battery capacity, target operating life and task execution strategy, through semantic analysis. The energy budget calculation module is used to calculate the average current budget of the device based on the key power consumption constraint parameters parsed by the power consumption demand parsing module and the battery efficiency factor, which serves as the core quantitative target for code generation and optimization. The energy-aware code generation module accesses a pre-built power knowledge base containing hardware power profiles and low-power design patterns. Based on the power knowledge base and the average current budget derived from the energy budget calculation module, highly contextualized prompts are constructed to drive a large language model to generate initial code that incorporates low-power strategies such as deep sleep, periodic sampling, and batch communication. The static power consumption estimation module is used to perform static analysis on the initial code and estimate its average power consumption over a complete cycle without using actual hardware. The average power consumption is then converted into average current and compared with the average current budget calculated by the energy budget calculation module. The closed-loop feedback optimization module is used to analyze the root cause of power consumption exceeding the budget when the estimated average current exceeds the average current budget, generate specific optimization suggestions and feed them back to the large language model to trigger code regeneration; this generation-estimation-optimization loop iterates automatically until the generated code meets all power consumption constraints. The solution output module is used to output the final low-power firmware code, detailed energy consumption report and battery life prediction after the code passes power consumption verification.

8. An electronic device, characterized in that, include: One or more processors; Memory; And one or more programs, wherein the one or more programs are stored in the memory and configured to be executed by the one or more processors, wherein when the programs are executed by the processors, they implement the steps of the power-constrained IoT program automatic generation method based on a large language model as described in any one of claims 1-6.

9. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by the processor, it implements the steps of the automatic generation method for power-constrained IoT programs based on a large language model as described in any one of claims 1-6.

10. A computer program product, comprising a computer program, characterized in that, When the computer program is executed by the processor, it implements the steps of the automatic generation method for power-constrained Internet of Things programs based on a large language model as described in any one of claims 1 to 6.