From 003559ae0ec6dca1b1eb39a181f8ca27c9ed94a4 Mon Sep 17 00:00:00 2001 From: Pecusx Date: Mon, 6 Mar 2017 19:21:12 +0100 Subject: [PATCH] Added 5s. wait for network on start (for slow PI and WiFi) --- radio4.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/radio4.py b/radio4.py index a30f9bd..3ab6b8e 100755 --- a/radio4.py +++ b/radio4.py @@ -125,16 +125,25 @@ class MyDaemon(Daemon): lcd.line1("Radio version " + radio.getVersion()) time.sleep(0.5) - ipaddr = exec_cmd('hostname -I') - hostname = exec_cmd('hostname -s') - log.message("IP " + ipaddr, log.INFO) - # Display daemon pid on the LCD message = "Radio pid " + str(os.getpid()) lcd.line2(message) - lcd.line3("Starting MPD") + lcd.line3("Waiting for network") + IPwait = 5 # Wait max 5s. for network + while IPwait > 0: + IPwait = IPwait - 1 + ipaddr = exec_cmd('hostname -I') + if ipaddr is "": + time.sleep(1) + else: + IPwait = 0 + lcd.line4("IP " + ipaddr) + hostname = exec_cmd('hostname -s') + log.message("IP " + ipaddr, log.INFO) + + lcd.line3("Starting MPD") radio.start() log.message("MPD started", log.INFO) time.sleep(0.5)