[pisa-src] r1113 - trunk/tools

  • From: Tobias Heer <tobias.heer@xxxxxxxxxxxxxxxxx>
  • To: pisa-src@xxxxxxxxxxxxx
  • Date: Tue, 13 Oct 2009 15:27:00 +0200

Author: heer
Date: Tue Oct 13 15:27:00 2009
New Revision: 1113

Log:
Modified the iwlist parser and supplemented it with a handover script

Added:
   trunk/tools/auto-handover.sh   (contents, props changed)
   trunk/tools/iwlist_parser.c   (contents, props changed)
      - copied, changed from r1073, trunk/tools/iwlist_parser.cc
Deleted:
   trunk/tools/iwlist_parser.cc

Added: trunk/tools/auto-handover.sh
==============================================================================
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ trunk/tools/auto-handover.sh        Tue Oct 13 15:27:00 2009        (r1113)
@@ -0,0 +1,33 @@
+#!/bin/bash  
+
+echo "This file searches APs with SSID $PATTERN* and switches to the strongest 
signal" 
+
+
+#your parameters
+WIFI_IF="eth2"
+PATTERN="pisa-demo"
+
+## internal parameters
+last_result="NONE"
+
+while [ 1 ]
+do
+result=($(iwlist $WIFI_IF scan | ./piwlist -s $PATTERN))
+
+if [ "${result[0]}" == "NONE" ]
+then
+       echo "No PISA access points nearby"
+else 
+       if [ "$last_result" != "${result[0]}" ]
+       then
+               echo "Changing to " ${result[1]}
+               iwconfig $WIFI_IF ap  ${result[0]} essid  ${result[1]}
+               arp -d -a
+               last_result=${result[0]}
+       else
+               echo "Access Point is still best"
+       fi
+
+fi
+sleep 5
+done

Copied and modified: trunk/tools/iwlist_parser.c (from r1073, 
trunk/tools/iwlist_parser.cc)
==============================================================================
--- trunk/tools/iwlist_parser.cc        Thu Oct  8 19:31:25 2009        (r1073, 
copy source)
+++ trunk/tools/iwlist_parser.c Tue Oct 13 15:27:00 2009        (r1113)
@@ -13,9 +13,10 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <time.h>
-
+#include <stdbool.h>
 #include <unistd.h>
 
+
 #define MAX_CELLS              32
 #define ESSID_LENGTH           32
 #define MAC_LENGTH             18
@@ -236,24 +237,31 @@
                //Select best SignalStrength for given AP (or all AP's)
                int iIndexCell          = 0;
                int iBestStrength       = 0;
-       
-               for( int i = 0; i < MAX_CELLS; i++ ) {  
+               int i;  
+               int foundBest = false;
+               for( i = 0; i < MAX_CELLS; i++ ) {      
                        if( strEssid[i] == 0 )
                                continue;
                
-                       if( strcmp(strEssid[i], strSelectedESSID) == 0 || 
!essidflag ) {
+                       if(      strncmp(strEssid[i], strSelectedESSID, 
strlen(strSelectedESSID)) == 0 || !essidflag ) {
+
                                if( iSignalStrength[i] > iBestStrength) {
                                        iBestStrength   = iSignalStrength[i];
                                        iIndexCell      = i;
 #ifdef DEBUG
                                        printf("Set index for best Cell to:  
%i\n", i);
 #endif
+                               foundBest = true;
                                }
                        }       
                }
-       
+               
        //Output
-               printf("ap %s essid %s", strMAC[iIndexCell], 
strEssid[iIndexCell]);
+               if(foundBest == true){
+                       printf("%s %s %d", strMAC[iIndexCell], 
strEssid[iIndexCell], iSignalStrength[iIndexCell]);
+               }else{
+                       printf("NONE");
+               }
        }
 
        // Log a given message to a file (currently a fixed one).

Other related posts: