[サイバー.net]

← back

Banana Pi with no sleep

When I was building weird things with my Banana Pi Zero 2 I noticed that it often loses the Wi-Fi connection.

Quite annoying.

After endless back and forth in the network settings I found somewhere on the net a way to solve it differently. Which was not quite optimal, so I had to find another solution.

It's a brutal solution and definitely not a real solution either, but it works.

A cronjob checks every minute if the Wi-Fi is still active, if it is not active, it is turned on again. Of course, this is not done by the cronjob alone, you have to create a small script.

And this is how you can prevent your Banana Pi from sleeping, at least you can prevent the Wi-Fi from sleeping.

Create a new file under vi /usr/local/bin/nosleep.sh on your Banana Pi.

ping -c4 192.1.1.1 > /dev/null

if [ $? != 0 ] 
then
  /sbin/ifdown 'wlan0'
  sleep 1
  /sbin/ifup --force 'wlan0'
fi

Replace the IP 192.1.1.1 with the IP from your modem/router.

To allow the script to do something we need to create the permissions.

sudo chmod 775 /usr/local/bin/nosleep.sh

Now we are almost done, now we create a cronjob which checks every minute if the wi-fi has gone out, we can solve this with the following command:

*/1 * * * * /usr/bin/sudo -H /usr/local/bin/nosleep.sh >> /dev/null 2>&1

The check now runs every minute, if this is too much you can replace the 1 with e.g. a 5 for every 5 minutes.

By the way, the script works not only on a Banana Pi but on almost everything that has a Wi-Fi chip.

System (システム)

netdir://サイバー.net → Banana Pi with no sleep

< OBEY THE SYSTEM Webring > Mastodon