Skip to content

l2ping freezes Raspberry

For the presence detection of my Smart Mirror I would have liked to use a Bluetooth ping via l2ping with the on-board means of my Raspberry to detect the presence of my Smartphone or my girlfriend and thus switch the HDMI port of the screen on or off.

The principle is actually simple. One determines the Bluetooth MAC address of the Bluetooth device to be recognized and requests this device at regular intervals via l2ping. If it reports back, the person is present and the HDMI port can remain switched on.

The nice thing about l2Ping is that the Smartphone/Wearable or similar does not have to be connected to the Smart Mirror. The Bluetooth of the devices only has to be activated. A big comfort gain compared to a permanent pairing.

Unfortunately there seems to be something wrong with the Raspberry Bluetooth Stack “bluez”. Single requests via l2ping are processed properly after a lot of requests the Raspberry Pi freezes completely sometime, so that only the power source can be disconnected.

The simple l2ping with parameter -f (Floodping) is enough for me to freeze the system after some time.

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

It takes me about 350 requests until the Raspberry freezes completely.

Unfortunately, I’m not the only one who has this problem. There are already some reports in home automation forums that people would like to use the l2ping command to control presence detection, but unfortunately, depending on the frequency of pings, the devices will freeze at some point.

I’m not a C-programmer and can therefore only guess what’s wrong here but a point in the source code of bluez-l2ping seems suspicious to me.

A new socket is created for each request, but is only closed in the event of an error:


So if the Bluetooth device is within range, the socket handler will eventually run full (my guess). I wrote to the developers of the l2ping and described the problem, but how and whether the problem can be solved is still in the stars. l2ping is unfortunately not (yet) suitable for a presence detection for home automation.


I thought with Python I had found another way to detect a Bluetooth device. And with the help of:

import bluetooth

while True:
    result = bluetooth.lookup_name('12:23:34:45:56:67', timeout=5) 
    if (result != None): 
        print "Gerät da" 
        print "Gerät nicht da"

Unfortunately, this script also freezes the Raspberry. In the background the stack of bluez is probably used.

Do you like the post?

Subscribe to the newsletter and receive at irregular intervals summarizing newsletters with the latest contributions. I keep it minimalistic. Promised.
Leave a Reply

Your email address will not be published. Required fields are marked *