Use sketch to create temporary wireless access point ?

Hi,

I would like to turn my Yun into a temporary wireless Access Point with commands from the sketch.
The ethernet connector is connected to my router to internet.

In the OpenWRT documentation, I can read about the configuration files and how to set up a wireless Access Point, but I want to turn it on from the sketch with a number of runShellCommand().
Is that possible ?

P.S.: I have a Arduino Leonardo with the Dragino Shield. That is (almost) the same as the Arduino Yun.

Make it easy: come up with a (set of) Linux shell scripts that make the necessary networking changes. Make sure they do what you want them to when you run them at the command line.

Once you have that working, then add a Process object to your sketch that calls the shell script. You can use the Process Example as a starting point to run your script.

That would be the best solution. But I don't know OpenWRT that well, to turn a wifi client into a wifi Access Point while running.

Do you just want to turn an access point on and off? Or do you want to be able to choose different configurations and switch between them?

I think I want to switch between different configurations.

configuration 1 : wifi connected to my home wifi as client, ethernet cable sometimes connected.
configuration 2 : wifi as (bridged or not) AP using the ethernet cable.
configuration 3 : wifi as AP, without ethernet cable.

I want to use a webcam anywhere in my house, and use my home wifi to view the webcam. This is working.
But I also want to be able to use it as a (bridged) AP with the ethernet cable connected, as a substitute for a home wifi.
And and I want to carry it with me, and use any tablet to connect and view the webcam, like a wireless borescope.

Peter_n:
I think I want to switch between different configurations.

configuration 1 : wifi connected to my home wifi as client, ethernet cable sometimes connected.
configuration 2 : wifi as (bridged or not) AP using the ethernet cable.
configuration 3 : wifi as AP, without ethernet cable.

This is by no means the only way to do it, but it's a method I've used successfully to switch between two modes (client and AP in my case) but it can be expanded to any number of configurations.

The current WiFi configuration is stored in a file [color=blue]/etc/config/wireless[/color].

For the setup phase of my process, use whatever tools you like to set up the first configuration. This can be editing files, using UCI commands, the configuration web pages... whatever. Once you have a working configuration, copy the [color=blue]/etc/config/wireless[/color] configuration file to another location, giving it a useful name. In my case, I called it wireless.AP and put it in /mnt/sda1/wireless:

cp /etc/config/wireless /mnt/sda1/wireless/wireless.AP

Repeat this for each desired configuration, each time saving the [color=blue]/etc/config/wireless[/color] configuration file to a unique name. For example, I used names of wireless.AP and wireless.client.

Now, create this shell script, I called it changeWiFi and put it in the same folder and the saved wireless configuration files:

#!/bin/ash

# Script to change the WiFi configuration
# Parameter is the name of the new WiFi configuration file
# Wifi interface is brought down, the new configuration file
# is copied into place, then the WiFi is started again.

# Stop the current WiFi configuration
wifi down

# Copy the new configuration file into place
cp /mnt/sda1/wireless/$1 /etc/config/wireless

# Start the new WiFi configuration
wifi

Be sure to make the script file executable:

chmod +x changeWiFi

To make a configuration active, run the script, passing the saved configuration name as a parameter. This can be done on the Linux command line, or as a call to the Bridge library's Process class:

/mnt/sda1/wireless/changeWiFi wireless.AP

The script first stops the WiFi interface. It then takes the first parameter ("wireless.AP" in this case) and appends that to the path ("/mnt/sda1/wireless/") then copies the file to the configuration directory overwriting the current WiFi configuration. Finally the script starts the WiFi interface, making the new settings take effect.

Peter_n:
I think I want to switch between different configurations.

configuration 1 : wifi connected to my home wifi as client, ethernet cable sometimes connected.
configuration 2 : wifi as (bridged or not) AP using the ethernet cable.
configuration 3 : wifi as AP, without ethernet cable.

::::SNIP::::

@Peter_n,

ShapeShifter has given you a good start. Next,
what you need is a bit of shell programming with some good recipes.

I did a quick search for unix shell basics
This should do:
Learn UNIX in 10 minutes. Version 1.3
http://freeengineer.org/learnUNIXin10minutes.html

+++ Plus +++
OpenWrt Howto Recipes and HowTos
http://wiki.openwrt.org/doc/howto/start
It has everything from Basic Howto to VoIP. I think what you need is there in the first few recipes..

I'm think you'll need some help. Don't be afraid to ask.

Jesse

Thanks ShapeShifter ! That is what I was looking for.
I trying now to find the right configurations, loosing both my Ethernet and wifi all the time. I think I'm going to need a lot of 30 seconds resets to learn how to use the network settings :stuck_out_tongue:

jessemonroy650, I know linux, but not at a low level. Thanks for the OpenWRT howto/start page.

Peter_n:
I think I'm going to need a lot of 30 seconds resets to learn how to use the network settings :stuck_out_tongue:

The key is to plug in the Ethernet port - it shouldn't need any setup if you are plugging it into a router that has a DHCP server (the normal case.) I've found that with the Ethernet connected, I can always get to the Yun's configuration web pages and SSH command line. That makes it very handy to try various network configurations without having to reset things between each attempt.

And either way, you probably don't want the 30 second reset press: that resets everything, including any work you've done so far. It's the 5 second press that resets just the WiFi back to being an access point.

Speaking of which, when playing with WiFi settings, be aware that if you mess things up, and the WiFi can't connect to your selected access point, there is a built-in reset mechanism: a minute or two after rebooting, it looks to see if you have an active WiFi connection. If not, it does the same thing as a five second reset push and restores the default access point configuration and automatically resets. This can be helpful during initial configuration, but can be annoying once you have things straightened out (all your hard work configuring it can be wiped out if your access point should go down temporarily.) It's hard for me to find things and post links on the tablet I'm using at the moment, but if you search this forum for "wifi-live-or-reset" you should find instructions to remove it (basically comment out that line in rc.local.)

Thanks.

It is normal that when I set the wifi AP as a bridged AP, that I no longer can access the Yun itself via wifi or Ethernet ? (no more LuCI webinterface, not my webpage with data from by ATmeg32U4 and no Telnet SSH).

The Arduino "Bridge" to the ATmega32U4 is still running. I could setup some kind of terminal via the serial, as an alternative to Telnet SSH.

configuration 1 : wifi connected to my home wifi as client, ethernet cable sometimes connected.

  1. Set wifi as client to AP (router):
./setwifista.sh

http://forum.arduino.cc/index.php?topic=319496.msg2210215#msg2210215

  1. Roll back to dhcp ethernet port (for support ethernet cable sometimes connected.):
./setethdhcp.sh

http://forum.arduino.cc/index.php?topic=319496.msg2210198#msg2210198

Nice, I didn't know the UCI Sytem. Thanks. I will try that tomorrow.

@Peter_n,

I've given some thought to your original idea/request, and it is possible. In theory, of course, and it makes sense, not something out of this world.

However, three (3) days ago I started an upgrade (using an SD). I've had nothing but trouble. Currently, the python bridge has STOPPED working. IT's not working for Bridge.ino, WiFiStatus.ino, and YunSerialTerminal.ino. know there is a library upgrade I must do for the IDE, it may take care of all these problems.

I've going to write more in a new THREAD, later tonight.

Jesse

http://forum.arduino.cc/index.php?topic=319496.msg2231162#msg2231162