managed wifi with a sketch

Hi everyone, i’m new on arduino (and unfortunately not native english speaker :s )

I’m doing a project on witch i have an arduino yun used as a weather station powered by a solar panel.

To save the energy i wanted to turn the wifi off.

The algorithm i wanted to use on the loop function is :

data<-getData(captors);

turnWifiOn()

connect<-connectToWifi(SSID)

if connect(Fail)

    insertInLocalBDD(data)

else

    getDataFromLocalBDD()

    insertAllDataInDistanteBDD()//i use the httpClient library to send the data by a webservice

    deleteDataFromLocalBDD()

turnWifiOff()

delay(600000)//wait 15 min

I tried to used the bridge functions

Process.runShellCommand("ifdown -a");

but it doesn’t work, i know runShellCommand works because i use it to get the date but ifdown/ifup don’t.

Anyone know how could i do to switch the wifi off and on?

thank you for answers!

Have a look at this thread, I know it's about permanently disabling Wifi but the build in auto reboot (have never heard this before, just read it in the linked posting) should be a problem for your goal also: http://forum.arduino.cc/index.php?topic=189105.0

nano /mnt/sda1/disablewifi.sh
#!/bin/sh
/sbin/uci set wireless.radio0.disabled=1
/sbin/uci commit wireless; /sbin/wifi
#/etc/init.d/network  restart
chmod 755 /mnt/sda1/disablewifi.sh
nano /mnt/sda1/enablewifi.sh
#!/bin/sh
/sbin/uci set wireless.radio0.disabled=0
/sbin/uci commit wireless; /sbin/wifi
#/etc/init.d/network  restart
chmod 755 /mnt/sda1/enablewifi.sh

Testing:

ifconfig wlan0
/mnt/sda1/disablewifi.sh
ifconfig wlan0
/mnt/sda1/enablewifi.sh
ifconfig wlan0

Arduino code:

#include <Process.h>
void setup() {
 Bridge.begin();  // Initialize Bridge
}
void loop() {
 Process p;              
 p.begin("/mnt/sda1/disablewifi.sh");      
 p.run();
 delay(5000); 
}

thank you for the fast answer! you are all awesome! i'm going to test your solution sonnyyu and let you know the result!

Sorry for this late answer but my arduino yun was toasted and the sdcard reader dead so i had to order a new one, with the new one everything is working properly thank you guys!