We have upgraded the community system as part of the upgrade a password reset is required for all users before login in.

Omega not reconnecting to wifi / wireless / wlan after router reboot



  • Hello everyone!
    Maybe the following helps someone who is fighting wifi connection issues, too.

    I use several Omega and Omega v2 to record room temperatures and to control my central heating.
    Most are connect directly to the WIFI router, one is connected to another Omega which in turn provides connection to the router.

    It seems that they all loose their connection if the router is rebooted. Or, if the "bridge" Omega reboots, the Omega connected to it is isoloated.

    In that situation it's always possible to connect to each of the Omegas using their own wifi access point (like Omega-0CF5)
    It took me a while, but at some point I realized that the wifi config file is modified so that the the connection to the router is disabled. Rebooting the Omega doesn't change that, it stays disabled.
    So to get connected to the router again, you need to fix the wifi config and then activate it.
    And that has to be done automatically, of course.

    I got this working using the following approach:

    1. Execute a script every 10 minutes or so to check the connection to the router
    2. If connection is present, save the working wifi config
    3. If connection is not working, replace current (broken) wifi config with the good and restart wifi

    For starters, ensure that the Omega is currently connected to the router.
    I stopped using the web console for that, instead, I make sure that /etc/config/wireless looks like the examples below:

    For an Omega (v1):

    config wifi-device 'radio0'
            option type 'mac80211'
            option hwmode '11g'
            option path 'platform/ar933x_wmac'
            option htmode 'HT20'
            option disabled '0'
            option channel '9'
            option txpower '30'
            option country 'US'    <= change that to your county (optional)
    
    config wifi-iface
            option device 'radio0'
            option network 'wlan'
            option mode 'ap'
            option encryption 'psk2'
            option key 'XXXXXX'  <= wifi key to connect to this Omega
            option ssid 'Omega-0CF5'   <= SSID of this Omega
            option disabled '0'
    
    config wifi-iface
            option device 'radio0'
            option mode 'sta'
            option network 'wwan'
            option ssid '<router SSID>' <= replace with your router SSID
            option encryption 'psk2'
            option key '<router wifi key>' <= replace with your router wifi key
            option disabled '0'
    

    For an Omega v2, this is slightly different:

    config wifi-device 'ra0'
            option type 'ralink'
            option mode '9'
            option channel 'auto'
            option txpower '100'
            option ht '20'
            option country 'US'    <= change that to your county (optional)
            option disabled '0'
    
    config wifi-iface
            option device 'ra0'
            option network 'wlan'
            option mode 'ap'
            option encryption 'psk2'
            option key 'XXXXXX'  <= wifi key to connect to this Omega
            option ApCliAuthMode 'WPA2PSK'
            option ApCliEncrypType 'AES'
            option ssid 'Omega-0DE7'  <= SSID of this Omega
            option ApCliSsid '<router SSID'  <= replace with your router SSID
            option ApAuthMode 'WPA2PSK'
            option ApCliPassWord '<router wifi key>' <= replace with your router wifi key
            option ApCliEnable '1'
    
    config wifi-config
            option ssid '<router SSID'  <= replace with your router SSID
            option encryption 'WPA2PSK'
            option key '<router wifi key>' <= replace with your router wifi key
    

    Once you have those edited properly, you can reconnect to your router by issuing the wifi command.

    Now we need a script that can be executed on a regular basis to check if the connection to the router is working and to either save the good config file or to fix a broken config file and restart wifi.
    That "saving" seemed to be a good idea, because it still allows you to make changes with the web console. The script would then use the new (working) configuration.

    That script named /root/reconnect_wireless looks like this (for v1 and v2 Omegas):

    #!/bin/sh
    
    STAT=$(ifstatus wwan | awk 'BEGIN {FS="[ ,]"} /\"up\".*,/ {print $2}')
    
    if [ "$STAT" = "true" ] ; then
            IP=$(ifstatus wwan | awk '{FS="[ ,\"]"} /\"target\".*,/ && $0 !~ /0.0.0.0/ {print $5}')
            RESPONSE=$(ping -c 1 $IP | awk '/time/ {print $3}')
            if [ "$RESPONSE" = "from" ] ; then
                    logger -t WIFI "Could ping $IP => wifi ok, saving wireless config file"
                    cp -f /etc/config/wireless /root/working-wireless
                    exit
            fi
    fi
    
    logger -t WIFI "Could not ping $IP or wwan interface down, restarting wireless with working config"
    cp -f /root/working-wireless /etc/config/wireless
    wifi
    

    ifstatusis used to capture the status of the wwan connection (which is the one to the router).
    On a v1 Omega, if it's "up" status is not "true", the connection is obviously down.
    On v2 Omegas this is not sufficient, because they keep the "up" status "true", but pings to the router still don't work.
    So extract the router IP address from ifstatus and assign it to the "IP" variable, then ping "IP" and check the output. If there's a line with "from" in the output, the router did answer.
    In that case, the connection is up, otherwise down.

    If the connection is up, the obviously good wireless config file is saved.

    If the connection is down, the saved copy of the wireless config file is copied to /etc/config and wifi is restarted with the wifi command.

    Now, we only need to automate this by creating a corresponding crontab entry.
    Execute crontab -e press i and add the following line at the end:
    */10 * * * * /root/reconnect_wireless
    Press ESC, type :x to save and exit.

    Now the connection is checked every 10 minutes.
    You can check it by taking a look at the log file:

    root@omega:~# logread | grep WIFI
    Sun Feb  4 12:00:00 2018 user.notice WIFI: Could ping 192.168.3.1 => wifi ok, saving wireless config file
    Sun Feb  4 12:10:00 2018 user.notice WIFI: Could ping 192.168.3.1 => wifi ok, saving wireless config file
    

    Hope this helps someone šŸ™‚
    Feel free to get in touch in case of questions.

    Christian
    https://tethis-it.at



  • @Christian-Toller in the omega2 /etc/config/wireless you are missing the > in '<router SSID' for both instances. not that it matters, i just noticed when reading. it's a good guide should i have the problem. it was either you or someone else that mentioned this issue before and as i result i tested my omega2 devices by unplugging my router they connect to and all 3 of them had no issue with reconnecting once the router was back up so i started to think it might be an issue with your specific router but did not know of the re-write of the file at the time so i'll have to go and check the files before & after the next time i test.



Looks like your connection to Community was lost, please wait while we try to reconnect.