[SOLVED] wifi reset if wrong password

Hi,

i am finishing my first real project with Arduino Yun, everything seems to work fine but i am facing with a "stupid" issue.

I have created a web page to allow users to decide wether to use Yun as an AP or to use the Yun as a Client over their Wifi.
Basically i just see user decision and i change wifi config via UCI command then i call for a reboot. Actually it works fine, i can move from one config to the other in an easy way.

Now, i have to face two issues:

  1. User enters a wrong SSID
    In this case, the script wifi-live-or-reset detects the problem and after 60 seconds it calls the wifi-reset-and-reboot script reconfiguring the Yun as an AP with default SSID

  2. User enters a correct SSID but with a wrong password
    In this case, the script wifi-live-or-reset is not correctly understanding the issue because linux is trying to connect so on the iwconfig output SSID is set to the real wifi name (and not to off/any). When Linux stops trying the connection, the wifi-live-or-reset script has already gone so nothing happens and the Yun is "bricked". You have to connect via ethernet cable or switch off access point and restart Yun, in this way the system will fall into the 1) case.

As you can imagine, i can not ask to my customer to switch off their AP if the enter a wrong password (i think this will happen often!)....i was just trying to imagine how can i detect case 2) and call the wifi-reset-and-reboot script.

If you have any suggestion, please tell me! Meanwhile i will try to find a solution....

Best Regards
Ettore

It seems that i found the solution...

if the system is trying to connect to the wifi network iwconfig output shows the SSID but ifconfig is not showing the ip address (at least in my situation where i accept only dhcp-client config....it should be tried in static mode).
So i changed the wifi-live-or-reset script in the following way:

....
iface_exists=""
iface_is_managed=""
iface_has_ssid=""
iface_is_access_point=""
iface_has_ip=""

update_vars() {
        iface_exists=`/usr/sbin/iwconfig $IFACE`
        iface_has_no_ssid=`/usr/sbin/iwconfig $IFACE | grep ESSID\:off\/any`
        iface_is_access_point=`/usr/sbin/iwconfig $IFACE | grep Mode\:Master`
        iface_has_ip=`/sbin/ifconfig $IFACE | grep inet`
}
....
if [ "$iface_exists" = "" ]
        then
                wait_for_iface
        elif [ "$iface_is_access_point" != "" ]
        then
                blink-stop
                exit 0
        elif [ "$iface_has_no_ssid" != "" ]
        then
                wait_for_iface
        else
                if [ "$iface_has_ip" = "" ]
                then
                        wait_for_iface
                else
                        blink-stop
                        rm -f /last_dmesg_with_wifi_errors.log
                        exit 0
                fi
        fi
....

maybe there is a more polite solution but this just works :slight_smile: