PiSupply / PiJuice

Resources for PiJuice HAT for Raspberry Pi - use your Pi Anywhere
https://uk.pi-supply.com/collections/pijuice/products/pijuice-portable-power-raspberry-pi
GNU General Public License v3.0
440 stars 104 forks source link

Pi wakes up irregularly even when wakeup alarm is set to wakeup once a day #881

Open vvaibhav08 opened 2 years ago

vvaibhav08 commented 2 years ago

Hi! I have a Pi4 with a PiJuice module and a 12000mAh LiPo battery. I also have a solar panel connected. The entire setup is placed in a rather remote region. Now I have the Pi set up such that it should wake up once a day, run a process (take an image and upload to a cloud bucket), and then shut down, turning off the 5V as well. The setup wakes up as per the alarm specifications, but sometimes randomly wakes up at completely different times. The general pattern I've seen is that it would wake up randomly, triggering the process that I want to run on boot, shutdown, and then wake up multiple times quickly afterward in succession (as an example, I saw it woke up and uploaded an image 6 times in an hour period). I cannot figure out why that might be happening.

Attached are the screenshots of the PiJuice configuration that I am using. Setup: Raspberry-pi4, 8GB PiJuice, pijuice firmware v1.5 Battery: Pisupply, 12000mAh LiPo Solar panel, 6W

General settings: Screenshot from 2022-06-23 10-39-17

Wakeup alarm (I've also added dtoverlay=i2c-rtc,ds1307, in the boot config to make sure alarm flag remains checked) Screenshot from 2022-06-23 10-43-29

System task: Screenshot from 2022-06-23 10-43-59

System events: Screenshot from 2022-06-23 10-44-14

Would really appreciate some help. Cheers!

tvoverbeek commented 2 years ago

A 5W solar panel as (only) power source is probably too low. The charging current for the 12000mAh is 2.5A. A pi4 is also relatively power hungry. My guess is that the battery goes so low that the MCU turns off. In that case the RTC loses its time until it gets resynchronizes when there is an internet connection (sysetemd_timesyncd). Suggest you log the battery level at start to confirm that the battery has sufficient capacity.

vvaibhav08 commented 2 years ago

@tvoverbeek thanks for the response. That is a good point and suggestion. However, it's not clear to me why this will cause the PiJuice to trigger a wake-up. Do you mean that after the MCU turns off, and the RTC clock loses time due to very low battery, the MCU will trigger an automatic wake-up the pi as soon as it detects some charging (from the solar panel)? In that case, would the solution be to just not let the battery get so low, and enable the "min-charge" setting?

Also for the high required charging current and the available panel, I've adopted a CUSTOM battery profile which is basically the same as the default 'PJLIPO_12000' profile but with a lowest termination_current value (see the profile parameters below). I think the panel does charge the battery, extremely slowly though, but that is fine for my usecase. Would it help if I also lowered the charge current value? profile = {'capacity': 12000, 'chargeCurrent': 2500, 'terminationCurrent': 50, 'regulationVoltage': 4180, 'cutoffVoltage': 3000, 'tempCold': 0, 'tempCool': 2, 'tempWarm': 49, 'tempHot': 65, 'ntcB': 3450, 'ntcResistance': 10000 } ext_profile = {'chemistry': 'LIPO', 'ocv10': 3488, 'ocv50': 3824, 'ocv90': 4061, 'r10': 112.0, 'r50': 108.0, 'r90': 108.0 }

maxsitt commented 2 years ago

@tvoverbeek @vvaibhav08 I have a very similar problem regarding irregular wakeup times.

Setup:

In my case there are several wakeup times every day:

Screenshot (78)

While the wakeup is correctly triggered at the defined hours, it is additionally triggered about every 1-2 hours at irregular times. I also changed "Weekday" to "Day", which seems to make no difference.

Are there any other options I could try out to solve this problem? What could be possible causes despite power outage?

Thank you!

tvoverbeek commented 2 years ago

Note the alarm times are normally in UTC. What is your timezone? I am in Austria (now summertime: UTC+2) So for me your daily settings are 4; 5;6;12;14; local time.

maxsitt commented 2 years ago

Yes, the times are already in UTC. I'm in the same timezone as you, so the actual wakeup times are 8;9;10;16;18;19.

However the RPi gets wake up a lot more, during the whole night every 1-2 hours and during the rest of the day between the defined hours.

tvoverbeek commented 2 years ago

I do not know how you charge the power bank by the solar array. When the Pi is shut down do you remove the 5V from the PiJuice to the Pi? In that case the residual power consumption by the PiJuice/Pi might be too low for the power bank. Most power banks are designed for phone charging and turn off when the currrent drops below a certain value. Maybe your solar array/power bank restarts and again delivers power to the Pi -> boot.

maxsitt commented 2 years ago

I'm using a powerbank with "Always on" feature, so that should be no problem if it works as advertised.

I activated Software Halt Power Off with a delay period of 65 seconds, so 5V to the Pi should be removed after about one minute after shutdown.

If the powerbank should restart anyway, will this power on the Pi even if No battery turn on is deactivated? So if the USB micro power input changes from NOT_PRESENT to PRESENT the Pi will get turned on no matter what?

tvoverbeek commented 2 years ago

What is your 'Wakeup on charge' setting? If it is enabled and the PiJuice battery level is above threshold the Pi will start as soon as the USB micro power input changes to PRESENT.

maxsitt commented 2 years ago

Wakeup on charge is disabled, as I only want the Pi to wake up at specific times.

The only other enabled System Task is Min Charge (Threshold 5%).

tvoverbeek commented 2 years ago

Then I am out of suggestions. Note (but I guess you are aware of this) 'Wakeup on charge' is not part of the System Task. There is also an additional non-volatile setting since the last firmware release.

maxsitt commented 2 years ago

Ok, thank you anyway for the help! I will try a different powerbank (or the solar panel as direct input into the PiJuice), as well as a normal power adapter and see what happens.

maxsitt commented 2 years ago

@tvoverbeek I found the cause of the described problem! Now it seems kind of obvious, but I didn't think of it earlier, only after checking some of the settings. Even though the Watchdog setting was disabled, the Restore option on the right was enabled, which seems to activate the Watchdog even if it was disabled in the settings. I'm not sure if this is only happening on my system or if this could be improved by making the Restore option only available/active if the Watchdog setting is actually enabled.

So the Wakeup times were triggered by the Watchdog every 65min after the last shutdown. I can now see this pattern in the Wakeup times.

Unfortunately there is no documentation on the Restore setting and it is a little bit unintuitive that the Restore setting activates the Watchdog even if the Watchdog was disabled by the user.

jei-gaither commented 2 years ago

Howdy! I've been listening to this thread and this explains my issue as well!

I had my Watchdog set to ON (but not Restore), and since your post pointed it out, the pattern is obvious to me as well.

Two things:

A) Can you shed more light on what Restore setting is designed for in terms of Watchdog and Wake Up on Charge? It's unclear to me what Restore setting does.

and

2) Is there a workaround for using Watchdog (in case of lockups) and NOT having it trigger a wake state?

Thanks for this awesome product and the great efforts to help other users/developers!!!

-Jei.

vvaibhav08 commented 2 years ago

@maxsitt, great that you found the issue for your repeated unwanted wake-ups. I am not really sure why I still had these wake-ups even when both the watchdog and the restore settings were disabled in my setup. It's so strange. Anyways, since I never could find the root cause for this, I shamelessly just updated my boot script to check if the current time matches the intended wakeup alarm times, run the process if it does, and shut down otherwise. Quite dirty but works for me.