Moode Forum
[PROBLEM] Losing wifi at power glitch - Printable Version

+- Moode Forum (https://moodeaudio.org/forum)
+-- Forum: moOde audio player (https://moodeaudio.org/forum/forumdisplay.php?fid=3)
+--- Forum: Support (https://moodeaudio.org/forum/forumdisplay.php?fid=7)
+--- Thread: [PROBLEM] Losing wifi at power glitch (/showthread.php?tid=4231)

Pages: 1 2


RE: Losing wifi at power glitch - TheOldPresbyope - 09-27-2021

(09-27-2021, 11:18 PM)Tim Curtis Wrote: I think the scenario is that the Pi's complete Moode startup before the WiFi Router completes its startup. In this case Moode startup fails its 3 x 3 second retry to check for an IP address assigned to the adapter and then reverts to AP mode. Something like that.

Sounds plausible…and suggests several approaches to fixing the problem.

Regards,
Kent


RE: Losing wifi at power glitch - Tim Curtis - 09-27-2021

I suppose we could simply bump the number of retries. Under normal circumstances bumping it to lets say 10 it won't have any effect because Routers usually hand out an IP address almost immediately.

Anyway here's the function.

Code:
function waitForIpAddr($iface, $maxloops = 3, $sleeptime = 3000000) {
    for ($i = 0; $i < $maxloops; $i++) {
        $ipaddr = sysCmd('ip addr list ' . $iface . " | grep \"inet \" |cut -d' ' -f6|cut -d/ -f1");
        if (!empty($ipaddr[0])) {
            break;
        }
        else {
            workerLog('worker: ' . $iface .' wait '. $i . ' for IP address');
            usleep($sleeptime);
        }
    }

    return $ipaddr;
}



RE: Losing wifi at power glitch - malcolmwa - 09-28-2021

(09-27-2021, 11:41 PM)Tim Curtis Wrote: Anyway here's the function.



Code:
function waitForIpAddr($iface, $maxloops = 3, $sleeptime = 3000000) {
    for ($i = 0; $i < $maxloops; $i++) {
        $ipaddr = sysCmd('ip addr list ' . $iface . " | grep \"inet \" |cut -d' ' -f6|cut -d/ -f1");
        if (!empty($ipaddr[0])) {
            break;
        }
        else {
            workerLog('worker: ' . $iface .' wait '. $i . ' for IP address');
            usleep($sleeptime);
        }
    }

    return $ipaddr;
}
 Where would you insert this function?


RE: Losing wifi at power glitch - Tim Curtis - 09-28-2021

It's in the file below.

Code:
/var/www/inc/playerlib.php



RE: Losing wifi at power glitch - TheOldPresbyope - 09-28-2021

Errm, that would be /var/www/inc/playerlib.php.

look around line 2963.

Before I started poking at the code, I'd try a little test. With my smart phone or my laptop, I'd find a way to monitor the list of available access points. Then I'd power-cycle my access point and see how long it takes for the SSID to be detected again.

Then I'd bump the $maxloops parameter accordingly. 

Most of the consumer-grade APs I've owned in the past recovered quickly from a power-cycle but a counter-example is the cable modem/mesh network system I received from my ISP last year. It took well over a minute.

As Tim said, it doesn't really do harm to extend the wait time but if the AP recovery time is annoyingly long, I'd probably invest in a UPS for at least the AP if not both it and the moOde player. One can always do listening tests to see if the UPS introduces electrical noise to the moOde player (cheap ones are notorious for their AC output having bad sinusoidal waveforms and switching glitches.)


Regards,
Kent


RE: Losing wifi at power glitch - Tim Curtis - 09-28-2021

Path fixed :-)


RE: Losing wifi at power glitch - malcolmwa - 09-28-2021

Thanks very much for the collaboration on this. I'll try soon.