diff --git a/src/functions.h b/src/functions.h index 1d1bf11..669e775 100644 --- a/src/functions.h +++ b/src/functions.h @@ -1102,22 +1102,31 @@ namespace { } } global::wifi::wifiState checkWifiState() { - foreach(QNetworkInterface interface, QNetworkInterface::allInterfaces()) { - // If something is wrong, debug with this: - // qDebug() << interface; - if(interface.flags().testFlag(QNetworkInterface::IsLoopBack) == false) { - if(interface.flags().testFlag(QNetworkInterface::IsUp) == true) { - if(interface.flags().testFlag(QNetworkInterface::IsRunning) == true) { - global::wifi::isConnected = true; - return global::wifi::wifiState::configured; - } - global::wifi::isConnected = false; - return global::wifi::wifiState::enabled; - } - } + QString interfaceStateFileHead = "/sys/class/net/"; + QString interfaceStateFileTail = "/operstate"; + QString interfaceName; + QString interfaceStateFile; + if(global::deviceID == "n437\n" or global::deviceID == "kt\n") { + interfaceName = "wlan0"; + } + else { + interfaceName = "eth0"; + } + interfaceStateFile = interfaceStateFileHead + interfaceName + interfaceStateFileTail; + + QString state = readFile(interfaceStateFile); + if(state == "up\n") { + global::wifi::isConnected = true; + return global::wifi::wifiState::configured; + } + else if(state == "unknown\n") { + global::wifi::isConnected = false; + return global::wifi::wifiState::enabled; + } + else { + global::wifi::isConnected = false; + return global::wifi::wifiState::disabled; } - global::wifi::isConnected = false; - return global::wifi::wifiState::disabled; } int testPing() { // For some reason, implementing a non-blocking version of this functions triggers a "terminate called without an active exception" error with a platform plugin compiled with a newer GCC 11 toolchain. The problem has been solved by transplanting this function into the related area which uses it. diff --git a/src/widgets/dialogs/wifi/connectiondialog.cpp b/src/widgets/dialogs/wifi/connectiondialog.cpp index 4b12481..3458d85 100644 --- a/src/widgets/dialogs/wifi/connectiondialog.cpp +++ b/src/widgets/dialogs/wifi/connectiondialog.cpp @@ -370,8 +370,8 @@ void connectiondialog::finalConnectWait() { else { string_writeconfig("/opt/ibxd", "connect_to_wifi_network\n"); - // This will be deleted later in MainWindow's icon updater if it failed. It is also deleted in the Wi-Fi stop script - log("Writing to config directory with connection information data", className); + // This will be deleted later in MainWindow's icon updater if it failed. It is also deleted in the Wi-Fi stop script. + log("Writing to configuration directory with connection information data", className); string_writeconfig("/mnt/onboard/.adds/inkbox/.config/17-wifi_connection_information/essid", connectedNetworkData.name.toStdString()); string_writeconfig("/mnt/onboard/.adds/inkbox/.config/17-wifi_connection_information/passphrase", passphraseForReconnecting.toStdString());