can a sketch tell the linux side which wifi network to use?

Hi,
Is it possible from the arduino side (using a sketch programmatically) to tell the linux side which wifi network to connect to?
For example, connect to "wifiguest" using "WPA2" encryption.

Hello rret,
yes it is possible to set wireless configuration from the sketch.
You can use the Process class provided by the Bridge library to run commands in the linux side. ( http://arduino.cc/en/Guide/ArduinoYun#toc18 )

In your example, to set the wireless network name you have to run:
uci set "wireless.@wifi-iface[0].ssid=wifiguest"
To have a complete list of parameter and configurations take a look here Wireless configuration [Old OpenWrt Wiki]

thanks very much - i'll have a look.

i'd like to add something to this. How can i select the active network ?

I my case, the Yun is connected trough LAN, WiFi or 3G . 3G should always be enabled, but
in some cases wifi or lan is too. How can my sketch use a process that selects the
connection that is best at a certain time (for example, disable the 3G if LAN is used, or Select
Wifi when the signal is better quality then the 3G, or the other way around)

Not easy, i suppose.

http://arduino.cc/en/Tutorial/ShellCommands for wifi strength?

bartdereu:
i'd like to add something to this. How can i select the active network ?

I my case, the Yun is connected trough LAN, WiFi or 3G . 3G should always be enabled, but
in some cases wifi or lan is too. How can my sketch use a process that selects the
connection that is best at a certain time (for example, disable the 3G if LAN is used, or Select
Wifi when the signal is better quality then the 3G, or the other way around)

Not easy, i suppose.

Indeed is not. Your 3g interface will look just like your ethernet or wifi, and linux will choose one reading its routing table (command "route" via ssh)
You can set your 3g device as the "default gateway" but that is not dynamic (not the way you want it)

Angelo9999:
Hello rret,
yes it is possible to set wireless configuration from the sketch.
You can use the Process class provided by the Bridge library to run commands in the linux side. ( http://arduino.cc/en/Guide/ArduinoYun#toc18 )

In your example, to set the wireless network name you have to run:
uci set "wireless.@wifi-iface[0].ssid=wifiguest"
To have a complete list of parameter and configurations take a look here Wireless configuration [Old OpenWrt Wiki]

i did some work/experimentation using your suggestion but did not get too far. would it be easier to just overwrite a file on the linux side with all of the wifi settings i need and then just reset the linux side?

/etc/config/wireless
looks as follows:

config wifi-device radio0
option type mac80211
option channel 11
option hwmode 11g
option path 'pci0000:00/0000:00:1c.2/0000:05:00.0'

REMOVE THIS LINE TO ENABLE WIFI:

option disabled 1

config wifi-iface
option device radio0
option network lan
option mode ap
option ssid OpenWrt
option encryption none

change it for "our" configuration:
file /etc/config/wireless is for open network:

config wifi-device radio0
option type mac80211
option channel 'auto'
option hwmode 11g
option path 'pci0000:00/0000:00:1c.2/0000:05:00.0'
option disabled 0

config wifi-iface
option device radio0
option network wwan
option mode sta
option ssid testwifi
option encryption none

http://forum.arduino.cc/index.php?topic=216850.msg1586874#msg1586874

make setupwifi.sh for first wifi network
make setupwifi2.sh for second wifi network
...

run setupwifi.sh via bridge/Process Class by arduino sketch.

Angelo9999:
Hello rret,
yes it is possible to set wireless configuration from the sketch.
You can use the Process class provided by the Bridge library to run commands in the linux side. ( http://arduino.cc/en/Guide/ArduinoYun#toc18 )

In your example, to set the wireless network name you have to run:
uci set "wireless.@wifi-iface[0].ssid=wifiguest"
To have a complete list of parameter and configurations take a look here Wireless configuration [Old OpenWrt Wiki]

okay - figured it out - this works (for those of you who need such functionality):

  Process p;		// Create a process and call it "p"
  p.begin("uci");// set wireless.@wifi-iface[0].ssid=RRwifi");	// Process that launch the "curl" command
  p.addParameter("set");
  p.addParameter("wireless.@wifi-iface[0].ssid=RR7");
  //p.addParameter("wireless.@wifi-iface[0].ssid=RRwifiguest; uci commit wireless; wifi"); // Add the URL parameter to "curl"
  p.run();		// Run the process and wait for its termination
  // A process output can be read with the stream methods
  while (p.available() > 0) {
    char c = p.read();
    Serial.print(c);
  }
  Serial.flush();
  
  p.begin("uci");// set wireless.@wifi-iface[0].ssid=RRwifi");	// Process that launch the "curl" command
  p.addParameter("commit");
  p.addParameter("wireless");
  p.run();		// Run the process and wait for its termination
  // A process output can be read with the stream methods
  while (p.available() > 0) {
    char c = p.read();
    Serial.print(c);
  }
  Serial.flush();
  
  p.runShellCommand("/etc/init.d/network restart");
  while(p.running()); 
  while (p.available() > 0) {
    char c = p.read();
    Serial.print(c);
  }
  // Ensure the last bit of data is sent.
  Serial.flush();
  
  //how about    uci show wireless?
  //p.runShellCommand("/usr/bin/pretty-wifi-info.lua");
  p.runShellCommand("uci show wireless");
  while(p.running()); 
  // A process output can be read with the stream methods
  while (p.available() > 0) {
    char c = p.read();
    Serial.print(c);
  }
  // Ensure the last bit of data is sent.
  Serial.flush();