<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://maemo.octonezd.me/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=169.232.246.21</id>
	<title>Maemo Wiki Mirror - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://maemo.octonezd.me/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=169.232.246.21"/>
	<link rel="alternate" type="text/html" href="https://maemo.octonezd.me/index.php/Special:Contributions/169.232.246.21"/>
	<updated>2026-04-22T11:07:23Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.45.1</generator>
	<entry>
		<id>https://maemo.octonezd.me/index.php?title=User:Nbc/W32g&amp;diff=49873</id>
		<title>User:Nbc/W32g</title>
		<link rel="alternate" type="text/html" href="https://maemo.octonezd.me/index.php?title=User:Nbc/W32g&amp;diff=49873"/>
		<updated>2010-04-09T20:32:16Z</updated>

		<summary type="html">&lt;p&gt;169.232.246.21: /* Script */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= What is it =&lt;br /&gt;
&lt;br /&gt;
w32g is a dbus script to toggle 2g/3g when connected/disconnected to wifi.&lt;br /&gt;
&lt;br /&gt;
If there&#039;s a call, it will delay the toggling.&lt;br /&gt;
&lt;br /&gt;
= Configuration =&lt;br /&gt;
&lt;br /&gt;
The configuration documentation is at the beginning w32g.conf. You can copy it to /home/user/.w32g.conf and modify it :&lt;br /&gt;
&lt;br /&gt;
  [w32g]&lt;br /&gt;
  &lt;br /&gt;
  ### the comment reflect the default configuration&lt;br /&gt;
  ### true is true (case insensitive), everything else is false&lt;br /&gt;
  &lt;br /&gt;
  ### the command used to test the wifi connection before downgrading to 2g&lt;br /&gt;
  ### if you don&#039;t want to do test just delete after =&lt;br /&gt;
  # connection_test = sudo /bin/ping -c 1 www.google.com&lt;br /&gt;
  &lt;br /&gt;
  ### notification message when going to 3g&lt;br /&gt;
  # message_on_idle = 3G cellular mode set&lt;br /&gt;
  ### notification message when going to 2g&lt;br /&gt;
  # message_on_connected = 2G (GSM) cellular mode set&lt;br /&gt;
  &lt;br /&gt;
  ### shall we go back to 3g when wlan disconnect ?&lt;br /&gt;
  #### if you want to have false just delete after =&lt;br /&gt;
  # change_on_idle = true&lt;br /&gt;
  ### shall we go back to dual or 3g ?&lt;br /&gt;
  # change_to_dual = true&lt;br /&gt;
  &lt;br /&gt;
  ### if wait_on_call is a integer greater than 0, the program will wait&lt;br /&gt;
  ### all this time to toggle to 2g/3g. After this time it will exit&lt;br /&gt;
  ### without toggling.&lt;br /&gt;
  ### if wait_on_call is 0 or lesser, w32g will exit without toggling&lt;br /&gt;
  # wait_on_call = 90&lt;br /&gt;
  &lt;br /&gt;
  ### if you want go to 2g only when connected to some wlan you can add their wlan id here&lt;br /&gt;
  ### you can find the wlan id using the command &lt;br /&gt;
  ### gconftool-2 -R /system/osso/connectivity/IAP&lt;br /&gt;
  ### For example :&lt;br /&gt;
  ### wifi = 91f493fb-7c89-4fc6-ac2c-b822923dde45 9ee5dd55-9a32-4ee9-9131-c464ad31d907&lt;br /&gt;
  # wifi =&lt;br /&gt;
