View Single Post
Posts: 61 | Thanked: 64 times | Joined on Oct 2007 @ EU
#14
@peterleinchen, thanks your application works fine.

However, if you have some experience with switching SIMs, maybe you can help with the following use case: I want to switch to SIM2, synchronize Exchange and then switch back to SIM1, all of this with Alarmed application that runs regularly the below script.

For some reason, if I am using in script the code "sudo /opt/sim-switcher/phonet-helper down and then up", the phone remains with SIM2, and when I am trying some call I get "Call not allowed" message. Only after I am running from command line "sudo killall csd" I can switch back to SIM1.

If instead of phonet0 down I am using "run-standalone.sh dbus-send --system --print-reply --dest=com.nokia.csd.Call /com/nokia/csd/call com.nokia.csd.Call.Release", the script switches fine to SIM2, sync and back to SIM1, but after a few runs, I still get to the above situation.

Any help with this would be appreciated. Thanks.

Code:
#!/bin/sh

CONNECTED=false
DROPCONN=false

# check for existing wifi connectivity
if [ "$(/sbin/route | awk '/au/ {print $1}')" == "default" ]; then
  CONNECTED=true
else
  #Bring up WLAN
  sudo ifconfig wlan0 up
  for i in WLAN1 WLAN2 WLAN3
  do
    # scan for SSIDs, if not found continue
    if [ -z `sudo iwlist wlan0 scan | grep -m 1 -o \"$i\"` ]; then
      continue;
    fi
    # find IAP_ID from SSID
    IAP_ID=`gconftool-2 -R /system/osso/connectivity/IAP | tac | awk "/name = $i/,/connectivity\/IAP/" | awk -F '/|:' '/connectivity\/IAP/{ print $6}'`
    # try to connect to known wifi
    run-standalone.sh dbus-send --system --type=method_call --dest=com.nokia.icd /com/nokia/icd com.nokia.icd.connect string:"$IAP_ID" uint32:0
    sleep 20
    if [ "$(/sbin/route | awk '/au/ {print $1}')" == "default" ]; then
      CONNECTED=true
      DROPCONN=true
      break
    fi
  done
  # if no WLAN was found (i.e. outdoor), then put WLAN down
  if [ "$DROPCONN" == "false" ]; then 
    sudo ifconfig wlan0 down
  fi
fi

if [ "$CONNECTED" == "true" ]; then
  # sync erminig if having connectivity
  #/usr/bin/erminig -a

  # sync MfE
  run-standalone.sh dbus-send --print-reply --type=method_call --session --dest=com.nokia.asdbus /com/nokia/asdbus com.nokia.asdbus.sync

  sleep 90

  # drop the wifi connection if it was initiated by this script (saves battery)
  if [ "$DROPCONN" == "true" ]; then
    run-standalone.sh dbus-send --system --dest=com.nokia.icd /com/nokia/icd_ui com.nokia.icd_ui.disconnect boolean:true
  fi
else
  # Try with SIM2
  opcode1=`run-standalone.sh dbus-send --system --print-reply=literal --dest=com.nokia.phone.net /com/nokia/phone/net Phone.Net.get_registration_status | tr '\n' ' ' | awk '{print $8,$10}' | cut -f1 -d' '`
  #echo $opcode
  # if operator code is SIM1 (1) switch to SIM2 (10)
  if [ $opcode1 == 1 ]; then
    run-standalone.sh dbus-send --system --dest=com.nokia.csd.Call --type=method_call --print-reply /com/nokia/csd/call com.nokia.csd.Call.CreateWith string:"002" uint32:0
    sleep 1
    #run-standalone.sh dbus-send --system --print-reply --dest=com.nokia.csd.Call /com/nokia/csd/call com.nokia.csd.Call.Release
    sudo /opt/sim-switcher/phonet-helper down
    sleep 7
    sudo /opt/sim-switcher/phonet-helper up
    sleep 22
  fi
  opcode2=`run-standalone.sh dbus-send --system --print-reply=literal --dest=com.nokia.phone.net /com/nokia/phone/net Phone.Net.get_registration_status | tr '\n' ' ' | awk '{print $8,$10}' | cut -f1 -d' '`
  # if operator code is SIM2 (10)
  if [ $opcode2 == 10 ]; then
    # Connect to SIM2 Internet
    echo "Connect SIM2 Internet"
    run-standalone.sh dbus-send --system --type=method_call --dest=com.nokia.icd /com/nokia/icd com.nokia.icd.connect string:"SIM2 Internet" uint32:0
    sleep 30
    # Sync emails
    echo "Start Sync"
    run-standalone.sh dbus-send --print-reply --type=method_call --session --dest=com.nokia.asdbus /com/nokia/asdbus com.nokia.asdbus.sync
    sleep 104
    # Disconnect SIM2 Internet
    echo "Disconnect SIM2 Internet"
    run-standalone.sh dbus-send --system --dest=com.nokia.icd /com/nokia/icd_ui com.nokia.icd_ui.disconnect boolean:true
    sleep 8
  
    # Switch to SIM1
    if [ $opcode1 == 1 ]; then
      run-standalone.sh dbus-send --system --dest=com.nokia.csd.Call --type=method_call --print-reply /com/nokia/csd/call com.nokia.csd.Call.CreateWith string:"001" uint32:0
      sleep 1
      #run-standalone.sh dbus-send --system --print-reply --dest=com.nokia.csd.Call /com/nokia/csd/call com.nokia.csd.Call.Release
      sudo /opt/sim-switcher/phonet-helper down
      sleep 7
      sudo /opt/sim-switcher/phonet-helper up
    fi
  fi
fi
 

The Following User Says Thank You to yrannadx For This Useful Post: