Raspberry pi, bash script, and ad-hoc networks


RESULT=$(iwlist wlan0 scan | grep ESSID | grep -Po '".*?"')

echo $RESULT


for i in $RESULT;
 echo $i
 if [ $i = '"solarcar"' ]
 echo "This is home"
 echo "Not home"

echo "done"
if [ $ATHOME ]
 echo "normal mode"
 cp defaultSetup /etc/network/interfaces
 echo "adhoc mode"
 cp adhocSetup /etc/network/interfaces


ifdown wlan0
ifup wlan0


The UK solar car uses a raspberry pi to collect information from different systems of the car. The biggest are the motor controller, maximum power point trackers , and battery protection system. This information is re-factored on the pi. Then the data is saved on the SD, and the information is re-factored again, and broadcast over our 900 Mhz system telemetry.

The high levels of concurrence required make this a difficult. The physical positions of the pi in the car make it difficult to verify the pi is working.

So, what we(I) want, is the pi to go into an ad-hoc mode when the ssid of the garage is not in range. I wrote a bash script that will switch modes depending the ssids in the available.

The above script is the first pass. There are many irritating things about bash scripts. The white space, and the $ are the first 2 that come to mind.

T= $PWD  
#is not the same as, 

I have been been playing with the raspberry pi for the last couple of days. I SSH into the machine, so I still have all the advantages of a modern computer at my fingertips. The pi very responsive when the GUI is not running.


IMG_0720I need the screen and keyboard because I am rewriting the network config files. Occasionally I will mess up the basic internet connection, and have to undo something using the keyboard, and portable dvd player screen.  I do everything else through an SSH client.


Update: The code is on github