PPAASS: Practical Power-Aware Duty Cycle Algorithm for Solar Energy Harvesting Sensors

Energy-harvesting sensor networks promise unlimited operation throughout time, benefiting ongoing monitoring applications. However, most energy sources, such as sunlight, vary over time and do not guarantee constant power delivery to a device. In addition, these devices lack a battery with the necessary capacity to store enough energy to operate when harvesting is impossible. Thus, managing energy consumption becomes essential for any device to function correctly. This article proposes PPAASS (Practical Power-Aware Algorithm for Solar Sensors), a novel algorithm that allows devices to change their duty cycle to maximize the use of harvested energy based on the device’s battery backup level and solar irradiance predictions. The algorithm was evaluated through simulations performed in Python and with different solar irradiance conditions depending on the season of the year. PPAASS shows a higher average duty cycle than other algorithms in the literature while maintaining a few changes in the duty cycle, which makes it ideal for constant monitoring applications. Furthermore, the implementation of the algorithm shows that the real-time duty cycle adaptation allows a device to react quickly to energy harvesting prediction failures and take full advantage of all the harvested energy. Our experimental results showed that PPAASS provided devices with power availability at all times while reducing to a maximum of 15% the time the system did not harvest all the solar energy because the battery was full.


I. INTRODUCTION
In recent years, the use of low-cost wireless detection, monitoring, and communication devices has been on the rise, constituting what is known as wireless sensor networks (WSN). This technology has been used to develop various applications, including seismic, acoustic, chemical, home security, habitat monitoring, forecasting, and industrial systems. Although these networks base their versatility on the devices' small size, they inherit the problem of limited energy storage The associate editor coordinating the review of this manuscript and approving it for publication was Hongwei Du. capacity. Nonetheless, network devices should work for long periods without frequently recharging. [1].
Depending on the sensor's characteristics, the batteries might last years or only a few days. In some cases, it is hard or even impossible for some applications to replace batteries. For this reason, many studies have sought to develop protocols that increase WSN device lifetime. The techniques used in those protocols include routing and scheduling, data processing, adaptive duty cycles, and other techniques that are found in [2]. Recently, energy harvesting has become an alternative solution to the problem of supplying energy to such devices, as it virtually eliminates the need to replace batteries. VOLUME 10, 2022 This work is licensed under a Creative Commons Attribution 4.0 License. For more information, see https://creativecommons.org/licenses/by/4.0/ Instead, the batteries recharge by harvesting energy from their environment. Theoretically, this means that devices might keep up with their energy needs for an unlimited time [3]. Some harvesting sources include piezoelectric, RF, wind, and solar energy. Solar energy has gained special attention due to its low cost and ease of implementation. Solar cells that convert solar energy into electricity are cheap and easy to purchase. It is possible to find solar cells in many sizes, from a few centimeters to a few meters. There is a direct relationship between solar cell size and the cell's power. The same applies to batteries since larger batteries tend to have a greater capacity.
Although a trivial solution for supplying energy is to use large solar cells and batteries for small devices, it is costly and impractical. Similarly, many sensor applications do not require the sensor to be working all the time (i.e., temperature sensors might only need to sense every so often) unless the sensed phenomenon changes drastically over short periods. In many applications, sensors can work in a periodic on/off manner. For example, a sensor can be actively sensing for one second and then sleep for nine seconds. In this example, the device will work under a 10% duty cycle saving almost 90% of its energy compared to the always-on approach. Dutycycling mechanisms allow devices to perform their assigned duties using smaller batteries and solar cells, thus decreasing the system's total cost. Energy prediction has been conducted using both statistics and machine learning. Statistical methods include extrapolations [4] and the use of filters such as the Exponentially Weighted Moving Average filter (EWMA) [5]. On the other hand, machine learning techniques include supervised learning [6], reinforcement learning [7], and neural networks [8].
Predicting solar energy is the first step to computing a device's duty cycle. When a sensor device uses batteries and solar cells, the duty cycle can be computed according to the battery's capacity and harvested energy. Various works in the literature have addressed this issue and have proposed algorithms that generally discretize time into equally-sized time slots so that the duty cycle remains constant during a slot. Also, these algorithms assume that the battery level is known at the beginning (or the end) of each time slot. Most algorithms use energy predictions to define the duty cycle for future slots [9], [10], [11], [12], [13], [14].
Nevertheless, some algorithms do not require energy predictions, thus giving up the precision of selecting the duty cycle but requiring less computing power [15], [16], [17], [18], [19], [20], [21], [22]. Most protocols seek to maintain an energy-neutral operation principle as described in [5]. Energy-neutral operation means that the energy consumed in a certain period must be lower or equal to the energy harvested in the same period. An energy-neutral operation virtually (and with a perfect prediction) allows a device to work for an unlimited time.
This work proposes a new algorithm for estimating the duty cycle of solar energy harvesting sensors. The aim is to reduce the computational cost compared to other algorithms while maintaining a stable duty cycle so that devices can perform the same daily and night functions. It also aims to keep the battery energy at levels that extend its useful life. In summary, the main contributions of this paper are: • We designed and characterized a duty-cycling algorithm that seeks to use all of the energy delivered by a solar panel while avoiding power outages in solar harvesting devices.
• We compared the performance of the designed algorithm with other state-of-the-art protocols designed for solar harvesting environments.
• We implemented and characterized PPAASS in a physical device to demonstrate its feasibility in the real world. We show through simulations and experiments that PPAASS performs better in terms of the mean duty cycle, power outages, and power wastage while maintaining the stability of the duty cycle. The rest of the paper is organized as follows: Section II describes the most relevant related work on this topic and contrasts it with PPAASS. Section IV describes the proposed algorithm to modify the duty cycle of devices powered by solar energy and batteries. Section V shows the results of the simulations and compares them with the performance of other works. Section VII shows the testbed experiment results and their characterization. Finally, Section VII presents our conclusions.

II. RELATED WORK
Most studies that consider renewable energy sources agree that the best option so far is the one provided by sunlight. Other energy sources, such as RF, present various problems not easily solved with the current technology [23]. In addition, solar energy has specific characteristics that make it easier to predict compared with other energy sources. For example, sunlight is available for approximately 10 hours during the day, while at night, there will be almost no energy to collect. On the other hand, the number of available sunlight hours varies according to the season of the year and the region of the planet. For example, in the northern hemisphere, more energy is available during the summer than in winter. Moreover, some seasons tend to have more weather variations than others.
Some of the first models predicted solar irradiance based on numerical methods given the energy harvested in previous days. The work in [4] uses statistical models to predict the future trend of a solar irradiance time series. Other predictors consider smooth analysis, linear regression, autoregression, and auto-regressive integrated moving average. In [5], the authors use a model based on the EWMA filter. The value of the energy generated in a particular hour of the day is predicted as a weighted average of the energy received throughout that hour during previous days. The weights are exponential, resulting in less consideration for previous data.
Some works perform energy prediction using machine learning techniques that consider supervised learning, reinforcement learning, or neural networks. There are linear regression methods among the supervised learning techniques, in which the data is fitted linearly, polynomially, or using probability distributions. For example, [24] compares five different algorithms that perform the energy prediction, with the Cubist model and Spikeslab showing the best results. The work in [7] describes a reinforcement learning algorithm that modified the EWMA. In addition to weighting the energy harvested in the previous days, another weighting factor changes dynamically according to current weather conditions. The authors in [8] propose a neural network with better performance rather than a traditional back-propagation neural network and support vector regression. This model is helpful for mapping how the model's inputs mathematically affect the predictions.
Many studies modify the devices' duty cycle in order to balance energy consumption, harvested energy, and energy storage. Works such as [11], [15], [25], and [26] aim to seek the principle of energy-neutral operation. These works aim to have the same battery backup level at the beginning and end of a period. Others, such as [17], [22], [25], [27], and [18], aim to keep the duty cycle stable in order to avoid abrupt variations. Finally, some works try to optimize the performance of the network by individually taking advantage of the device's energy-neutral operation. For example, in [16], the authors maximize the network throughput and minimize packet transmission delay. It is worth noting that most algorithms in the literature assume that solar panels and backup batteries behave like a linear function, as can be seen in [9], [12], [15], [21], [26], and [28].
In the literature regarding energy harvesting systems, most works adapt the devices' duty cycle based on battery level. The available battery energy depends on two factors. The first one is the energy harvested, and the second one is load consumption. Some works propose estimating the battery level by predicting solar irradiance. For example, works such as [9], [10], [11], [12], [28], [29], and [25] use solar irradiance prediction to estimate the battery level to adapt the sensor devices' duty cycle. Unlike [25], where Q-learning is used, these algorithms do not use machine learning to modify the duty cycle, having lower computational complexity.
Other works such as [13], [26], and [30] estimate the battery level based on weather predictions. Reference [13] uses Q-learning to change the actions performed by a device according to its battery level. Reference [26] uses a reinforcement learning model called sarsa, while [30] uses a reinforcement learning algorithm with PPO optimization.
Although energy prediction is the most commonly used method to perform duty cycle modification, works such as [31] and [32] present algorithms based on traffic prediction to estimate the energy drained from the battery and modify the device's duty cycle based on this. These algorithms use recurrent neural networks and exponential smoothing methods, respectively. Some works omit energy predictions while adapting the device's duty cycle in order to decrease the computational complexity of such algorithms. These include algorithms using machine learning methods such as those shown in [15], [22], and [27]. They mostly use reinforcement learning methods or a combination with deep learning. However, there are also several works such as [17], [20], [21], and [33] that do not use machine learning methods. They nevertheless still manage to achieve energy-neutral operation or have a stable duty cycle with lower computational complexity (as seen in [33]). Finally, [16], [18], and [19] use Markov models to represent the behavior of harvested energy and the device backup energy without using predictions. Algorithms in this category manage devices to operate for extended periods, even when a power outage occurs, as in [19].
This work proposes PPAASS for estimating the duty cycle of solar energy harvesting sensors based on the solar cycle. This algorithm seeks to reduce the computational cost of other algorithms, thus enabling its implementation by processing-constrained devices. The algorithm compensates for the inaccurate solar irradiance prediction, maintaining the device's backup battery level within certain limits. It also seeks to maintain the highest possible energy level when daylight ends in order to maximize the devices' duty cycle during night hours. One prominent feature of PPAASS is that it keeps the duty cycle as stable as possible so that its variation rate is minimal while maximizing the use of harvested energy.

