Starting sakis3g from an rc.d script

Have been working on The Duke’s brain today.  Needed to get the mobile internet connection to start automatically when the Raspberry Pi boots.  I’m using a Huawei E220 dongle with a Giff Gaff SIM. The easiest way to get it connected to the internet is to use the fantastic sakis3g script.

The best way to get anything to run at startup is with an rc script, but even after searching for some time I couldn’t find any examples.  So here’s one I crafted myself, in case anyone finds it useful. Obviously you’ll have to change the “ARGS” line to set the correct APN and so on for your connection.  You’ll also need to copy the sakis3g script itself to /usr/sbin.



. /etc/rc.conf
. /etc/rc.d/functions

ARGS="APN=\"CUSTOM_APN\" CUSTOM_APN=\"\" FORCE_APN=\"\" APN_USER=\"giffgaff\" APN_PASS=\"password\""

PID=$(get_pid sakis)

case "$1" in
   stat_busy "Starting sakis"
   [ -z "$PID" ] && /usr/sbin/sakis3g connect $ARGS &>/dev/null
   if [ $? = 0 ]; then
     add_daemon sakis
     exit 1
   stat_busy "Stopping sakis"
   /usr/sbin/sakis3g disconnect &>/dev/null
   if [ $? = 0 ]; then
     rm_daemon sakis
     exit 1
   $0 stop
   sleep 1
   $0 start
   echo "usage: $0 {start|stop|restart}"

This can be started from rc.conf by adding “sakis” toi your daemons line.


DAEMONS=(!hwclock syslog-ng @network @net-profiles @dhcpd @openntpd @netfs @crond @sshd @samba @sakis)

There are some downsides to using sakis3g for connecting to the internet though – especially for my project.  I have both a 3g and a WiFi dongle attached to the RaspberryPi, but sakis sets up the routes in such a way once you’re connected via the mobile network, you always route that way.  Even though the wireless is faster, when I run a package upgrade or download a file it comes over 3g, not WiFi.  Worse than that, if you stop sakis, it doesn’t restore your routes, so you can’t connect to the internet at all without issuing some route commands.

2 thoughts on “Starting sakis3g from an rc.d script

  1. Hello, i am a beginner in Raspberry Pi and electronic. I see on the picture big battery, i have the same ane would like to use it to power on Pi. Please tell me how do you convert 12V into 5V, what kind of stuff did you use etc… Thanks in advance for answer.

    • I used a cheap “12v to 5v” converter I found on eBay! I won’t recommend the specific model because it failed after a few weeks, however, there are many available.

      You can buy a small Linear 5v regulator which will drop 12v down to 5v but will need a large heat sink and will run the battery down quickly. Better to use a “switch mode” regulator which won’t need the heat sink and (because it doesn’t waste poower generating heat) will give better battery life.

Leave a Reply

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