diy-guy
Posts: 5
Joined: Wed Mar 09, 2016 7:29 pm

Raspi crashes in while loop

Wed Mar 09, 2016 7:41 pm

Hi all,
i have an problem with a script i wrote.
When running this infinityloop script, my Raspberry Pi 3 freezes after a few minutes. I have to force reboot my pi to get it working again.
This Script checkes if my girlfriend or me is at home with our smartphones and activates or deactivates the HDMI Port to save some energy.
It would be nice to get an hint what causes this and how to fix this problem

Code: Select all

#!/bin/bash 
MACME="12:34:56:0D:FE:10" 
MACHER="12:34:56:3A:4C:54" 

while :  
do 
if sudo l2ping -c 1 $MACME &> /dev/null || sudo l2ping -c 1 $MACHER &> /$
   then
        vcgencmd display_power 1 
        sleep 20 
   else
        vcgencmd display_power 0 #deaktiviert den HDMI Port
        sleep 10
fi
done

User avatar
DougieLawson
Posts: 39303
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Raspi crashes in while loop

Thu Mar 10, 2016 7:54 am

I've no idea what you're trying to achieve by running that script that does stuff with vcgencmd periodically, can you explain what it's trying to do?

The first thing you need to do after pulling power (or shorting the RUN header) and rebooting is to look at what diagnostics you've got available. So start by looking at: /var/log/dmesg, /var/log/messages & /var/log/syslog, you're looking for any messages in there that don't appear normal or informational. Is there a kernel oops? Is there something like a USB device driver that's killing your system? Has the kernel out-of-memory (OOM) killer been activated?

Next is to set up a cronjob so that you record the output from the free command every minute as that will tell you if something is leaking storage.

There's no exact science involve here, it's just a case of forensics and hoping you find something that's being triggered that shoots your operating system dead.

Also, remember that vcgencmd is a sample program and, possibly, hasn't been fully debugged by the RPF folks who wrote it.
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

diy-guy
Posts: 5
Joined: Wed Mar 09, 2016 7:29 pm

Re: Raspi crashes in while loop

Thu Mar 10, 2016 6:49 pm

I use vcgencmd because it is easy to use. I can sent an "vcgencmd display_power 1" even if my HDMI Port is running, without having my monitor flickerung as it is with the "tvservice" command.

This script checks if my smartphone is reachable to have some kind of presence detection.
If i am not at home the Monitor is in sleep mode an reduces energy consumption to save some money.
This is an Smart Mirror Project.

diy-guy
Posts: 5
Joined: Wed Mar 09, 2016 7:29 pm

Re: Raspi crashes in while loop

Thu Mar 10, 2016 10:09 pm

I just watched those logfiles at the time my errors occured but there is poorly no useful entry which shows me an error.
I also wrote a script which just l2pings my smartphone without this vcgencmd command.

So there seems to be a problem with permanently (5sec delay) pinging an Bluetooth MAC adress via l2ping. This script works for about 10minutes then the screen freezes and my PI3 isn´t responding via ssh and has to be hart rebooted.

stderr
Posts: 2178
Joined: Sat Dec 01, 2012 11:29 pm

Re: Raspi crashes in while loop

Thu Mar 10, 2016 10:36 pm

diy-guy wrote:I just watched those logfiles at the time my errors occured but there is poorly no useful entry
If whatever is happening locks up the entire machine, would there be any way for it to write a useful entry?
So there seems to be a problem with permanently (5sec delay) pinging an Bluetooth MAC adress via l2ping. This script works for about 10minutes then the screen freezes and my PI3 isn´t responding via ssh and has to be hart rebooted.
No one is going to know if there is some problem unless they happen to have done exactly the same things you are doing. But clearly the answer is to debug your program.

Question number one, what line in your script is causing the problem, if it is really the script at all. Maybe you've got a hardware problem or something else in some other software is messed up.

So debug it by removing pieces that seem most likely to be a problem and see if the problem still occurs. You can't do this so easy if it takes days to crash but your claim is five minutes. Remove the bluetooth pings and see what happens. Does it still blow up?

Let's say you find out it is the bluetooth that kills everything. That's huge because then you can ask a question about bluetooth and not a question about your program, which only you have any experience with. Or better, first google about the topic to see if others are having bluetooth ping lock up problems on the pi, probably have to ask more generally but maybe not.

Leaving aside the logic in trying to find out if you are home every five seconds in order to save money by turning off a monitor. Why not every five minutes? Even if you feel like you need to turn the monitor on more quickly when you get home and can't just wiggle the mouse, at least *test* with a longer delay. You want to start to get a feel for why the system is blowing up when you bluetooth ping, if that's what is happening.

User avatar
DougieLawson
Posts: 39303
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Raspi crashes in while loop

Fri Mar 11, 2016 8:52 am

stderr wrote:... at least *test* with a longer delay. You want to start to get a feel for why the system is blowing up when you bluetooth ping, if that's what is happening.
This is a good suggestion, with a longer delay does it take longer before it dies? Try with a shorter delay, does it die quicker?
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

User avatar
RaTTuS
Posts: 10563
Joined: Tue Nov 29, 2011 11:12 am
Location: North West UK
Contact: Twitter YouTube

Re: Raspi crashes in while loop

Fri Mar 11, 2016 9:01 am

why sudo ping ?
How To ask Questions :- http://www.catb.org/esr/faqs/smart-questions.html
WARNING - some parts of this post may be erroneous YMMV

1QC43qbL5FySu2Pi51vGqKqxy3UiJgukSX
Covfefe

diy-guy
Posts: 5
Joined: Wed Mar 09, 2016 7:29 pm

Re: Raspi crashes in while loop

Fri Mar 11, 2016 10:55 am

thanks for you help.
meanwhile i found out that it is clearly the l2ping that crashes my Pi. If the delay between the ping is longer it just takes longer to freeze my device. I just move the problem to an later point but does not solve it with an delay of 5min.

But this error seems to be prominent and well known since 2002 (here i found the first problems whith freezing devizes while l2ping an MAC adress)

https://groups.google.com/d/msg/openhab ... PNS9IcJhwJ
viewtopic.php?p=410269#p410269

Poorly none of them found an solution for this problem. Maybe an Problem with BlueZ stack?

Aydan
Posts: 729
Joined: Fri Apr 13, 2012 11:48 am
Location: Germany, near Lake Constance

Re: Raspi crashes in while loop

Fri Mar 11, 2016 11:08 am

See if you can use bluetoothctl scan instead of l2ping.

User avatar
DougieLawson
Posts: 39303
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Raspi crashes in while loop

Fri Mar 11, 2016 12:39 pm

RaTTuS wrote:why sudo ping ?
Because ping as a non-privileged user was badly broken for a while. Latest version is fixed.
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

diy-guy
Posts: 5
Joined: Wed Mar 09, 2016 7:29 pm

Re: Raspi crashes in while loop

Fri Mar 11, 2016 8:47 pm

You should reproduce this error by yourself if you do a simple floodping for a few minutes:

sudo l2ping -f 12:23:34:45:56:67

it takes about 2min until my Raspberry Pi crashes while pinging my iPhone.

you can find your MAC Adress via

hcitool scan (make sure your BT device is in pairing mode)

Return to “General discussion”