I’m running a simple script that checks every second the satus of a GPIO.
There is a PIR Sensor connected to this pin and another pi running home assistant reads the status via SSH.
But after about 3 to 4 days my pi with the script dies and have to pull out the power en put in back in.
When he dies, i can’t reach him via SSH or look at the GUI what is wrong because i get a black screen.
Checking the /var/log/messages also doesn’t give me anymore information?
This sounds like some kind of memory (or other resource leak). Every time your script runs through its loop it uses a bit more memory, and doesn’t free it up.
Eventually, there is no more memory left for anything on the Pi to run, and you have to reboot.
You can check for this by using something like the top command to see the running processes. It shows each one’s memory usage, which is probably significantly bigger after a day or so for your script - or possibly something else if that is really the problem.
But i’m also running the command echo 3 > /proc/sys/vm/drop_caches every 10 minutes to free up the memory and het reboots every night. So wouldn’t it be strange he runs out of memory ?
If you are rebooting your Pi every night, then yes, my initial idea is probably incorrect. But you really need to say everything you are doing on the Pi before you can get any useful help.
For instance, why are you running drop_caches every 10 minutes? Why are you rebooting every night?
I implemented these actions recently, trying to fix the dying of my pi.
When this problem occured the first time, i deleted some package i had previous running on the pi.
The second time, my thoughts were also that the pi had insufficient memory.
So i implemented the action drop_caches to free up the memory.
And let it reboot every night, to have a clear start, so it won’t die anymore.
If the problem is that the script is grabbing more and more memory, drop_caches won’t help. But if it is only happening on certain days, then either the sensor is being called at different rates, or there is something else wrong.
I still think you should monitor your process by starting a terminal and running top for a while. You can switch the sort order to the amount of memory being used by pressing the ‘>’ character, which might help you see if something is increasing.
Of course, it may be something other than memory that is being used up.
And if you can go without your sensor for a while, it might be worth trying to run the Pi without your script, just to make sure it is reliable on its own. It may be a hardware fault.