How to establish a 3g mobile broadband autoconnection/ reconnection on Linux

TRY SOLUTION 3: IT IS WORKING PERFECTLY
 
Solution 1:

1- create a shell script as follows (Replace "Tunisie Télécom / TUNTEL WEB DATA" with the name of your Mobile Broadband connection):


 
#!/bin/bash

while true; do
    LC_ALL=C nmcli -t -f TYPE,STATE dev | grep -q "^gsm:disconnected$"
    if [ $? -eq 0 ]; then
        #jdownloader is still in the download status so stop it because
        #internet is disconnected and jdownloader won't resume download
        #when connected again
        #jdownloader --stop-download
        #sometimes I can not get connected after disconnection when
        #I click on . I have to disable
        #and enable Mobile Broadband
        nmcli -t nm wwan off
        sleep 1
        nmcli -t nm wwan on
        sleep 1
        nmcli -t con up id "
YourMobileBroadbandConnectionNameHere"
        #wait approximately 15 sec to get connected
        #if anyone can add better command to check for it just comment it :-p
        sleep 15
        #now connected to internet so start download
        #jdownloader --start-download
    fi
    #it does not worth keep it checking every millisecond.
    #my connection will be reestablished within 5-15 seconds
    sleep 2
    #if anyone can code it better please feel free to comment
    #TO-DO:: check for data received. if data < 15 KB after 20 seconds of connection
    #reconnect mobile broadband connection
done



you may download here download 
2- Save it and give it execution permission then add it to Startup Applications.
 




Now it will connect automatically at startup and if connection is dropped.



 Solution 2 :same thing another method
                                                      
1- get the a readymade script    download
2- extract it to your home folder (or somewhere safe) and make it hidden by placing a period before it like this .network-autoconnection.sh (so that you won't accidently delete it)

3- Give it execution permission like this: rightclick on it, go to "properties", then navigate to "permissions" then tick "Allow executing file as program"
4- go to the Mint menu and type "startup applications"


5- click on "add" then "browse" opposite to "command" field to give the directory of the script (your home folder or wherever you've placed it) then give it a name in the "name" field, for example mine is "Reliance smart WAP"

finished

 solution 3:

1. Setup a new Mobile Broadband Connection and connect.

  • After you have set up a new Mobile Broadband Connection it will appear in the network connections (click on taskbar network icon).
  • In this case our new connection name is : Reliance smart WAP
  • Connection 'name' should contain only alpha-numerical characters and no spaces to avoid problems.
  • Make sure the "Enable Mobile Broadband" is activated. (see below)
  • Connect to the internet with your Mobile Broadband connection by clicking on the connection name. In this case Reliance smart WAP
  •  


2. Create a Network Manager CLi startup script for your connection.

  • Open the Terminal Window and enter :
sudo gedit /etc/init.d/mobile-broadband-connect
 
#!/bin/sh
# CD Mobile Broadband Startup Service script v2.0 beta by CD May 2012
# acts as startup service script for nmcli to fire up Mobile Broadband Connections
# user the name of the Mobile Connection as defined in the Network Manager as the 'id' 
# USAGE: start|stop|status
#
### BEGIN INIT INFO 
# Provides: mobile-broadband-connect 
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Should-Start: $network
# Should-Stop: $network
# Default-Start: 3 4 5 
# Default-Stop: 0 1 6 
# Short-Description: Autoconnect 3G GSM
### END INIT INFO

NAME="mobile-broadband-connect"
DESC="Autoconnect 3G/4G GSM USB modem at startup"

test -x $DAEMON || exit 0

case "$1" in
 start)
    echo "[MBC] *** Starting Mobile Broadband Connection."  
    while true; do
        # Waiting for GSM modem adaptor...
          LC_ALL=C nmcli -t -f TYPE,STATE dev | grep -q "^gsm:disconnected$"
          if [ $? -eq 0 ]; then   
          # now gsm detected, run the script
             echo "[MBC] GSM Modem Detected - attempting auto connect" 
       nmcli -t con up id YourMobileBroadbandConnectionNameHere
          echo "[MBC] GSM Modem connecting ....."
             # we want the script to loop forever and 
             # check if the connection is down
             # but we need to give it a chance to connect or 
             # the modem will attempt to connect in an endless loop so we 
             # give a 30 second break to make sure it is not connected 
          echo "[MBC] Hopefully connected now... sleeping for 30sec"            
          sleep 30
       else
          # GSM device not detected yet or GMS device already connected - sleep 
          echo "[MBC] MBC still running - sleeping for 10....." 
          sleep 10
        fi
       done
 ;;
 stop)  
       echo "[MBC] Stopping Mobile Broadband Connection."  
       nmcli -t con down id YourMobileBroadbandConnectionNameHere
       ps aux | grep "mobile-connection-connect-2.0.sh start" | grep -v grep | awk '{print $2}' | xargs kill -9
       #nmcli -t nm wwan off 
 ;;
 status)
       # Check network status with nmcli 
       nmcli -p dev
 ;;
 
 *)
    echo "[MBC] Mobile Broadband Startup Service"
       echo $"Usage: $0 {start|stop|status}"
       exit 1
esac
exit 0
 
 
 
  • Add the following into the startup script file and save with name : mobile-broadband-connect.sh
  • Note: Replace the YourMobileBroadbandConnectionNameHere with the name of your connection. In this case our service provider is:Reliance smart WAP
  • Note: If you do not see a codeblock right below this text or see a small empty box before step 3 - please reload this page.

​3. Change the startup script file permissions.

  • By default a new file is not allowed to be executed - so we need to modify the permissions to allow us to run the script at startup..
  • Open the Terminal Window and enter :
     sudo chmod +x /etc/init.d/mobile-broadband-connect

​4. Update system startup defaults to include your new script as a service.

  • To update the startup services, open the Terminal Window and enter :






sudo update-rc.d mobile-broadband-connect defaults
  • The script is registered as a system startup service so you can start, stop, or check the status of the script with :
  •  
sudo service mobile-broadband-connect start
sudo service mobile-broadband-connect stop
sudo service mobile-broadband-connect status

​5. Reboot to complete installation and auto connect.

  • Reboot your system to complete the installation.
  • After reboot it takes up to 60 seconds before the USB device is active.
  • When active - The Mobile Broadband Connection will be activated and auto connected.

6. Troubleshooting.

  • If it does not connect on startup the most likely problem is that the connection is not available to all users at startup.
  • Click on "Edit Connections..." in the Network Connections Manager dialog window, select Mobile Broadband, select your connection, and click on "Edit".
  • Make sure that the "Available to all users" is selected and click on Save
 

Comments

Popular posts from this blog

how to install internet download manger in linux

ImportError: DLL load failed while importing onnx_cpp2py_export

awstats with www