III. SYSTEM MODEL
Before describing the specifics of each stage of the PPAASS, some considerations need to be established. First, for the system to operate appropriately, devices must operate in an energy-neutral operation; that is, devices should not consume more energy than the energy that the harvesting source can provide [1]. In addition, to decrease power outages, it is essential to have an energy harvesting subsystem that can keep the device with enough energy to operate for a theoretically infinite period.
Although different device configurations can make use of energy harvesting sources [34], this work, in particular, considers two cases shown in Fig. 1. In the first scenario, the solar panel's sole purpose is to charge the battery; then, the battery is responsible for powering the load (in this case, the device). In a second scenario, both the solar panel and the battery can power the load. In this case, the solar panel can alone power the device as long as it harvests sufficient energy to maintain its operation; otherwise, the device takes power from the battery to keep the assigned duty cycle. Furthermore, if the energy harvested by the solar panel is more significant than that required by the load, the excess energy is used to recharge the battery.
We consider a solar panel with an energy generation limit E hmax and efficiency η p < 1. The latter value depends on the panel manufacturing material that accounts for the portion of the collected solar energy converted into electrical energy. In addition, there is a need for a battery (or any other energy storage device such as a supercapacitor) that, depending on characteristics such as charge/discharge efficiency, size, or internal resistance, can increase the lifetime of the sensor node. It is considered that the energy storage device has a charging efficiency η b < 1, which means there is energy loss while it is charging. This work considers two battery models: an ideal battery with infinite capacity and a finite and fixed-capacity battery. Our model assumes that all of the energy that the solar panel delivers can be used to charge the battery or power up the circuit, thus, it's assumed that the system uses a Maximum Power Point Tracking (MPPT).
In addition, in order to estimate the residual battery level in any of the two scenarios, the total energy consumed by the device in each time slot E c (i) is calculated according to the duty cycle (DC(i)) established for each slot i. It is well documented that the radio-frequency module consumes the most energy in a wireless sensor device, greater than other modules such as sensing or data processing [35]. The total device's energy consumption should consider both the slots when the device is E awake and when it is in sleep mode E sleep as follows:

IV. PROPOSED ALGORITHM
This section introduces PPAASS, an algorithm based on solar energy and backup battery predictions. In addition, feedback from real-time energy harvesting and battery values allows PPAASS to fine-tune the device's duty cycle in order to maximize device availability (e.g., the awake state). Fig. 2 shows a flow block diagram describing PPAASS. The algorithm is composed of four stages. The first stage uses historical data to predict solar irradiance for the coming days. Then, the predictions are used to perform a pre-estimation of a duty cycle, generating a pre-estimated battery behavior. That battery behavior is used to optimize the duty cycle and avoid power outages (produced when the device runs out of power) and energy waste (when part of the harvested energy is not used nor can be stored in the battery because it is fully loaded). The first three stages can be pre-computed before deployment and can be done in a device with bigger computational resources. The final stage occurs in real time and needs to be computed in the sensor device. This stage will overcome the prediction errors by adjusting the duty cycle according to the actual battery level. During each stage, the algorithm predicts the duty cycle and the battery level for N days in the future. Each day D n (where n is the n − th day of the period) is composed of time slots of duration T . Thus, the duty cycle is computed for K future slots to keep the device energized for that period.
In order to help the readers, the symbols used during the rest of the paper are summarized in Table 1.

A. PREDICTION OF HARVESTED ENERGY
The first stage aims to predict solar irradiance levels P h (i) in a slot i by using statistical methods [4], [5] or machine learning [6], [7], [8]. This, in turn, makes it possible to calculate the amount of electrical energy available for the load in each slot E load (i) depending on the solar panel efficiency η p , the area A p , the maximum voltage V p of the solar panel, and the energy generation limit E hmax of the solar panel. The energy that the solar panel can deliver in ideal conditions is calculated as: This equation is used as a simplification of solar panel modeling as described in [36]. However, it is possible to perform more complex analysis, as shown by Singh in [37]. As a result, the amount of energy harvested E harv (i) in each time slot that can be used to power the device or the backup battery is bounded to its energy generation limit E hmax as in (3).

B. PRE-ESTIMATION OF DUTY CYCLE
A pre-estimation of the duty cycle is carried out so the device can operate fairly, which means that this stage maintains the same duty cycle in the K slots. This pre-estimation approach minimizes duty cycle variations. The duty cycle is computed in order to achieve an energy-neutral operation, i.e., consume all the harvested energy during the period. By using solar irradiance predictions, the energy pre-estimation of each slot i in the predicted interval is the expected value of the harvested energy for each slot and can be computed as: where slot 0 represents the interval from time 0 to T , slot 1 represents the interval from T to 2T , and so on. The duty cycle for each slot i is calculated by solving (1), where E c (i) = E(i), meaning that the energy harvested in each slot must be completely consumed: Each time a duty cycle is computed, it must be bounded using (6). This keeps the duty cycle between the minimum desired duty cycle DC min and the maximum preferred duty cycle DC max .
As shown in Fig. 3a, in this stage DC pre (i) are the same for all values of i. In this example and the subsequent figures, slot 0 represents the hour from midnight to 1 am on the first day of the prediction, and the following slots correspond to the next hours of the day. Similarly, slot 24 represents the hour from midnight to 1 am on the second day.
The second and third stages of PPAASS estimate the duty cycle according to the predicted residual battery. It is important to note that an ideal battery is considered, meaning that there is no limit on how much energy the battery can store, and its minimum energy can be less than zero. These assumptions allow the exact calculation of how much energy can be available to the device in a particular slot i. These include cases in which a device harvests less energy than needed or wastes energy via excessive harvested energy.
For the first proposed system, when only the battery can power the device, the estimated residual battery at the end of each time slot B(i) is calculated according to (7).
As aforementioned, in this system, the solar panel charges the battery directly (which we assume charges/discharges in a linear way). Thus, the stored energy depends on the harvested energy and battery efficiency. On the other hand, the drained energy depends only on the load's power consumption.
Furthermore, for systems in which both battery and solar energy can power the device, two cases must be considered: 1) When the energy harvested from the panel is greater than the device's consumption for a time slot i, then the battery saves the excess energy (considering its efficiency η b ). The estimated residual battery at the end of the slot i is as follows: 2) When the energy harvested by the panel is not enough to fulfill the device's consumed energy in slot i, the backup battery is used so that the load can complete its operation. Therefore, the estimated residual battery at the end of the slot is given in (7). From the duty cycle calculated in section IV-B, the energy stored in the device's backup battery is calculated, which will be used to continue modifying the duty cycle in the next stage. We present an example of this in Fig. 3b.
The computational complexity of this stage is O (K ) as it is lead by the sum in (4).

C. DUTY CYCLE CORRECTION
Performing the duty cycle allocation as in section IV-B may cause the backup battery to exceed the limits of a real battery (B 0 , B max ), as can be seen in Fig. 3b. Therefore, this stage is aimed at avoiding this phenomenon. First, the algorithm obtains the global maximum and minimum residual energy in the battery for each of the days that comprise the duty cycle's prediction window. The maximum level on day D n occurs during the slot s max (D n ) since during the previous slots, the harvested energy was greater than the load demand, thus charging the battery. On the other hand, in the following slots, the harvested energy is lower than the load demand, draining part of the energy from the battery. In Fig. 3b, the maximum battery level for the first day occurs at slot 17 and at slot 43 for D 2 . On the contrary, the minimum level on day D n occurs during s min (D n ), that is, when the harvested energy is enough to power the load without the need to drain the battery. In Fig. 3b, the minimum battery level occurs at slot 8 for D 1 and at slot 32 for D 2 . Each period of 24 hours during the period of D n days has one minimum E min and one maximum E max of the battery level (called battery peaks). These battery peaks comply with: This algorithm stage defines two levels in which the battery can fluctuate. The first is the battery's minimum desired level B inf . The second level refers to the battery's maximum desired level B sup . These boundaries allow overcoming prediction errors and can be used to work within levels that might benefit a battery's lifetime. B inf and B sup are selected according to the application. For instance, if the goal is to increase the life cycles of a lithium polymer battery, B sup has to be set around 60 − 65% of its maximum energy capacity with B inf between 50 − 55% [38]. If B inf = B min , the devices might run out of battery if a wrong prediction occurs.
Knowing the above and noticing the behavior shown in Fig. 3b, it is possible to compute the missing or excess energy between two consecutive peaks so that the predicted residual battery level can be kept between B inf and B sup , as shown in (12) and (13).
With the amount of energy in excess or missing, it is possible to adjust the slots' duty cycle between the pair of battery peaks p j−1 and p j so that the residual battery levels fluctuate between the desired values B inf and B sup while the device operates continually. The new duty cycle of each slot between the peaks in p j−1 and p j for j > 0 is calculated as: DC cor (i) = Equation (14) is used when there is an excess of the predicted battery level in slot p j and (15) is used when there is a battery deficit in slot p j . Fig.4a shows the duty cycle obtained with (14) and (15). The plot shows that the duty cycle of slots 0 to 8 increased because the battery level of the minimum peak of day 1, found in slot 8, is greater than B inf . Also, the duty cycle of slots 9 to 17 increased because the battery level in the peak found in slot 17 (s max (D 1 )) is greater than B sup (Fig. 3b). It can also be noticed that the duty cycle of the slots 18 to 32 decreased because the battery level in the slot 32 (s min (D 2 )) is lower than B inf (Fig. 3b). Once again, the duty cycle of slots 33 to 43 decreased because the battery level in the maximum peak of day two (slot 43) is lower than B sup . Recall that after the evaluation of (14) and (15), the duty cycle must be bounded by using (6).
From the duty cycle adjustment performed in this stage, the predicted residual battery level in each slot B(i) is calculated with (7) and (8). The new battery level might deliver a different set of energy peaks. Thus, it is necessary to compute the new set of energy peaks P new and compare it against P. If P = P new , this algorithm stage repeats with P = P new until the set of peaks is the same at the beginning and the end of the iteration. This phenomenon causes the computational complexity of this stage to be O K 2 . At the end of this stage, the predicted battery levels remain within the limits B inf and B sup , as can be seen in Fig. 4b.

