[NOTE] Some WiFi tricks and a scripts

These tricks all assume you are logged into the Yun. You can, of course, run them use the library runShellCommand() (Example)

Get a list of AP (Access Points) as seen by the Arduino Yun

    $ iwlist wlan0 scan | grep ESSI

Note, that iwlist spews out a bunch of information. The grep utility acts as filter for the string ESSI.

Get the configuration of your wifi

root@Arduino:~# iwconfig wlan0
wlan0     IEEE 802.11bgn  Mode:Master  Tx-Power=16 dBm   
          RTS thr:off   Fragment thr:off
          Power Management:off

This Yun is in AP access point mode (or Mode:Master). (AKA working like a non-routable hotspot).

Get the AP (access point) your connected to

root@Arduino:~#  iwconfig wlan0
wlan0     IEEE 802.11bgn  ESSID:"ATT4FWBkmS"  
          Mode:Managed  Frequency:2.412 GHz  Access Point: 94:62:XX:XX:XX:XX   
          Bit Rate=39 Mb/s   Tx-Power=16 dBm   
          RTS thr:off   Fragment thr:off
          Encryption key:off
          Power Management:off
          Link Quality=61/70  Signal level=-49 dBm  
          Rx invalid nwid:0  Rx invalid crypt:0  Rx invalid frag:0
          Tx excessive retries:0  Invalid misc:19   Missed beacon:0

root@Arduino:~#  iwconfig wlan0 | grep ESSID
wlan0     IEEE 802.11bgn  ESSID:"ATT4FWBkmS"  

root@Arduino:~#  iwconfig wlan0 | grep ESSID | cut -f 2 -d :
"ATT4FWBkmS"

A home router is the AP (access point). In the second example, the grep utility acts as filter for the string ESSID - which is the AP we are connected to. In the third example, we filter out just the name.

Resetting the Wifi interface

    wifi down && sleep 5 && wifi

As suggested by OpenWrt

Let's not forget the OpenWrt Wireless FAQ
wiki.openwrt.org/doc/faq/faq.wireless
NOTE, this script was not well designed. It will be replaced in the future.

SCRIPT

Last, but not least. If you are on a Linux, FreeBSD or OS-X box, essentially anything that has a UNIX-flavor or a bash shell, this is my logon script.

Generally I have about 4 networks I can usually connect to. I usually get the same IP every time I connect the Yun to that network. So this script is just a shorthand to something I do.

I call it with:
./sshIn home
and that tells the script to use the IP I usually get at home. If that IP does not match the sub-network, I'm not connected to my home IP, and I will get a message that tell me to switch networks. The same applies to other networks.

The other alternative is to call it with an IP
./sshIn 192.168.240.1
This assumes I know what the IP of the YUN is, and it uses that IP during the SSH call.

Lastly, you can do similar with scp, except it is:
./scpIn 192.168.240.1 filename
the file when transferred will end up in the /root directory. The code for that is include, but commented out.

#!/bin/bash
#
# 2015-05-03 - updated to allow hostname as well as IP
# 2015-05-05 - Added 'help'
#
clear #; ./sshIn 192.168.43.237

ArduinoHOST=192.168.240.1   # Arduino default
MetroHOST=192.168.43.237  # MetroPCS hotspot
HouseHOST=192.168.1.193   # House AT&T
MYNAME=`basename $0`
HOST=""

if [ X"$1" != X"" ] ; then
 HOSTorIP=$1
fi

case $HOSTorIP in
default|arduino|yun)
 HOST=${ArduinoHOST}
;;
hotspot|metro|metropcs)
 HOST=${MetroHOST}
;;
house|home|att)
 HOST=${HouseHOST}
;;
help)
 HOST='help'
;;
[0123456789]*)
 HOST=${HOSTorIP}
;;
*)
 # default startup 
 HOST=""
;;
esac


echo HOST=$HOST
#exit
MYSUBNET=`ifconfig | grep "inet addr:192.168" | cut -d "." -f 3`
OTHERNET=`echo $HOST | cut -d "." -f 3`

if [ X${HOST} == X"" ]
then
 echo ""
 echo Need hostname or IP.
 echo ""
# See if we need "help".
elif [ X${HOST} == X"help" ]
then
 echo ""
 echo " ${MYNAME} [network|IP]"
 echo " Available:"
 echo " default|arduino|yun"
 echo " hotspot|metro|metropcs"
 echo " house|home|att"
 echo ""
# Compare the subnet of our IP and the target IP (the Yun) 
elif [ ${MYSUBNET} != ${OTHERNET} ]
then
 echo ""
 echo Different subnets";" Change Access Point.
 echo ""
else
 ssh -q -o StrictHostKeyChecking=no root@${HOST}
 # scp -q -o StrictHostKeyChecking=no $2 root@${HOST}:~/$2
fi

That's it, if you have your own hacks, tricks, please attach to this thread.

TIA
Jesse