Thank you for your donation!


Cloudsmith graciously provides open-source package management and distribution for our project.


Problem: Losing wifi at power glitch
#11
(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
Reply
#12
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;
}
Enjoy the Music!
moodeaudio.org | Mastodon Feed | GitHub
Reply
#13
(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?
Reply
#14
It's in the file below.

Code:
/var/www/inc/playerlib.php
Enjoy the Music!
moodeaudio.org | Mastodon Feed | GitHub
Reply
#15
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
Reply
#16
Path fixed :-)
Enjoy the Music!
moodeaudio.org | Mastodon Feed | GitHub
Reply
#17
Thanks very much for the collaboration on this. I'll try soon.
Reply


Forum Jump: