maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   Applications (https://talk.maemo.org/forumdisplay.php?f=41)
-   -   [Announce] SIM-Switcher, automated switching with a double ( dual ) SIM adapter (https://talk.maemo.org/showthread.php?t=85722)

peterleinchen 2012-07-26 22:50

[Announce] SIM-Switcher, automated switching with a double ( dual ) SIM adapter
 
5 Attachment(s)
Having participated in the 2012 Coding Competition (wiki).
It seems you really use/like this little tool or thought it is worth a vote, as it got enough votes to make it second place in both categories
Others, result
and
Beginners, result.


Update:
SIM-Switcher is now in Extras repository,
thank you all for using/testing/feedbacking/voting! :)

Download statistics.

So, here is my very first own thread with a nice tool for everybody running a two SIM adapter in his/her N900.
I do call them Double-SIM, as Dual-SIM naming pretends to have both SIM online, which is not possible with these adapters.

As already stated in this thread there is the possibility to switch the SIM online without rebooting.

Some time went by since this approach and I made some improvements to my solution.

Functionality:
- switch the SIM with one "app" icon click
- 'refresh' hildon-home (to update the operator name)
- choose the cell mode (2G/3G/Dual)
- choose the connection policy, i.e. always ask, any connection, only WLAN, default GPRS connection
- connect to a specific InternetAccessPoint (created via fAPN)
and (badly desired by me and took me ages to find out) you may
- set/unset call forwarding for current SIM and for the SIM you will switch to

All done with one-click (from menu).
--edit You may also add a shortcut to your desktop via the the desktop menu. Or use it with DCEW (same as command line usage, see) or use it with QBW (see here). edit--

Your adapter will need to support the so called 007 mode, i.e. the switching needs to be executed by calling a number (like 001, **1, 11*, 1#, ...).
I have a GDI3SG (fully UMTS compatible) without any effects on battery.
Mine has some characteristic/flaw to activate always the second SIM, when the same number is called (is handled in script).


After installation, use vi nano txpad leafpad or any other editor of your choice and edit
(/home/user/).config/sim_switcher/SIM1
and
(/home/user/).config/sim_switcher/SIM2
to your liking.
At least you need to give the switching code.


So, that's it for now.

Here is the deb package. It is also my very first package, so be gentle with me ;) I made it manually. Installed/removed/installed it on my device and everything fine. (will leave it attached, although in repo is newer/latest version)
Ah, one more: of course this package depends on starhash-enabler, so please install if you do not have already. (repo package has dependency)

I do not expect many users out there with a Double SIM adapter in N900. That is the reason I do attach the DEB directly here and not in the repos (and I do not know how to do that ;)).
But if I get some response here, I will do so ....

Nevertheless here is the package page. So if you like to vote for it (do not forget to log into maemo.org or you will not see the thumb up, as I always do ;)).


Happy switching.



-- edit 1
Giveaway functionality:
- saving and restoring plugins/widgets/desktop
sometimes necessary after crash/kill of hildon-home (seldom hildon-desktop). In x-term call
Code:

sim-switcher savehome
to save your layout (automatically done on installation) and
Code:

sim-switcher restorehome
to restore your layout after sth has gone wrong badly.
--

--edit 2
Upgrade from Pre-Announce to Announce (put into repos).
--

--edit 3
Now in extras-testing with updated version,
possible to set the operator name on desktop icon.
Vote
--

--edit 4
New version with online check before starting the switch.
This is needed to not run the full tasks if not connected, could lead to bad call forwarding settings (esp. if SIMs are from same network. This infinite loop may be canceled via command-line 'sim-switcher break'.
Automatic call of editor on first start.
Vote
--

--edit 5
Important Notice
Please use only version >=0.5.10 for installation!
Otherwise you may experience strange/odd behaviour, see here for more details.
Sorry!
Vote.
--

--edit 6
New stable version 0.5.12 in testing.
Please vote for this version.
--

--edit 7
Version 0.5.12 is now in Extras repository.
--

-- edit 8
New stable version 0.6.5 in Extras-Testing.
Please vote for this version again.
--


This is it's icon:
http://talk.maemo.org/attachment.php...1&d=1346449525
And here are some screenshots (mainly popup messages, as it has no GUI):

sifo 2012-07-26 23:09

Re: [Pre-Announce] SIM-Switcher (automated switching with a double ( dual ) SIM adapter)
 
Thank you :)
and nice start ;)

nkirk 2012-07-27 07:53

Re: [Pre-Announce] SIM-Switcher (automated switching with a double ( dual ) SIM adapter)
 
I appriciate your effort. though i wanted this feature a couple of years ago when i realized phone was missing sim toolkit support. Good work..

/nkirk

seanmcken 2012-07-27 09:08

Re: [Pre-Announce] SIM-Switcher (automated switching with a double ( dual ) SIM adapter)
 
for the people who cant buy please give some advice.
thanks in advance

reinob 2012-07-27 09:13

Re: [Pre-Announce] SIM-Switcher (automated switching with a double ( dual ) SIM adapter)
 
Quote:

Originally Posted by seanmcken (Post 1243671)
for the people who cant buy please give some advice.
thanks in advance

buy what? a double-SIM adapter?
if you can't buy that, then the advice would be to ignore this thread?!

seanmcken 2012-07-27 09:28

Re: [Pre-Announce] SIM-Switcher (automated switching with a double ( dual ) SIM adapter)
 
alright im sorry?

seanmcken 2012-07-27 09:29

Re: [Pre-Announce] SIM-Switcher (automated switching with a double ( dual ) SIM adapter)
 
i meant give some advice to build that adapter for people who cant buy this adapter

Hurrian 2012-07-27 10:31

Re: [Pre-Announce] SIM-Switcher (automated switching with a double ( dual ) SIM adapter)
 
Quote:

Originally Posted by seanmcken (Post 1243681)
i meant give some advice to build that adapter for people who cant buy this adapter

You probably can't. If you could, you'd be welcome at a robotic assembly facility.

IIRC these things simply have a SIM electrical pad, with a microcontroller hooked up to two SIMs at the same time, and simply switches signal lines between them.

Sounds simple enough, until you see how much space you can't work with.

peterleinchen 2012-07-27 11:32

Re: [Pre-Announce] SIM-Switcher (automated switching with a double ( dual ) SIM adapter)
 
Quote:

Originally Posted by nkirk (Post 1243649)
though i wanted this feature a couple of years ago

Sorry for being late (but simple solution was available since last year, see above linked thread).

Quote:

Originally Posted by nkirk (Post 1243649)
phone was missing sim toolkit support. .

Yes, there is no STK in N900, so your adapter needs to support "007" mode for this tool (just for clarification).

nkirk 2012-07-27 18:56

Re: [Pre-Announce] SIM-Switcher (automated switching with a double ( dual ) SIM adapter)
 
No need for apologies "peterleinchen" i just typed what i felt when i saw the title and how simple & easy this app was. I was using 2 lines on a single sim before switching to N900, I missed that feature badly and I had to settle for a single primary connection because of the absence of stk.

/nkirk

Estel 2012-07-28 00:07

Re: [Pre-Announce] SIM-Switcher (automated switching with a double ( dual ) SIM adapter)
 
Nice work, peterleinchen! It just *begs* for being in repositories :)

peterleinchen 2012-07-28 17:35

giveaway functionality to save/restore desktop after crash / kill of hildon-home (hildon-desktop)
 
Added following comment (forgotten on OP):

Giveaway functionality:
- saving and restoring plugins/widgets/desktop
sometimes necessary after crash/kill of hildon-home (seldom hildon-desktop). In x-term call
Code:

sim-switcher savehome
to save your layout (automatically done on installation) and
Code:

sim-switcher restorehome
to restore your layout after sth has gone wrong badly.


There may follow more ... ;)

peterleinchen 2012-08-06 21:27

Re: [Pre-Announce] SIM-Switcher (automated switching with a double ( dual ) SIM adapter)
 
Quote:

Originally Posted by Estel (Post 1243973)
Nice work, peterleinchen! It just *begs* for being in repositories :)

Your wish is my command !

You may find it now in the repos (atm devel, promoted to testing).

yrannadx 2012-08-10 09:16

Re: [Announce] SIM-Switcher (automated switching with a double ( dual ) SIM adapter)
 
@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


peterleinchen 2012-08-10 10:56

Re: [Announce] SIM-Switcher (automated switching with a double ( dual ) SIM adapter)
 
New version in testing.
Added parameter "oper" in config file to add the operator name for specific SIM. Will be shown as name for desktop icon.
Keep it short, less than 9 chars, and please do NOT use blanks (but put underlines or such, e.g. "VF_de" instead of "VF de") in that parameter.

peterleinchen 2012-08-10 13:25