D. DUTY CYCLE WITH REAL-TIME ADAPTATION
If solar irradiance prediction is identical to the actual solar irradiance, the device would never run out of battery and could work indefinitely. However, since the prediction can present errors, like those shown in Fig. 5, this stage of the algorithm adjusts the duty cycle in order to mitigate errors in the prediction.
This stage also considers a set of slots with peaks P. Thus, in each slot p j where the battery peaks occur, the device's actual battery level at that slot B real (p j ) might have a deviation from the predicted value, as shown in Fig. 6a, in which the actual battery level is measured in slots 8, 17, 32 and 43.
In this way, for each slot p j of the set P, the difference between the actual battery level and the predicted battery level E dif is calculated as in (16).
From this result, the duty cycle of the next p j+1 − p j slots is adjusted according to (17). For example, in slot 8 in Fig. 6a, the actual battery level is lower than predicted. Therefore, the duty cycle of the slots 9 to 17 must be decreased accordingly, as shown in Fig. 6b. On the other hand, as in slot 32, the actual battery level is higher than predicted. Then, in slots 33 to 43, the duty cycle is increased as in Fig. 6b. In the case where E dif = 0, the duty cycle of the following p j+1 − p j slots remains the same as the one computed in section IV-C. where: Since this stage always performs two corrections per day, the computational complexity is O (N ).

V. SIMULATIONS
We ran a series of simulations and experiments in order to test the algorithm's performance considering that the main objectives are to optimize: energy utilization by avoiding overcharging the battery, power outages by avoiding overuse of the battery, and the number of duty cycle changes. Simulations used NREL data from 2017 to 2019 to make solar irradiance predictions in Mexico City. The duration of each slot was one hour. In particular, simulations use global solar irradiance data from the 15 previous and subsequent days from the three prior years of the date to predict using the Cubist Model [6]. In the presented results, predictions were made for seven days. The tests took place in Mexico City from April 8 to 14 and November 23 to 29, 2020, because it allowed the study of the duty cycle in spring and fall, respectively.
Simulations considered a 3.7 V rechargeable lithium battery of 550 mAh with an 85% charge efficiency and no discharge loss. For all simulations, the initial battery level is half its total capacity, that is, 275 mAh. Also, simulations considered the technical specifications of the used sensor device, taking into account both active and sleep mode consumption. The aforementioned system parameters and the parameters corresponding to the algorithm are shown in Table 2.  Fig. 7 shows how the seasons of the year impact the algorithm's performance regarding the battery system (hybrid and battery charge) and the prediction accuracy. Fig.7a and Fig. 7d show the solar irradiance prediction for April and November, respectively. The variation of the prediction can be characterized by the average coefficient of determination computed as in (18), where E real is the observed harvested energy in the slot i, E harv is the estimated harvested energy in the slot i, andĒ real is the mean of the observed harvested energy. In our case, we obtained a coefficient of 0.945 per day, with the second day being the least reliable, obtaining a coefficient of 0.83. On the other hand, in November, the average coefficient of determination per day was 0.974, with the first and second days being the least reliable, with a coefficient of 0.94. A coefficient of determination close to 1 indicates that the prediction adjusts to the proposed days' actual solar irradiance. Fig. 7a and Fig. 7d show less mean solar irradiance in November (fall) than in April (spring) in Mexico City. These results highlight that the prediction model adapts to the different seasons of the year. Fig. 7b and Fig. 7e show the device's duty cycle for each slot of the simulated week in April and November, respectively. The plots show the results for the two scenarios introduced in Section III: the one in which only the battery powers the device, and the hybrid scenario, in which the harvester can directly power the device. As shown in Fig. 7a and 7d, the first and last slots in each day correspond to night hours, since there is no solar irradiance for the device to harvest. For example, slot 0 represents midnight to 1 am on the first day, and slot 23 means 11 pm on the same day to the moment before the midnight of the following day. In the case of April (7b) and for the hybrid system, PPAASS obtained an average duty cycle of 21.93%. The algorithm demonstrated stable behavior by having only three different duty cycles per day, a trend maintained during the seven days of experiments (the duty cycle ranged from 12.71% to 30%). In the case of the battery charging system, the average duty cycle was 21.35%, using only three different daily duty cycles. Nevertheless, the average duty cycle decreased due to battery efficiency (the energy loss when the battery charges). In this case, the duty cycle ranged from 11.98% to 30%. In both systems, the results show that solar irradiance during the tested week was enough to power the device. On days three to seven during April, the harvested energy was higher than expected (see Fig. 7a), so the battery level reached its maximum value B max = 550 mAh in the same days despite using the highest duty cycle allowed, as shown in Fig. 7c. On the other hand, it is observed in Fig. 7b and 7c that the algorithm adjusted the duty cycle for the night slots so that the battery level did not drop below B inf = 100 mAh from the third to seventh day.

A. SIMULATIONS COMPARING TWO ENERGY HARVESTING SYSTEMS
The duty cycle results for November (shown in Fig. 7e) indicate an average duty cycle of 20.21% for the hybrid system, with three duty cycle changes per day, similar to the case in April. The duty cycle varied from 12.7% to 30% for the seven days shown. In the case of the battery charge system, the average duty cycle was 18.82%. As the harvested energy is lower than in April, the energy loss caused by the battery charging efficiency is more noticeable, so the duty cycle ranged from 10.8% to 29%. This phenomenon can also be observed in Fig. 7f, where the level of the battery charging system hardly reached the B sup = 495 mAh. On the other hand, for the hybrid system, the calculated duty cycles enabled the battery level to fluctuate from B inf = 110 mAh, but still, on all days from three to seven, the battery level is higher than B sup = 495 mAh.

B. SIMULATIONS COMPARING PPAASS WITH OTHER ALGORITHMS
PPAASS, operating in hybrid mode, was compared with two algorithms that were selected because they represent stateof-the-art examples of algorithms operating with and without solar irradiance predictions. The first one by Sharma et al. [9] is a machine learning-based algorithm with O (K ) complexity that operates with solar irradiance predictions. In contrast, the second one (called StableSENS by Loreti et al. [33]) uses a Lyapunov optimization and has a complexity of O R 2 , where R is the number of possible duty cycles used (this algorithm operates without solar irradiance prediction). The two algorithms were also selected because they have similar computational complexity compared with PPAASS.
We used the same parameters for the sensor device and the solar panel shown in Table 2 to simulate Sharma's algorithm. We also used the same duty cycle bounds (1% and 30%) in the case of the simulation for the StableSENS algorithm and performed an analogy with the energy cost table associated with a duty cycle that can only take integer numbers. In addition, we considered two different configurations that modify the algorithm's stability for the StableSENS simulation. The first configuration with parameters γ = 9 and V = 4, 000, which is more stable, and the second one with γ = 1 and V = 4, 000, which uses most of the harvested energy. Fig. 8 and 9 show the behavior of the algorithms under consideration for two seasons of the year. Fig. 8 compares the behavior of the three algorithms during a week in April. The average duty cycle of PPAASS for the seven simulation days is 21.93%, with a minimum of 14% during the night of the first day and a maximum of 30% during six of the seven days in daylight, as shown in Fig. 8a. As shown in Fig. 8b, the battery is never exhausted, although the device uses the DC max almost half of the time. On the other hand, Fig. 8c shows that Sharma's algorithm obtained an average duty cycle of 19.93%, and the lowest duty cycle DC min = 1% occurs in the last hours of the day. In addition, there are slots in which the duty cycle is zero, for example, before the dawn of the second day, which implies that the device burned out during those hours, as shown in Fig. 8d. Next, for the StableSENS algorithm with parameters γ = 9 and V = 4, 000, the results in Fig. 8e show that the average duty cycle is 14.68%, maintaining a constant duty cycle after the first eight hours of simulation. With the assigned duty cycle, the device's backup battery level is never less than B inf = 100 mAh. Still, in contrast, the battery is at 100% of its power capacity in most slots, as shown in Fig. 8f. Finally, Fig. 8g shows the results for the StableSENS algorithm with γ = 1 and V = 4, 000. In this case, the duty cycle varies between 10% and 30%, with an average of 21.38%. The duty cycle is higher when more solar energy is harvested, that is, during daytime. In contrast, the duty cycle is lower for night slots. Fig. 8h shows that the battery level reaches B max = 550 mAh fewer hours than the configuration with γ = 9 and V = 4, 000, and also has a behavior similar to the battery level of PPAASS.
The simulation results for the three algorithms for the week of November are shown in Fig. 9. In general, all algorithms reduced their average duty cycle compared to April due to the fall season in Mexico City. Fig. 9a shows the duty cycle of PPAASS. The duty cycle varies from 12.7% to 30%, with an average of 20.21%, which is 1.72% lower than the average during the April week. In addition, Fig. 9b shows less battery waste than the results for April since B sup = 495 mAh was exceeded in fewer slots. Fig. 9c shows the duty cycle of the Sharma model. The duty cycle ranges from 1% to 30%, averaging 16.41%. As in April, the minimum duty cycles occur during the last hours of the day, while the maximum duty cycles oscillate between the beginning of the day and midday. Unfortunately, on most of the days before dawn, the battery is depleted (Fig. 9d), which means that during those slots, the duty cycle is zero due to power outages. However, in this case, no slots reach the B sup = 495 mAh limit. The duty cycle of the StableSENS algorithm with γ = 9 and V = 4, 000 is shown in Fig. 9e. It can be observed that there are more variations in the duty cycle compared to April's. In November, the duty cycle varied between 14% and 15%, with an average of 14.56%. Fig. 9f shows that, once again, the price of the stability of the duty cycle of StableSENS is the energy waste during daylight of the seven days. Finally, we find the duty cycle behavior of the StableSENS algorithm with γ = 1 and V = 4, 000 in Fig. 9g. The duty cycle remained similar to that of April, averaging 20.19%, which increases drastically in the dawn and decreases gradually during the noon. Fig. 9h shows that the battery level is lower than B inf = 100 mAh in the last five days of the week compared to PPAASS, which rarely is below B inf .
As described above,PPAASS achieves a higher average duty cycle in the spring and fall seasons than the other two algorithms. Now, we present an energy analysis since it is desired that devices maximize the usage of harvested energy as much as possible while avoiding energy shortages. That is, the backup battery power should not be allowed to deplete, as this would imply a temporary power outage of the device while simultaneously preventing the battery level from reaching the maximum level. Although it is less problematic than running out of power, it leads to energy waste. Fig. 10a shows the number of hours where the battery level was above B sup = 495 mAh or below B inf = 110 mAh during the simulated week in April. In those cases, a device is in danger of wasting energy or powering down. For PPAASS, the battery was below B inf = 110 mAh for six hours during VOLUME 10, 2022 the seven days of simulation, but the system never ran out of battery power. However, for 33 hours, the battery level was above B sup = 495 mAh because the prediction was below the actual harvested energy, as shown in Fig. 7a, thus resulting in a lower duty cycle. The StableSENS algorithm with γ = 1 behaves in a similar way to PPAASS. However, it wastes more energy as there are four more hours where the battery level exceeds B sup = 495 mAh. The StableSENS algorithm with γ = 9 showed the worst performance in terms of energy waste since the battery level exceeded B sup = 495 mAh in 61 slots trying to maintain a low duty cycle during all simulation slots. Finally, Sharma's algorithm performed the worst as far as energy waste is concerned because 21.4% of the time, the battery level is below B inf = 110 mAh. The plot shows that the device ran out of battery during 13 hours for the Sharma's model, thus turning off the device. In addition, the two configurations of the StableSENS algorithm fill the battery for more hours than PPAASS, which is also a waste of energy. Fig. 10b shows the number of hours or slots in which the battery had a level above B sup = 495 mAh or below B inf = 100 mAh for the simulation carried out in November. For PPAASS, during November, there were nine hours where the battery level is below B inf = 110 mAh, compared to April, in which there were only six hours below B inf = 110 mAh. Nevertheless, the device did not run out of battery in both simulations. During 20 slots, the battery level was above B sup = 495 mAh (13 hours less than in April). These two phenomena are due to the decrease in the amount of solar irradiance compared with April, as shown in Fig. 7a and Fig. 7d. The StableSENS algorithm with γ = 1 behaved differently when comparing its performance between November and April. In this case, there were more hours when the battery level was below B inf = 110 mAh compared to the number of hours in which the battery level was above B sup = 495 mAh (with a total of 31 hours versus 11 hours, respectively). This behavior implies that the system is at a higher risk of running out of battery power; therefore, a change of season directly impacts performance. For the StableSENS algorithm with γ = 9, the behavior is very similar to the one observed in April. The only difference is that the number of slots in which the battery level exceeded the B sup = 495 mAh limit decreased to 47, as well as the number of hours in which the battery was fully charged. This behavior occurs due to a decrease in solar irradiance. Finally, Sharma's algorithm, which already had the poorest performance in April, worsened its performance during November when the number of hours in which the battery level was below B inf = 110 mAh increased to 44, and the device ran out of battery during 17 hours.
A desired characteristic of any algorithm is the ability to have a stable duty cycle while maximizing the use of harvested energy. Fewer changes in the duty cycle improve a device's overall performance since it avoids frequent and possibly drastic variations of the duty cycle that ultimately impact what the device does. The daily variation rate is For all the experiments of this paper, the slot duration was one hour, thus Daily slots = 24. Fig. 8a and Fig. 9a show the stability of PPAASS because there are only two changes in the duty cycle for each 24-hour period. Fig. 11a shows the rate of change in the duty cycle for seven days in April. As can be seen, the StableSENS algorithm with γ = 9 only shows changes in the duty cycle on the first simulation day. However, during the following days, it remained unchanged because the parameter γ is optimized to maximize the stability. Thus, making it the most stable algorithm but having the lowest mean duty cycle (Fig. 8e). On the other hand, PPAASS shows a variation rate in the duty cycle equal to 8.69% per day (Fig. 11), equivalent to changing the duty cycle twice every 24 hours. Finally, the Sharma model and the StableSENS algorithm with γ = 1 demonstrated the highest variation rates during April. They presented rates between 13.04% and 30.43% and  between 30.43% and 39.13%, respectively, making them the most unstable. On the other hand, 11b shows the variation rate in November. PPAASS maintained its variation rate similar to April, while the other algorithms increased the rate of variations in the duty cycle. The StableSENS algorithm with γ = 9 increased to 8.69%, while with γ = 1, the variation rate was between 34.78% and 43.47%. Finally, the Sharma model ranged from 26.08% to 39.13%. A summary of the main results is shown in Table 3. The table shows the average duty cycle, the number of hours that the battery was insufficient to power the device, the number of hours when the battery was fully charged and unable to harvest all of the available solar energy, and the mean number of daily duty cycle changes.

VI. IMPLEMENTATION
We evaluated the performance of PPAASS in a real-world experiment. We implemented the battery charging system shown in Fig. 1a using a Heltec's Wireless Stick Lite IoT device, which has an ESP32-Pico processor and integrates Wi-Fi, LoRa, and Bluetooth technologies. On the other hand, the system used a 3.7V lithium-polymer battery, harvesting energy through a solar panel with the characteristics shown in Table 4. Also, the system used a solar power manager module, which includes an MPPT to optimize the charging of the battery. The solar power module can also charge the battery without exceeding its maximum capacity and provides a constant voltage output to power the Wireless Stick Lite. Fig. 12 shows the testbed used for this experiment with the elements described above. Table 4 shows the parameters for the algorithm and other system parameters empirically obtained.
The B sup = 3.94 V and B inf = 3.7 V parameters were chosen according to [39], in which the authors describe a battery's characteristics. This type of battery can have more VOLUME 10, 2022 life cycles if it maintains a level around 80% and has a depth discharge lower than 40%; that is how much energy goes into and out of the battery in a given cycle. Notice that, in practice, the battery level is measured by the voltage in the battery. Then, B sup = 3.94 V represents 90% of the battery's maximum capacity, while B inf = 3.7 V represents 60% of the maximum capacity. The proposed voltages consider that the solar power manager module requires at least 3.4 V , which is regarded as the minimum battery level.
The only operation that the device performs is the duty cycle real-time adaptation. For this operation, the actual battery level is compared with the predicted battery level. The other stages of the algorithm were pre-computed.
The results can be seen in Fig. 13 in which variations in measured battery level are shown against the estimation made using the solar irradiance predictions and the duty cycle obtained in stage 3 of PPAASS (from section IV-C). In Fig. 13b, it can be observed that a battery level below B inf = 3.7 V was only registered in approximately 5 hours of all the analyzed days, while there was a battery level above B sup = 3.94 V in one hour. This behavior shows a satisfactory operation of PPAASS that would allow the battery to have more life cycles due to the previously explained depth of discharge. On the other hand, the obtained duty cycle, shown in Fig. 13a, has similar behavior to the shown simulations, given that the duty cycle only has two changes per day, reflecting the stability of PPAASS. The duty cycle changed from 17.65% during daytime to 1.15% during nighttime on the last day. The same occurred the previous day when the duty cycle changed from 20.5% during daytime to 2.4% during nighttime. Fig. 13b shows that with real-time duty cycle adaptation, energy in the battery never surpasses the maximum level B sup = 3.94 V before it starts dropping. At the same time, the battery reported the lowest energy level at the beginning of the daytime, which is close to the minimum level B inf = 3.7 V taking advantage of the incoming harvested energy. However, due to prediction errors, it can be observed in Fig. 13b that the battery level did not reach B sup = 3.94 V , showing two particular behaviors. The first one appeared in the last two days when the maximum battery level was far below B sup = 3.94 V , which implies that the system received much less solar irradiance than expected, and the weather was cloudy. The second behavior was observed in the first three days, when the received solar irradiance was interrupted before expected because the day became cloudy, causing the maximum battery level to be located before the predicted hour.
Another aspect to highlight is that although the battery level did not reach the desired maximum during most days due to differences between solar prediction and day-to-day solar irradiance levels, the real-time adaptation of the duty cycle responded to these variations. PPAASS allowed the battery to reach the desired B inf = 3.7 V level in the mornings. This can be seen in Fig. 13a, where changes in the duty cycle are not so abrupt in contrast to the ones predicted for the evening hours since, at the start of daylight, the difference between the predicted and actual battery level is negligible. The prediction errors during daylight are mostly due to weather conditions because most of the days were cloudy when they were expected to be sunny. The last two days were the most cloudy of all the experiments. Despite those error predictions, the battery level seeks to keep between B inf and B sup .
Finally, Fig. 13b shows some exceptional cases on days 1 and 4. At the end of each of those days (i.e., at 17 hrs. and 18 hrs., respectively), the difference between real and predicted battery levels is not as significant as on the other days. However, in Fig. 13a, it can be seen that the actual duty cycle showed abrupt changes compared with the predicted changes. This is because the algorithm considers that a device consumes energy even in sleep mode. This energy consumption significantly impacts a device's total consumption, showing a significant difference between the predicted duty cycle and the one adopted in the testbed.

