diff --git a/frontend/device/cervantes/device.lua b/frontend/device/cervantes/device.lua index 29b28daff..e4a93a61f 100644 --- a/frontend/device/cervantes/device.lua +++ b/frontend/device/cervantes/device.lua @@ -14,11 +14,30 @@ local function getProductId() end local function isConnected() + -- read carrier state from sysfs (for eth0) local file = io.open("/sys/class/net/eth0/carrier", "rb") + + -- file exists while wifi module is loaded. if not file then return 0 end - local carrier = tonumber(file:read("*all")) or 0 + + -- 0 means not connected, 1 connected + local out = file:read("*all") file:close() - return carrier + + -- strip NaN from file read (ie: line endings, error messages) + local carrier + if type(out) ~= "number" then + carrier = tonumber(out) + else + carrier = out + end + + -- finally return if we're connected or not + if type(carrier) == "number" then + return carrier + else + return 0 + end end local function isMassStorageSupported() diff --git a/platform/cervantes/koreader.sh b/platform/cervantes/koreader.sh index ea6774f31..29470e41b 100755 --- a/platform/cervantes/koreader.sh +++ b/platform/cervantes/koreader.sh @@ -108,7 +108,8 @@ while [ "${RETURN_VALUE}" -ge "${RESTART_KOREADER}" ]; do # waiting forever for home button events. elif [ "${RETURN_VALUE}" -eq "${ENTER_QBOOKAPP}" ]; then - # iface is down and wpa killed. Start connman + ./release-ip.sh + ./disable-wifi.sh [ -x /etc/init.d/connman ] && /etc/init.d/connman start # (re)start the reading application in the background @@ -123,6 +124,8 @@ while [ "${RETURN_VALUE}" -ge "${RESTART_KOREADER}" ]; do done if [ "${STANDALONE}" != "true" ]; then + ./release-ip.sh + ./disable-wifi.sh [ -x /etc/init.d/connman ] && /etc/init.d/connman start restart.sh >/dev/null 2>&1 fi