Re: [Announce] SIM-Switcher (automated switching with a double ( dual ) SIM adapter)
 
@yrannadx
Nice one, too.

I can only think of timing problems, maybe the 7 seconds is not enough between down and up. I had same problesm, but after setting to 7 seconds it always worked out for me. Do you have high loads?

And the CallRelease just ends the call, no more. It may be there, but it is not needed, as shutting down phonet0 is doing the same (OK, almost).
Shutting down the telephony system (and enabling again) will bring up the switch. So I am curious how you are able to switch without bringing down?

Oh and one more about timing. Maybe also increase he sleep between bringing up the call and shutting down. Maybe your adapter needs more time to detect ...

Either way let me know, to make mine more stable, please.
But you said my method works for you?


Oh and about 'killall csd': that was my first very early approach and it worked out. But after a few switches I ran into troubles also (do not remember exactly, but I think it was about internet connectivity / telephony unavailable).

--
Maybe found your issue: imagine going into your script with SIM2 active! Then opcode1 will be 10 and opcode2 will be 10 also. So at the end of script there is no instruction to switch back to SIM1 ...

yrannadx 2012-08-21 09:43

Re: [Announce] SIM-Switcher (automated switching with a double ( dual ) SIM adapter)
 
@peterleinchen

Maybe it depends of SIM adapter. My one is Magicsim 28th and the switch actually works fine just by using CallRelease without calling phonet0 down and up. But of course the SIM switch works also with your method, phonet0 down and up, as well as with killall csd.

I tried different timings and so on and it was not working. The new code that seems to work is to use CallRelease after calling the switch code and using once the phonet0 down and up after "Disconnect SIM2 Internet" command. Maybe connecting and disconnecting the internet is the problem that prevented the switch back to SIM1 after that.

if opcode1 is 10 and opcode2 is 10 also, then that is the intended behavior of the script, to remain with SIM2 and not to switch back, so I think the script is OK.

I will try for few days the new code to see if it works after several switches combined with normal phone usage.

Code:

  # 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
    sleep 20
  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 1
    sudo /opt/sim-switcher/phonet-helper down
    sleep 7
    sudo /opt/sim-switcher/phonet-helper up
    sleep 20
 
    # 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
    fi
  fi
fi


peterleinchen 2012-08-21 22:00

Re: [Announce] SIM-Switcher (automated switching with a double ( dual ) SIM adapter)
 
@yrannadx

If it is intended (not go back to SIM1, if started withSIM2) then it seems OK.

Let me guess: you do not have PIN code enabled on second SIM, but you do have on SIM1?
In that case the switching to SIM2 occurs immediately after the call release. And a phonet down/up is not necessary (but do not harm either).
So in that/your case just omit down/ups for switch to second SIM and it should work. But it should work also with my approach. What about using command line 'sim-switcher SIM1' in your script (in config file only the switch code)?

So in short:
Never use killall csd, it will create internet (access point) problems.
If there is no PIN code query enabled, switching occurs without any interaction (but it works with my method, too).

-- more edit
I have some extension ready to let my script wait if there is no cell radio connection available. In my case I do need the SIM to be online to successfully switch. Please let me know if that is valid for your adapter too (go into offline mode and dial 002 and see if the SIM switches, I expect not).

yrannadx 2012-08-23 12:50

Re: [Announce] SIM-Switcher (automated switching with a double ( dual ) SIM adapter)
 
@peterleinchen

Actually none of the SIMs have PIN code enable so that's the explanation.

On the other hand, it seems none of the methods are working after all. Nor my above attempts, nor calling 'sim-switcher SIM1 and 2' in the script. It is strange why first attempt of running the script succeeded (when using sim-switcher) and second attempt fail with SIM2 remaining active and when I am trying a normal call with SIM2 I get call not allowed (although your script display wrongly the message of successfully switch). This means also that switching back to SIM1 is not possible without using killall csd or reboot. Maybe the sync is causing this strange behavior, otherwise I see no logical explanation for this.

The next method I will try is to separate totally the actions of switch SIM and sync, i.e. to switch first the SIM 3 minutes before the sync with Alarmed, do the sync and switch back 3 minutes after the sync with Alarmed as totally independent actions.

Regarding your note, I cannot dial 002 in offline mode to switch SIM.

peterleinchen 2012-08-23 20:28

Re: [Announce] SIM-Switcher (automated switching with a double ( dual ) SIM adapter)
 
Hey yrannadx,

one question at first:
my app is working for you? So using sim-switcher switches from SIM1 to SIM2 and vice versa?

How do you verify your script dows not switch back to SIM1?
Do not rely on operator name shown on hildon-home!


In your script there is some flaw, which should not cause your behaviour, but who knows?

Switch your code to:
Code:

.
.
.
    # 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
 
    # 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
    sleep 1
    sudo /opt/sim-switcher/phonet-helper down
    sleep 7
    sudo /opt/sim-switcher/phonet-helper up
    sleep 20
    fi
  fi
fi

or maybe:
Code:

.
.
.
    # 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
 
    # 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
#    sleep 1
#    sudo /opt/sim-switcher/phonet-helper down
#    sleep 7
#    sudo /opt/sim-switcher/phonet-helper up
#    sleep 20
    fi
  fi
fi


Crogge 2012-08-23 21:14

Re: [Announce] SIM-Switcher (automated switching with a double ( dual ) SIM adapter)
 
Great work, I always wanted to use my business SIM in my beloved N900. Is there any compatibility list which adapters are working / fitting into the N900?

peterleinchen 2012-08-23 21:21

Re: [Announce] SIM-Switcher (automated switching with a double ( dual ) SIM adapter)
 
New version 0.4.1 out.

As yrannadx confirmed the necessity of cell modem to be online, I added some check and an infinite loop until first connectiion, then the switch starts. This may be canceled via command-line 'sim-switcher cancel'.

changelog
Added direct call of editor for config file without switching code (first start).
Added online check before starting the switch (some adapter needs online status), may be deactivated.
Added new param (stop) to interactively break/cancel a hanging switch (due to not being online).

peterleinchen 2012-08-23 21:29

Re: [Announce] SIM-Switcher (automated switching with a double ( dual ) SIM adapter)
 
Quote:

Originally Posted by Crogge (Post 1255096)
Great work, I always wanted to use my business SIM in my beloved N900. Is there any compatibility list which adapters are working / fitting into the N900?

I do not know of any "list",
but there are two threads on TMO about dual SIM adapters (one linked in first post), maybe check those.
I do use a GDI3SG (perfect, not battery consuming, full UMTS) and yrannadx has the MagicSIM28, so these are at least compatible.
If you find other ones, just come back here ...

Oh, and of course only the cutting adapter really fit. There is some other alternative to use a non-cutting version, but I do not advise, cause of N900 SIM card holder flaw...

imo 2012-08-23 22:47

Re: [Announce] SIM-Switcher (automated switching with a double ( dual ) SIM adapter)
 
something i ever wanted and got it finally,thanks bud,hope you show up with yours other great projects as well.

yrannadx 2012-08-24 08:27

Re: [Announce] SIM-Switcher (automated switching with a double ( dual ) SIM adapter)
 
Quote:

Originally Posted by peterleinchen (Post 1255076)
Hey yrannadx,

one question at first:
my app is working for you? So using sim-switcher switches from SIM1 to SIM2 and vice versa?

How do you verify your script dows not switch back to SIM1?
Do not rely on operator name shown on hildon-home!

Using your app works fine for me. Sometimes I got the message "Please do NOT call me on already selected SIM ($1) !" which I shouldn't, maybe the currentSIM file got messed when using the command in my script. I think maybe the file is not updated when sim-switcher is run inside a script or maybe other reason.

I would suggest an improvement in your application:
- possibility to use your script silently without pop-up messages, e.g. if I want to switch by Alarmed I don't want success messages to be displayed.

I am using a Desktop Command Widget for checking operator name so that to know exactly what operator I am with, with the following script executed:

Code:

#!/bin/sh

opcountry=$(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}')
opcode=$(echo $opcountry | cut -f1 -d' ')
countrycode=$(echo $opcountry | cut -f2 -d' ')
dbus-send --system --print-reply --dest=com.nokia.phone.net /com/nokia/phone/net \
Phone.Net.get_operator_name byte:0 uint32:$opcode uint32:$countrycode | grep string \
| awk '{print $2 " " $3}' | tr -d \"

Also I will check your suggested code improvements although I have doubts this will ever work after so many tests I made.


Update:
I was trying to switch to SIM2 for 10 minutes and then back to SIM1 (e.g. for receiving SMS messages if any), without doing anything else, by using the following simple script two times in Alarmed.

Code:

#!/bin/sh

# Check no call in progress
oncall=`run-standalone.sh dbus-send --system --type=method_call --print-reply=literal --dest=com.nokia.csd.Call /com/nokia/csd/call/1 com.nokia.csd.Call.Instance.GetStatus`
if [ $oncall != "uint32 0" ]; then
  dbus-send --type=method_call --dest=org.freedesktop.Notifications /org/freedesktop/Notifications org.freedesktop.Notifications.SystemNoteDialog string:"No switch while oncall" uint32:0 string:"OK"
  return
fi

# Switch SIM
opcode=`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 from SIM1 switch to SIM2
if [ $opcode == 1 ]; then
  sim-switcher SIM2
else
  sim-switcher SIM1
fi

The first switch went fine to SIM2, but then switch back to SIM1 failed and the phone remained with Operator2. This due to "Call not allowed" message when trying to make any call with SIM2. The same as before, I could switch back to SIM1 only after running killall csd. So it is quite clear that for some reason switching the SIM in any other way than from application icon will fail.

Maybe you could try running such switch back and forth with Alarmed or other meaning with your adapter, after all switching the SIMs for certain period of time from time to time is a valid case for anybody using 2 SIMs.

peterleinchen 2012-08-24 22:23

Re: [Announce] SIM-Switcher (automated switching with a double ( dual ) SIM adapter)
 
Quote:

Originally Posted by yrannadx (Post 1255205)
Using your app works fine for me.

Thanks for confirmation. :)

Quote:

Originally Posted by yrannadx (Post 1255205)
Also I will check your suggested code improvements although I have doubts this will ever work after so many tests I made.

Give it a try, even I do not see it causing it. But ...

Quote:

Originally Posted by yrannadx (Post 1255205)
Sometimes I got the message "Please do NOT call me on already selected SIM ($1) !" which I shouldn't, maybe the currentSIM file got messed when using the command in my script. I think maybe the file is not updated when sim-switcher is run inside a script or maybe other reason.
...
The first switch went fine to SIM2, but then switch back to SIM1 failed and the phone remained with Operator2. This due to "Call not allowed" message when trying to make any call with SIM2. The same as before, I could switch back to SIM1 only after running killall csd. So it is quite clear that for some reason switching the SIM in any other way than from application icon will fail.

This leads me to the conclusion, that your SIM2 somehow does not accept the switch code at that time. There is no check, if the 'call' (switch code) has been excuted, in contrary to your on-call check (which I like to add to my script). Do you know any return codes of dbus, that tell us: "call not allowed"?
If this (call not allowed) happens, then I think the switch is not initiated, but the script continues (sets currentSIM) and thinks everything went fine. So it marks the SIM1 as active, whereas still SIM2 is the active one (explanation for your messages and also behaviour).
One possibility I may think of causing this is the non-ability of your adapter to have internet AND call at the same time (topic: GPRS class A B C). A full UMTS adapter does not care about such limitations.
Was it assured that GPRS internet connection was down before switching back to SIM2? Could you please test this?


Quote:

Originally Posted by yrannadx (Post 1255205)
I would suggest an improvement in your application:
- possibility to use your script silently without pop-up messages, e.g. if I want to switch by Alarmed I don't want success messages to be displayed.

Exactly that I was thinking about this afternoon ;) Almost finished, needs some testing... (uploading to devel ...)
What is your favourite flavour? Be verbose as default or silent?
I would say silent on command line as default and verbose per icon.


I have added the SIM details and furthermore I would like to add the on-call check (it is not necessary for icon app, but for command line usage).
Thanks for your helpful discussion and improving script snippets! :)

Another question here is: I have added a infinte loop to wait for getting online. But without notifications you will not see it, or just by "script execution time/halt". I do not want to make it as param, but have added a file to detect this (see changelog version 0.4.1). So what do you think about this infinite loop?

peterleinchen 2012-08-25 09:05

Re: [Announce] SIM-Switcher (automated switching with a double ( dual ) SIM adapter)
 
New version 0.5.1 uploaded to devel.

changelog:
Added details about SIMs in last popup.
Added oncall check before starting the switch (sim-switcher may not be called during a call).
Deactivated all popups for silent command-line usage. Added new SECOND param (-v / --verbose) to enable popups (default for app icons).
Thanks to yrannadx for tips/hints/snippets.

peterleinchen 2012-08-26 22:40

Re: [Announce] SIM-Switcher (automated switching with a double ( dual ) SIM adapter)
 
And 0.5.2 out (devel).

changelog:
Increased time between down and up (hopefully resolves seldom non-switch prob).
Small modifications regarding output of operator and network codes.
Some corrections regarding call of editor.
Other little code reviews.


@yrannadx
during testnig I also once had this strange behaviour of not being able to switch. I just needed to bring down phonet0 and up it again. Solved.
So as this happened to me also, the only reason I see is time between down and up. I had tested it earlier and tried to make it as short as possible (with some safety marfin). But too short is problematic, so I increased this value. Hopefully this solves your issue, please test and report.


Meanwhile I just rethought that and will make another command line call 'reactivate' to solve this 'call not allowed' issue easily.

And bring version 0.5.3 to devel. Uploaded!
changelog
Added another command line switch to (re)activate a failed switch.

yrannadx 2012-08-27 12:06

Re: [Announce] SIM-Switcher (automated switching with a double ( dual ) SIM adapter)
 
@peterleinchen

This latest version of the script works much better. Seems now that the switch back and forth is successful all the time when run automatically by Alarmed. What's more surprising (really great) in my case is that now I have operator name updated on desktop by default although I am not using refhome.

To answer some other items:

- When I got "call not allowed" I was not using internet at all, just switch and wait 10 minutes and switch back. But now this scenario seems to work, although I cannot tell for sure before running automatically the switch for next few days. Also MagicSim 28th I think is full UMTS.
- Using on-call check in your script is very useful, thanks.
- Silent command line usage is great, thanks.
- I think waiting for getting online is very useful in areas when there is low GSM signal, there might be scenarios when the switch is started in such conditions and signal drops before doing the switch. I have been traveling across low signal area and almost always things messed up, e.g. I arrived at destination with SIM2 active without being aware about that for example.


Update: I can confirm that after several runs, the script works now great, I didn’t got “Call not allowed” not even once since the upgrade. So I can use now the Exchange sync script as I always wanted, thanks.

Some more refine of the script suggested:
- There is an error in command line: “/usr/bin/sim-switcher: line 452: was: not found”, not sure if this is important.
- Check line 335, sleeep is misspelled, although I didn’t notice any change after correcting this line.
- currentSIM method seems is not working OK, I had to delete manually the file so that to be able to make the switch back. Maybe you could use the operator code for this check or something else, or disable the check. At least in my case there is no harm if same SIM is tried to be activated.

peterleinchen 2012-08-27 20:36

Re: [Announce] SIM-Switcher (automated switching with a double ( dual ) SIM adapter)
 
Nice to hear it is working better now. :D
I think the delay between down and up was/is the key!

Thanks for reporting back.
It was late and I sleeepy ;)
Fixed it and putting it as 0.5.4 to devel.

About currentSIM:
it is working flawlessly for me and mine (others adapters?) do need it, so I am going to keep it in (not making it configurable). As the new 'sim-switcher reactivate' almost is the same as activating the current active SIM.
Your switching code is '002' for second SIM and '001' for first SIM, right? Please check your config files for SIM1 and SIM2 again.
Using the op name may not be unique (SIMs from same network).
But please test it again and give me more details, so we may overcome that little beast also :)
And push it further to testing.

yrannadx 2012-08-29 12:26

Re: [Announce] SIM-Switcher (automated switching with a double ( dual ) SIM adapter)
 
One more problem found: from time to time I get the message for the SIM I switched to as "empty string operator name, MNC: 0 and MCC: 0". The message is displayed about one second before having the GSM signal icon in place, thus I assume you are checking these parameters to early for the second SIM.

And finally I think I found the reason sim-switcher script is not always working as scheduled job, despite what I thought earlier that this was solved by increasing the delay between down and up. When running in this way (e.g. through Alarmed), the calls for switching the SIMs might be performed with the phone in some sleep or idle state and thus first switch succeed and switching back fails (due to "Calls not allowed" error). This highly depends on how many hours the phone was in idle state, so that is the explanation sometimes the script succeeded and sometimes fails and then I had to run killall csd to be able to switch back. In this situation, reactivate is not working.

Wondering if you have some idea how to wake up the phone in some state similar with the one when using the script through application icon and put that code in the script? I hope this makes sense.

peterleinchen 2012-08-30 18:31

Re: [Announce] SIM-Switcher (automated switching with a double ( dual ) SIM adapter)
 
@yrannadx

This message needs a huge sleep (for getiing the network code reliable). So I added a 30 s wait. Seems not to be enough in all situations. Especially not using param iap and forw_aft. So I added a infinite loop (no messages/popups) just before that to assure SIM is online before getting/printing network codes.

For your special problem I tried to switch forth and back with an sleepy/idle device and I could not reproduce. So I have no chance to support you here. The only way to get device into "app icon state" would be to unlock, which is not a good idea.
At first I thought it could be some lagging or swapping problem, but I tried with no delay between call and call release and no prob. So I am running out of ideas. Maybe try to do some research with longer sleeping time between call and call release, or add sleep time between call release and phonet down or add a second call/call release or or ...
Or it just may be a flaw of your adapter (like mine has when giving code2 on SIM2 it switches to SIM1). I am sorry to be not more helpful here. But please keep me informed or ask for more support.

--
just queued 0.5.8 to devel
and 0.5.9 (still learning about packaging ;) on device)

yrannadx 2012-08-31 07:39

Re: [Announce] SIM-Switcher (automated switching with a double ( dual ) SIM adapter)
 
@peterleinchen

Thanks, I will check your improved version of the application next week.

However, I still believe there is something wrong with saving data for both files:

/home/user/.config/sim-switcher/.tmp/currentSIM
/home/user/.config/sim-switcher/.tmp/home.plugins

Today I had a situation where home.plugins file was not saved (.tmp directory was empty) and then I didn't got home plugins restored. This would have been very bad if I would not use yesterday savehome command. Maybe you could do a check that the file home.plugins was really saved before killing hildon-home?

Regarding the other problem, I already tried with unlock and the following code is working for me although is not nice. I made it generic so that other users could use it if they will replace WLAN1,2,3 on line 22 with own wlans and then opcode (operator code) for SIM1 on line 58 and 90 from 1 to whatever operator code is in particular case, but this works only if operator code for SIM1 differ from SIM2. Of course if this is useful, the script could be made more generic and add these data that needs to be changed at the beginning of the script.

Code:

#!/bin/sh

CONNECTED=false
DROPCONN=false

call_check ()
{
  # Check no call in progress
  oncall=`run-standalone.sh dbus-send --system --type=method_call --print-reply=literal --dest=com.nokia.csd.Call /com/nokia/csd/call/1 com.nokia.csd.Call.Instance.GetStatus`
  if [ $oncall != "uint32 0" ]; then
    dbus-send --type=method_call --dest=org.freedesktop.Notifications /org/freedesktop/Notifications org.freedesktop.Notifications.SystemNoteDialog string:"Sync dropped due to active call!" uint32:0 string:"OK"
    exit 1
  fi
}

# 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
    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 no wifi try with GPRS
if [ "$CONNECTED" == "false" ]; then
  opcode=`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' '`
 
  # Temporary disable SIM switch
  #opcode=10

  # Check lock state of the phone and unlock
  lock=`dbus-send --system --type=method_call --dest="com.nokia.mce" --print-reply "/com/nokia/mce/request" com.nokia.mce.request.get_tklock_mode|awk -F "\"" '/g/ {print $2}'`
  call_check
  dbus-send --system --type=method_call --dest=com.nokia.mce /com/nokia/mce/request com.nokia.mce.request.req_tklock_mode_change string:"unlocked"

  # if operator code is (1) switch to SIM2
  if [ $opcode == 1 ]; then
    sim-switcher SIM2
    if [ $? -ne 0 ]; then
      exit 1
    fi
  fi
  # Connect Internet
  dbus-send --system --type=method_call --dest=com.nokia.icd /com/nokia/icd com.nokia.icd.connect string:"Internet" uint32:0
  if [ $? -ne 0 ]; then
    exit 1
  fi
  CONNECTED=true
  DROPCONN=true
  sleep 10
fi

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

  # sync MfE
  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
    call_check
    dbus-send --system --dest=com.nokia.icd /com/nokia/icd_ui com.nokia.icd_ui.disconnect boolean:true
  fi
fi

# Switch back to SIM1
if [ $opcode == 1 ]; then
  sim-switcher SIM1
fi

# Lock back if needed
if [ "$lock" == "locked" ]; then
  call_check
  dbus-send --system --type=method_call --dest=com.nokia.mce /com/nokia/mce/request com.nokia.mce.request.req_tklock_mode_change string:"locked"
fi


peterleinchen 2012-08-31 21:32

Re: [Announce] SIM-Switcher (automated switching with a double ( dual ) SIM adapter)
 
IMPORTANT NOTICE:
Quote:

Originally Posted by yrannadx (Post 1258379)
However, I still believe there is something wrong with saving data for both files:

/home/user/.config/sim-switcher/.tmp/currentSIM
/home/user/.config/sim-switcher/.tmp/home.plugins

Yep, sorry!

PLEASE everybody watch out !


I put version 0.5.10 into devel and this one resolves the /home/user problem with root/user rights. There was some strange behaviour (at least I did not know about) with conffiles and root owner. Do not ask more ;) it took me a few versions ...

For everybody having already installed an older version of sim-switcher:
please check owner and rights for /home/user/.config/sim-switcher directory and files. It needs to belong to user, not root.
Make a copy of (or have in mind) your config. And then purge sim-switcher (apt-get purge sim-switcher), enable devel (or wait a few day until I push to testing), and do a install again (sudo apt-get install sim-switcher). I needed do to it twice to have apt set up sim-switcher correctly.
So
Code:

sudo apt-get purge sim-switcher
sudo apt-get install sim-switcher
sudo apt-get purge sim-switcher
sudo apt-get install sim-switcher

will be safe.
If you are asked to keep old or new config files (SIM1 / SIM2), then it is correctly set up. Please answer with yes ('y') to these questions at first install.

For everybody starting with >=0.5.10, you just need to say yes to config files overwriting at first install.

Please excuse this inconvenience, it was due to lack of deb packaging knowledge of mine.

peterleinchen 2012-09-04 19:44

Re: [Announce] SIM-Switcher (automated switching with a double ( dual ) SIM adapter)
 
Package 0.5.10 promoted to testing.

Tiran 2012-09-05 21:54

Re: [Announce] SIM-Switcher (automated switching with a double ( dual ) SIM adapter)
 
Thanks for program SIM-Switcher!
I am sorry for bad English.
I adapter MagicSIM28 also have two SIM one operator (with different tariffs). At switching with SIM1 on SIM2 (and on the contrary) I receive the following message on a screenshot:

http://imageplay.net/img/tya22282718...906_010923.png

Thus any SIM does not work (only I can call with SIM1).
Question: For correct job SIM should be different operators???

Tiran 2012-09-06 08:34

Re: [Announce] SIM-Switcher (automated switching with a double ( dual ) SIM adapter)
 
Quote:

Originally Posted by yrannadx (Post 1254076)
My one is Magicsim 28th

At me too Magicsim 28th. That you have printed in sim = "" (SIM swithing code, as given by your adapter). I have entered 001 and 002, but does not work!
Thanks for the answer!

yrannadx 2012-09-06 11:21

Re: [Announce] SIM-Switcher (automated switching with a double ( dual ) SIM adapter)
 
Quote:

Originally Posted by Tiran (Post 1262014)
At me too Magicsim 28th. That you have printed in sim = "" (SIM swithing code, as given by your adapter). I have entered 001 and 002, but does not work!
Thanks for the answer!

You should try first the SIM switch by simply dialing the number 001 and 002 from phone application. It should work. If not working, maybe you need to enable 007 mode by using another phone (N900 don't have SIM Toolkit support).

Tiran 2012-09-06 13:15

Re: [Announce] SIM-Switcher (automated switching with a double ( dual ) SIM adapter)
 
Quote:

Originally Posted by yrannadx (Post 1262129)
You should try first the SIM switch by simply dialing the number 001 and 002 from phone application. It should work.

I have tried to switch SIM dialling number 001 and 002 of the telephone application, but does not work.

Quote:

Originally Posted by yrannadx (Post 1262129)
If not working, maybe you need to enable 007 mode by using another phone (N900 don't have SIM Toolkit support).

And here is more detailed please! I should insert the SIM-adapter into other phone but how there to switch on a mode 007 and what I there should change??? The mode 007 enable from phone menu??? If it is possible describe these actions more in detail!

peterleinchen 2012-09-06 19:26

Re: [Announce] SIM-Switcher (automated switching with a double ( dual ) SIM adapter)
 
IIRC the MagicSIM needs to be put in 007 mode first by using "any" GSM phone supporting STK. I.e. you will find in the phone menu anywhere (depending on phone model) an entry where to configure the SIM adpter. May it be under STK or Extras or SIM menu or or or.

If you put here your model (not the N900 of course) you should find lots of helpful hints.

As the N900 does not support the STK, SIM-Switcher relies to have the adapter set up to use 007 mode.
Then you need to set these switching codes in the config files.


All times are GMT. The time now is 23:43.

vBulletin® Version 3.8.8