VII. CONCLUSION
This article presents PPAASS, a novel algorithm for optimizing energy consumption in solar energy harvesting devices that considers the device's consumption in sleep mode. PPAASS has the advantage that only the B sup and B inf system parameters for the battery level are needed. Both parameters can be set to suit a specific application, either to provide longer battery life or to keep the device working with higher duty cycles. PPAASS was compared for one week against other algorithms found in the literature, achieving better stability (with a daily variation rate of 8.69%) while maintaining a higher average duty cycle in both April (21.93%) and November (20.21%) weeks, thus maximizing the use of the harvested energy. PPAASS avoided the waste of energy that occurs when the battery is full (during November the battery never reached B max ), unlike the StableSENS configurations that had a full battery for two hours for γ = 1 and 27 hours for γ = 9. Also, PPAASS consumed as much energy as possible without running out of power, in contrast to Sharma's model, which also had a lower duty cycle and ran out of power for 13 hours in April and 17 hours in November. This behavior shown by PPAASS is well suited for many applications, such as those requiring constant monitoring and being very sensitive to information loss, like surveillance cameras and security sensors. The experiments showed that the PPAASS could efficiently react to errors caused by the prediction of harvested energy, which frequently occurs due to sudden changes in the weather. If the prediction algorithm is improved, there will also be an improvement in PPAASS performance, and the devices will waste less energy. On the other hand, PPAASS requires low processing power; that is, it is well suited for devices that do not have many resources, such as IoT devices. This is because running the first three stages on a device with higher computational resources is possible. Thus, the sensor device performs only the arithmetic operations of the final stage.