&lt;br /&gt;
= Script = &lt;br /&gt;
&lt;br /&gt;
And you must copy the program to /home/user/bin/w32g and follow instruction below :&lt;br /&gt;
&lt;br /&gt;
  #!/usr/bin/python&lt;br /&gt;
  &lt;br /&gt;
  # You need to install dbus-scripts (BE CAREFUL, it&#039;s a devel package)&lt;br /&gt;
  # &lt;br /&gt;
  # as root you need to create a file /etc/sudoers.d/w32g&lt;br /&gt;
  # with this line :&lt;br /&gt;
  #   user ALL = NOPASSWD: /bin/ping&lt;br /&gt;
  # and run the command update-sudoers because only root can use ping&lt;br /&gt;
  # &lt;br /&gt;
  # always as root and you need to create another file&lt;br /&gt;
  # /etc/dbus-scripts/w32g with the following line : &lt;br /&gt;
  #&lt;br /&gt;
  #   /home/user/bin/w32g * * com.nokia.icd status_changed * WLAN_INFRA *&lt;br /&gt;
  #&lt;br /&gt;
  # and copy this script in /home/user/bin/w32g&lt;br /&gt;
  &lt;br /&gt;
  import sys&lt;br /&gt;
  import os&lt;br /&gt;
  import ConfigParser&lt;br /&gt;
  import re&lt;br /&gt;
  import commands&lt;br /&gt;
  import time &lt;br /&gt;
  &lt;br /&gt;
  debug = False&lt;br /&gt;
  &lt;br /&gt;
  conf_file = &#039;/home/user/.w32g.conf&#039;&lt;br /&gt;
  &lt;br /&gt;
  config = { &#039;message_on_idle&#039;: &#039;3G cellular mode set&#039;,&lt;br /&gt;
    &#039;message_on_connected&#039;: &#039;2G (GSM) cellular mode set&#039;,&lt;br /&gt;
    &#039;connection_test&#039;: &#039;sudo /bin/ping -c 1 www.google.com&#039;,&lt;br /&gt;
    &#039;change_on_idle&#039;: &#039;true&#039;,&lt;br /&gt;
    &#039;change_to_dual&#039;: &#039;true&#039;,&lt;br /&gt;
    &#039;wait_on_call&#039;: 10,&lt;br /&gt;
    &#039;wifi&#039;: &#039;&#039;&lt;br /&gt;
  }&lt;br /&gt;
  &lt;br /&gt;
  config_parser = ConfigParser.SafeConfigParser()&lt;br /&gt;
  &lt;br /&gt;
  try:&lt;br /&gt;
      config_parser.read(conf_file)&lt;br /&gt;
      for item in config_parser.items(&#039;w32g&#039;):&lt;br /&gt;
          config[ item[0] ] = item[1]&lt;br /&gt;
  except ConfigParser.NoSectionError:&lt;br /&gt;
      pass&lt;br /&gt;
  &lt;br /&gt;
  def to_bool(string):&lt;br /&gt;
      if re.search(&#039;true&#039;, string, re.IGNORECASE):&lt;br /&gt;
          return True&lt;br /&gt;
  &lt;br /&gt;
  config[&#039;change_on_idle&#039;] = to_bool(config[&#039;change_on_idle&#039;])&lt;br /&gt;
  config[&#039;change_to_dual&#039;] = to_bool(config[&#039;change_to_dual&#039;])&lt;br /&gt;
  config[&#039;wait_on_call&#039;]   = int(config[&#039;wait_on_call&#039;])&lt;br /&gt;
  &lt;br /&gt;
  wifi_id,state = sys.argv[5],sys.argv[7]&lt;br /&gt;
  &lt;br /&gt;
  # if we are not on the good wifi network we do nothing and exit&lt;br /&gt;
  if config[&#039;wifi&#039;] and not re.search(wifi_id, config[&#039;wifi&#039;], re.IGNORECASE):&lt;br /&gt;
      if debug: print &amp;quot;not the good wifi network, exit&amp;quot;&lt;br /&gt;
      sys.exit(0)&lt;br /&gt;
  &lt;br /&gt;
  dbus_wifi = &amp;quot;dbus-send --system --type=method_call --print-reply --dest=com.nokia.phone.net /com/nokia/phone/net Phone.Net.set_selected_radio_access_technology&amp;quot;;&lt;br /&gt;
  &lt;br /&gt;
  dbus_notif = &amp;quot;dbus-send --system --type=method_call --print-reply --dest=org.freedesktop.Notifications /org/freedesktop/Notifications org.freedesktop.Notifications.SystemNoteInfoprint&amp;quot;;&lt;br /&gt;
  &lt;br /&gt;
  dbus_test_call = &amp;quot;dbus-send --system --dest=com.nokia.csd.Call --print-reply=literal /com/nokia/csd/call/1 com.nokia.csd.Call.Instance.GetStatus&amp;quot;&lt;br /&gt;
  &lt;br /&gt;
  def is_on_call():&lt;br /&gt;
      output = commands.getoutput(dbus_test_call)&lt;br /&gt;
      return &amp;quot;uint32 0&amp;quot; in output&lt;br /&gt;
  &lt;br /&gt;
  def wait_or_exit_on_call():&lt;br /&gt;
      if debug: print &amp;quot;in wait or exit on call&amp;quot;&lt;br /&gt;
      choice = config[&#039;wait_on_call&#039;]&lt;br /&gt;
      if choice &amp;gt; 0:&lt;br /&gt;
          end = time.time() + choice&lt;br /&gt;
          while end &amp;gt; time.time():&lt;br /&gt;
              if is_on_call(): return&lt;br /&gt;
              if debug: print &amp;quot;wait&amp;quot;&lt;br /&gt;
              time.sleep(1)&lt;br /&gt;
          sys.exit()&lt;br /&gt;
      else:&lt;br /&gt;
          sys.exit()&lt;br /&gt;
          &lt;br /&gt;
  if state == &#039;CONNECTED&#039;:&lt;br /&gt;
      if debug: print &amp;quot;CONNECTED STATE&amp;quot;&lt;br /&gt;
      # we verified that the connection works&lt;br /&gt;
      if config[&#039;connection_test&#039;]:&lt;br /&gt;
          ret = os.system(config[&#039;connection_test&#039;]);&lt;br /&gt;
      else:&lt;br /&gt;
          ret = 0&lt;br /&gt;
  &lt;br /&gt;
      # we wait or exit if there&#039;s a call&lt;br /&gt;
      wait_or_exit_on_call()&lt;br /&gt;
  &lt;br /&gt;
      if ret == 0:&lt;br /&gt;
          os.system(dbus_wifi + &amp;quot; byte:1&amp;quot;);&lt;br /&gt;
          os.system(dbus_notif + &amp;quot; string:&#039;&amp;quot; + config[&#039;message_on_connected&#039;] + &amp;quot;&#039;&amp;quot;)&lt;br /&gt;
  &lt;br /&gt;
  elif state == &#039;IDLE&#039; and config[&#039;change_on_idle&#039;]:&lt;br /&gt;
      if debug: print &amp;quot;IDLE STATE&amp;quot;&lt;br /&gt;
      dual = &amp;quot;2&amp;quot;&lt;br /&gt;
      if config[&#039;change_to_dual&#039;]: dual = &amp;quot;0&amp;quot;&lt;br /&gt;
      print dual&lt;br /&gt;
  &lt;br /&gt;
      # we wait or exit if there&#039;s a call&lt;br /&gt;
      wait_or_exit_on_call()&lt;br /&gt;
  &lt;br /&gt;
      os.system(dbus_wifi + &amp;quot; byte:&amp;quot; + dual);&lt;br /&gt;
      os.system(dbus_notif + &amp;quot; string:&#039;&amp;quot; + config[&#039;message_on_idle&#039;] + &amp;quot;&#039;&amp;quot;)&lt;br /&gt;
  &lt;br /&gt;
  print state&lt;br /&gt;
  &lt;br /&gt;
  if debug: print &amp;quot;end here&amp;quot;&lt;/div&gt;</summary>
		<author><name>169.232.246.21</name></author>
	</entry>
</feed>