View Single Post
Posts: 37 | Thanked: 18 times | Joined on Apr 2010
#9
Here's my current bash at it:
Code:
#!/bin/sh

#get current SSID
LIST=`iwconfig wlan0 | awk -F":" '/ESSID/{print $2}'`
echo Current connection: $LIST

#Quit if already connected
if [ $LIST = "\"$1\"" ]; then
    echo \"$1\" is already connected
    exit 1;
fi

#Bring up wlan and scan for SSIDs
ifconfig wlan0 up
if [ -z `iwlist wlan0 scan | grep -m 1 -o \"$1\"` ]; then
    echo SSID \"$1\" not found;
    exit 1;
fi

#Disconnect current using dbus
dbus-send --system --dest=com.nokia.icd \
/com/nokia/icd_ui com.nokia.icd_ui.disconnect boolean:true

#Wait for disconnect
sleep 6

#Find IAP_ID from SSID
IAP_ID=`gconftool-2 -R /system/osso/connectivity/IAP | tac | \
awk "/name = $1/,/connectivity\/IAP/" | \
awk -F '/|:' '/connectivity\/IAP/{ print $6}'`
echo IAP ID = $IAP_ID

#Connect to chosen SSID once disconnected
dbus-send --system --type=method_call --dest=com.nokia.icd \
/com/nokia/icd com.nokia.icd.connect string:"$IAP_ID" uint32:0

sleep 20

LIST=`iwconfig wlan0 | awk -F":" '/ESSID/{print $2}'`

echo Connected to $LIST

dbus-send --type=method_call --dest=org.freedesktop.Notifications \
/org/freedesktop/Notifications \
org.freedesktop.Notifications.SystemNoteDialog \
string:"Connected to $LIST" uint32:0 string:"OK"
  • Takes SSID as single parameter input
  • Uses SH instead of BASH and (I think) should work on an otherwise unmodified N900
  • Notifies user after connect
  • May well not work if you have changed the name of the connection to something other than the SSID
  • Still uses some inelegant string manipulation and downright ugly sleeps

Might try to add check for network status so I can remove the extra sleeps but probably won't get round to it!

EDIT: Doesn't seem to like being run as User. I'm running "sudo /usr/bin/run-standalone.sh /path/script 'SSID'" in alarmd to get round this

Last edited by hutchinsfairy; 2011-10-21 at 07:47. Reason: New info
 

The Following 4 Users Say Thank You to hutchinsfairy For This Useful Post: