From c6c21ea1880d071000831c34a59bc6cde9a1bb2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20St=C3=BCrz?= Date: Fri, 2 Nov 2018 15:19:25 +0100 Subject: [PATCH 1/4] Add wireless access point mode --- .../wifisetup/wirelesssetupmanager.cpp | 125 ++++++++++++++---- .../wifisetup/wirelesssetupmanager.h | 100 ++++++++------ nymea-app/images.qrc | 1 + nymea-app/resources.qrc | 3 +- .../wifisetup/BluetoothDiscoveryPage.qml | 11 +- .../ui/connection/wifisetup/BoxInfoPage.qml | 2 +- .../connection/wifisetup/ConnectWiFiPage.qml | 15 ++- .../wifisetup/CreateAccessPointPage.qml | 95 +++++++++++++ .../wifisetup/NetworkSettingsPage.qml | 11 +- ...e.qml => WirelessConnectionStatusPage.qml} | 56 +++++++- nymea-app/ui/images/wireless-router.svg | 121 +++++++++++++++++ 11 files changed, 459 insertions(+), 81 deletions(-) create mode 100644 nymea-app/ui/connection/wifisetup/CreateAccessPointPage.qml rename nymea-app/ui/connection/wifisetup/{WirelessSetupPage.qml => WirelessConnectionStatusPage.qml} (67%) create mode 100644 nymea-app/ui/images/wireless-router.svg diff --git a/libnymea-app-core/wifisetup/wirelesssetupmanager.cpp b/libnymea-app-core/wifisetup/wirelesssetupmanager.cpp index ddeb07e13..277cfc8dc 100644 --- a/libnymea-app-core/wifisetup/wirelesssetupmanager.cpp +++ b/libnymea-app-core/wifisetup/wirelesssetupmanager.cpp @@ -31,6 +31,7 @@ static QBluetoothUuid wifiServiceUuid = QBluetoothUuid(QUuid("e0 static QBluetoothUuid wifiCommanderCharacteristicUuid = QBluetoothUuid(QUuid("e081fec1-f757-4449-b9c9-bfa83133f7fc")); static QBluetoothUuid wifiResponseCharacteristicUuid = QBluetoothUuid(QUuid("e081fec2-f757-4449-b9c9-bfa83133f7fc")); static QBluetoothUuid wifiStatusCharacteristicUuid = QBluetoothUuid(QUuid("e081fec3-f757-4449-b9c9-bfa83133f7fc")); +static QBluetoothUuid wifiModeCharacteristicUuid = QBluetoothUuid(QUuid("e081fec4-f757-4449-b9c9-bfa83133f7fc")); static QBluetoothUuid networkServiceUuid = QBluetoothUuid(QUuid("ef6d6610-b8af-49e0-9eca-ab343513641c")); static QBluetoothUuid networkStatusCharacteristicUuid = QBluetoothUuid(QUuid("ef6d6611-b8af-49e0-9eca-ab343513641c")); @@ -43,7 +44,6 @@ static QBluetoothUuid systemServiceUuid = QBluetoothUuid(QUuid(" static QBluetoothUuid systemCommanderCharacteristicUuid = QBluetoothUuid(QUuid("e081fed1-f757-4449-b9c9-bfa83133f7fc")); static QBluetoothUuid systemResponseCharacteristicUuid = QBluetoothUuid(QUuid("e081fed2-f757-4449-b9c9-bfa83133f7fc")); - WirelessSetupManager::WirelessSetupManager(const QBluetoothDeviceInfo &deviceInfo, QObject *parent) : BluetoothDevice(deviceInfo, parent), m_accessPoints(new WirelessAccessPoints(this)) @@ -87,6 +87,11 @@ bool WirelessSetupManager::working() const return m_working; } +bool WirelessSetupManager::accessPointModeAvailable() const +{ + return m_accessPointModeAvailable; +} + WirelessSetupManager::NetworkStatus WirelessSetupManager::networkStatus() const { return m_networkStatus; @@ -97,6 +102,11 @@ WirelessSetupManager::WirelessStatus WirelessSetupManager::wirelessStatus() cons return m_wirelessStatus; } +WirelessSetupManager::WirelessDeviceMode WirelessSetupManager::wirelessDeviceMode() const +{ + return m_wirelessDeviceMode; +} + bool WirelessSetupManager::networkingEnabled() const { return m_networkingEnabled; @@ -145,7 +155,7 @@ void WirelessSetupManager::loadNetworks() emit workingChanged(); QVariantMap request; - request.insert("c", (int)WirelessServiceCommandGetNetworks); + request.insert("c", static_cast(WirelessServiceCommandGetNetworks)); streamData(request); } @@ -172,7 +182,7 @@ void WirelessSetupManager::loadCurrentConnection() emit workingChanged(); QVariantMap request; - request.insert("c", (int)WirelessServiceCommandGetCurrentConnection); + request.insert("c", static_cast(WirelessServiceCommandGetCurrentConnection)); streamData(request); } @@ -196,7 +206,7 @@ void WirelessSetupManager::performWifiScan() emit workingChanged(); QVariantMap request; - request.insert("c", (int)WirelessServiceCommandScan); + request.insert("c", static_cast(WirelessServiceCommandScan)); streamData(request); } @@ -255,7 +265,35 @@ void WirelessSetupManager::connectWirelessNetwork(const QString &ssid, const QSt } QVariantMap request; - request.insert("c", (int)WirelessServiceCommandConnect); + request.insert("c", static_cast(WirelessServiceCommandConnect)); + QVariantMap parameters; + parameters.insert("e", ssid); + parameters.insert("p", password); + request.insert("p", parameters); + + streamData(request); +} + +void WirelessSetupManager::startAccessPoint(const QString &ssid, const QString &password) +{ + qDebug() << "WifiSetupManager: Start wireless access point using SSID:" << ssid << " password:" << password; + + m_ssid = ssid; + m_password = password; + + if (!m_wifiService) { + qWarning() << "WifiSetupManager: Could not set wireless network. Service not valid"; + return; + } + + QLowEnergyCharacteristic ssidCharacteristic = m_wifiService->characteristic(wifiCommanderCharacteristicUuid); + if (!ssidCharacteristic.isValid()) { + qWarning() << "WifiSetupManager: Could not connect. Characteristic is not valid"; + return; + } + + QVariantMap request; + request.insert("c", static_cast(WirelessServiceCommandStartAccessPoint)); QVariantMap parameters; parameters.insert("e", ssid); parameters.insert("p", password); @@ -280,7 +318,7 @@ void WirelessSetupManager::disconnectWirelessNetwork() } QVariantMap request; - request.insert("c", (int)WirelessServiceCommandDisconnect); + request.insert("c", static_cast(WirelessServiceCommandDisconnect)); streamData(request); } @@ -300,7 +338,7 @@ void WirelessSetupManager::pressPushButton() } QVariantMap request; - request.insert("c", (int)SystemServiceCommandPushAuthentication); + request.insert("c", static_cast(SystemServiceCommandPushAuthentication)); QByteArray data = QJsonDocument::fromVariant(request).toJson(QJsonDocument::Compact) + '\n'; qDebug() << "WifiSetupManager: SystemService: Start streaming response data:" << data.count() << "bytes"; @@ -387,6 +425,27 @@ void WirelessSetupManager::setWirelessStatus(int wirelessStatus) emit wirelessStatusChanged(); } +void WirelessSetupManager::setWirelessDeviceMode(int wirelessDeviceMode) +{ + if (m_wirelessDeviceMode == wirelessDeviceMode) + return; + + m_wirelessDeviceMode = static_cast(wirelessDeviceMode); + qDebug() << "-->" << m_wirelessDeviceMode; + emit wirelessDeviceModeChanged(); + + switch (m_wirelessDeviceMode) { + case WirelessDeviceModeAccessPoint: + loadCurrentConnection(); + break; + case WirelessDeviceModeInfrastructure: + loadNetworks(); + break; + default: + break; + } +} + void WirelessSetupManager::setNetworkingEnabled(bool networkingEnabled) { if (m_networkingEnabled == networkingEnabled) @@ -445,8 +504,8 @@ void WirelessSetupManager::processNetworkResponse(const QVariantMap &response) return; } - NetworkServiceCommand command = (NetworkServiceCommand)response.value("c").toInt(); - NetworkServiceResponse responseCode = (NetworkServiceResponse)response.value("r").toInt(); + NetworkServiceCommand command = static_cast(response.value("c").toInt()); + NetworkServiceResponse responseCode = static_cast(response.value("r").toInt()); if (responseCode != NetworkServiceResponseSuccess) { qWarning() << "WifiSetupManager: Got error for command" << command << responseCode; @@ -483,8 +542,8 @@ void WirelessSetupManager::processWifiResponse(const QVariantMap &response) return; } - WirelessServiceCommand command = (WirelessServiceCommand)response.value("c").toInt(); - WirelessServiceResponse responseCode = (WirelessServiceResponse)response.value("r").toInt(); + WirelessServiceCommand command = static_cast(response.value("c").toInt()); + WirelessServiceResponse responseCode = static_cast(response.value("r").toInt()); if (responseCode != WirelessServiceResponseSuccess) { qWarning() << "WifiSetupManager: Got error for command" << command << responseCode; @@ -566,7 +625,7 @@ void WirelessSetupManager::processWifiResponse(const QVariantMap &response) accessPoint->setHostAddress(currentConnection.value("i").toString()); } } - qDebug() << "current connection is:" << m_currentConnection; + qDebug() << "Current connection is:" << m_currentConnection; emit currentConnectionChanged(); m_initialized = true; @@ -589,8 +648,8 @@ void WirelessSetupManager::processSystemResponse(const QVariantMap &response) return; } - SystemServiceCommand command = (SystemServiceCommand)response.value("c").toInt(); - SystemServiceResponse responseCode = (SystemServiceResponse)response.value("r").toInt(); + SystemServiceCommand command = static_cast(response.value("c").toInt()); + SystemServiceResponse responseCode = static_cast(response.value("r").toInt()); if (responseCode != SystemServiceResponseSuccess) { qWarning() << "WifiSetupManager: Got error for command" << command << responseCode; @@ -781,9 +840,9 @@ void WirelessSetupManager::onNetworkServiceStateChanged(const QLowEnergyService: emit workingChanged(); // Done with discovery - setNetworkStatus(networkCharacteristic.value().toHex().toUInt(0, 16)); - setNetworkingEnabled((bool)networkingEnabledCharacteristic.value().toHex().toUInt(0, 16)); - setWirelessEnabled((bool)wirelessEnabledCharacteristic.value().toHex().toUInt(0, 16)); + setNetworkStatus(static_cast(networkCharacteristic.value().toHex().toUInt(nullptr, 16))); + setNetworkingEnabled(static_cast(networkingEnabledCharacteristic.value().toHex().toUInt(nullptr, 16))); + setWirelessEnabled(static_cast(wirelessEnabledCharacteristic.value().toHex().toUInt(nullptr, 16))); // Wifi service if (!m_wifiService) { @@ -847,12 +906,14 @@ void WirelessSetupManager::onNetworkServiceCharacteristicChanged(const QLowEnerg return; } } else if (characteristic.uuid() == networkingEnabledCharacteristicUuid) { - qDebug() << "Networking enabled changed" << (bool)value.toHex().toUInt(0, 16); - setNetworkingEnabled((bool)value.toHex().toUInt(0, 16)); + bool networkingEnabled = static_cast(value.toHex().toUInt(nullptr, 16)); + qDebug() << "Networking enabled changed" << networkingEnabled; + setNetworkingEnabled(networkingEnabled); return; } else if (characteristic.uuid() == wirelessEnabledCharacteristicUuid) { - qDebug() << "Wireless enabled changed" << (bool)value.toHex().toUInt(0, 16); - setWirelessEnabled((bool)value.toHex().toUInt(0, 16)); + bool wirelessEnabled = static_cast(value.toHex().toUInt(nullptr, 16)); + qDebug() << "Wireless enabled changed" << wirelessEnabled; + setWirelessEnabled(wirelessEnabled); return; } @@ -874,16 +935,29 @@ void WirelessSetupManager::onWifiServiceStateChanged(const QLowEnergyService::Se foreach (const QLowEnergyCharacteristic &characteristic, m_wifiService->characteristics()) { qDebug() << " -->" << characteristic.name() << characteristic.uuid().toString() << characteristic.value(); + + if (characteristic.uuid() == wifiModeCharacteristicUuid) { + m_accessPointModeAvailable = true; + emit accessPointModeAvailableChanged(); + } + foreach (const QLowEnergyDescriptor &descriptor, characteristic.descriptors()) { qDebug() << " -->" << descriptor.name() << descriptor.uuid().toString() << descriptor.value(); } } + // Enable notifications m_wifiService->writeDescriptor(m_wifiService->characteristic(wifiResponseCharacteristicUuid).descriptor(QBluetoothUuid::ClientCharacteristicConfiguration), QByteArray::fromHex("0100")); m_wifiService->writeDescriptor(m_wifiService->characteristic(wifiStatusCharacteristicUuid).descriptor(QBluetoothUuid::ClientCharacteristicConfiguration), QByteArray::fromHex("0100")); - setWirelessStatus(m_wifiService->characteristic(wifiStatusCharacteristicUuid).value().toHex().toUInt(0, 16)); + // Note: For compatibility + if (m_accessPointModeAvailable) { + m_wifiService->writeDescriptor(m_wifiService->characteristic(wifiModeCharacteristicUuid).descriptor(QBluetoothUuid::ClientCharacteristicConfiguration), QByteArray::fromHex("0100")); + setWirelessDeviceMode(static_cast(m_wifiService->characteristic(wifiModeCharacteristicUuid).value().toHex().toUInt(nullptr, 16))); + } + + setWirelessStatus(static_cast(m_wifiService->characteristic(wifiStatusCharacteristicUuid).value().toHex().toUInt(nullptr, 16))); // System service if (!m_systemService) { @@ -950,8 +1024,13 @@ void WirelessSetupManager::onWifiServiceCharacteristicChanged(const QLowEnergyCh return; } - qWarning() << "Bluetooth: Unhandled service characteristic changed" << characteristic.uuid() << value; + if (characteristic.uuid() == wifiModeCharacteristicUuid) { + qDebug() << "Wireless mode changed:" << value.toHex().toUInt(nullptr, 16); // << "Old status:" << m_wirelessStatus; + setWirelessDeviceMode(value.toHex().toInt(nullptr, 16)); + return; + } + qWarning() << "Bluetooth: Unhandled service characteristic changed" << characteristic.uuid() << value; } void WirelessSetupManager::onWifiServiceReadFinished(const QLowEnergyCharacteristic &characteristic, const QByteArray &value) diff --git a/libnymea-app-core/wifisetup/wirelesssetupmanager.h b/libnymea-app-core/wifisetup/wirelesssetupmanager.h index 3f8523ce7..c657fb7c8 100644 --- a/libnymea-app-core/wifisetup/wirelesssetupmanager.h +++ b/libnymea-app-core/wifisetup/wirelesssetupmanager.h @@ -37,6 +37,7 @@ class WirelessSetupManager : public BluetoothDevice Q_OBJECT Q_PROPERTY(bool working READ working NOTIFY workingChanged) Q_PROPERTY(bool initialized READ initialized NOTIFY initializedChanged) + Q_PROPERTY(bool accessPointModeAvailable READ accessPointModeAvailable NOTIFY accessPointModeAvailableChanged) Q_PROPERTY(WirelessAccessPoints *accessPoints READ accessPoints CONSTANT) Q_PROPERTY(WirelessAccessPoint *currentConnection READ currentConnection NOTIFY currentConnectionChanged) @@ -49,6 +50,7 @@ class WirelessSetupManager : public BluetoothDevice Q_PROPERTY(NetworkStatus networkStatus READ networkStatus NOTIFY networkStatusChanged) Q_PROPERTY(WirelessStatus wirelessStatus READ wirelessStatus NOTIFY wirelessStatusChanged) + Q_PROPERTY(WirelessDeviceMode wirelessDeviceMode READ wirelessDeviceMode NOTIFY wirelessDeviceModeChanged) Q_PROPERTY(bool networkingEnabled READ networkingEnabled NOTIFY networkingEnabledChanged) Q_PROPERTY(bool wirelessEnabled READ wirelessEnabled NOTIFY wirelessEnabledChanged) @@ -61,7 +63,8 @@ class WirelessSetupManager : public BluetoothDevice WirelessServiceCommandConnectHidden = 0x02, WirelessServiceCommandDisconnect = 0x03, WirelessServiceCommandScan = 0x04, - WirelessServiceCommandGetCurrentConnection = 0x05 + WirelessServiceCommandGetCurrentConnection = 0x05, + WirelessServiceCommandStartAccessPoint = 0x06 }; Q_ENUM(WirelessServiceCommand) @@ -77,6 +80,14 @@ class WirelessSetupManager : public BluetoothDevice }; Q_ENUM(WirelessServiceResponse) + enum WirelessDeviceMode { + WirelessDeviceModeUnknown = 0x00, + WirelessDeviceModeAdhoc = 0x01, + WirelessDeviceModeInfrastructure = 0x02, + WirelessDeviceModeAccessPoint = 0x03 + }; + Q_ENUM(WirelessDeviceMode) + enum NetworkServiceCommand { NetworkServiceCommandInvalid = -1, NetworkServiceCommandEnableNetworking = 0x00, @@ -150,8 +161,12 @@ class WirelessSetupManager : public BluetoothDevice bool initialized() const; bool working() const; + // Note: for compatibility + bool accessPointModeAvailable() const; + NetworkStatus networkStatus() const; WirelessSetupManager::WirelessStatus wirelessStatus() const; + WirelessDeviceMode wirelessDeviceMode() const; bool networkingEnabled() const; bool wirelessEnabled() const; @@ -168,47 +183,10 @@ class WirelessSetupManager : public BluetoothDevice Q_INVOKABLE void enableNetworking(bool enable); Q_INVOKABLE void enableWireless(bool enable); Q_INVOKABLE void connectWirelessNetwork(const QString &ssid, const QString &password = QString()); + Q_INVOKABLE void startAccessPoint(const QString &ssid, const QString &password); Q_INVOKABLE void disconnectWirelessNetwork(); Q_INVOKABLE void pressPushButton(); -signals: - void modelNumberChanged(); - void manufacturerChanged(); - void softwareRevisionChanged(); - void firmwareRevisionChanged(); - void hardwareRevisionChanged(); - - void initializedChanged(); - void workingChanged(); - - void networkStatusChanged(); - void wirelessStatusChanged(); - void networkingEnabledChanged(); - void wirelessEnabledChanged(); - - void currentConnectionChanged(); - - void errorOccurred(const QString &errorMessage); - -private slots: - void onConnectedChanged(); - void onServiceDiscoveryFinished(); - - void onDeviceInformationStateChanged(const QLowEnergyService::ServiceState &state); - void onDeviceInformationCharacteristicChanged(const QLowEnergyCharacteristic &characteristic, const QByteArray &value); - void onDeviceInformationReadFinished(const QLowEnergyCharacteristic &characteristic, const QByteArray &value); - - void onNetworkServiceStateChanged(const QLowEnergyService::ServiceState &state); - void onNetworkServiceCharacteristicChanged(const QLowEnergyCharacteristic &characteristic, const QByteArray &value); - void onNetworkServiceReadFinished(const QLowEnergyCharacteristic &characteristic, const QByteArray &value); - - void onWifiServiceStateChanged(const QLowEnergyService::ServiceState &state); - void onWifiServiceCharacteristicChanged(const QLowEnergyCharacteristic &characteristic, const QByteArray &value); - void onWifiServiceReadFinished(const QLowEnergyCharacteristic &characteristic, const QByteArray &value); - - void onSystemServiceStateChanged(const QLowEnergyService::ServiceState &state); - void onSystemServiceCharacteristicChanged(const QLowEnergyCharacteristic &characteristic, const QByteArray &value); - void onSystemServiceReadFinished(const QLowEnergyCharacteristic &characteristic, const QByteArray &value); private: QLowEnergyService *m_deviceInformationService = nullptr; @@ -230,9 +208,11 @@ private slots: bool m_working = false; bool m_initialized = false; + bool m_accessPointModeAvailable = false; NetworkStatus m_networkStatus = NetworkStatusUnknown; WirelessStatus m_wirelessStatus = WirelessStatusUnknown; + WirelessDeviceMode m_wirelessDeviceMode = WirelessDeviceModeUnknown; bool m_readingResponse = false; QByteArray m_inputDataStream; @@ -253,6 +233,7 @@ private slots: void setNetworkStatus(int networkStatus); void setWirelessStatus(int wirelessStatus); + void setWirelessDeviceMode(int wirelessDeviceMode); void setNetworkingEnabled(bool networkingEnabled); void setWirelessEnabled(bool wirelessEnabled); @@ -262,6 +243,47 @@ private slots: void processWifiResponse(const QVariantMap &response); void processSystemResponse(const QVariantMap &response); +signals: + void modelNumberChanged(); + void manufacturerChanged(); + void softwareRevisionChanged(); + void firmwareRevisionChanged(); + void hardwareRevisionChanged(); + + void initializedChanged(); + void workingChanged(); + void accessPointModeAvailableChanged(); + + void networkStatusChanged(); + void wirelessStatusChanged(); + void wirelessDeviceModeChanged(); + void networkingEnabledChanged(); + void wirelessEnabledChanged(); + + void currentConnectionChanged(); + + void errorOccurred(const QString &errorMessage); + +private slots: + void onConnectedChanged(); + void onServiceDiscoveryFinished(); + + void onDeviceInformationStateChanged(const QLowEnergyService::ServiceState &state); + void onDeviceInformationCharacteristicChanged(const QLowEnergyCharacteristic &characteristic, const QByteArray &value); + void onDeviceInformationReadFinished(const QLowEnergyCharacteristic &characteristic, const QByteArray &value); + + void onNetworkServiceStateChanged(const QLowEnergyService::ServiceState &state); + void onNetworkServiceCharacteristicChanged(const QLowEnergyCharacteristic &characteristic, const QByteArray &value); + void onNetworkServiceReadFinished(const QLowEnergyCharacteristic &characteristic, const QByteArray &value); + + void onWifiServiceStateChanged(const QLowEnergyService::ServiceState &state); + void onWifiServiceCharacteristicChanged(const QLowEnergyCharacteristic &characteristic, const QByteArray &value); + void onWifiServiceReadFinished(const QLowEnergyCharacteristic &characteristic, const QByteArray &value); + + void onSystemServiceStateChanged(const QLowEnergyService::ServiceState &state); + void onSystemServiceCharacteristicChanged(const QLowEnergyCharacteristic &characteristic, const QByteArray &value); + void onSystemServiceReadFinished(const QLowEnergyCharacteristic &characteristic, const QByteArray &value); + }; #endif // WIRELESSSETUPMANAGER_H diff --git a/nymea-app/images.qrc b/nymea-app/images.qrc index eac9c6ada..490f7412d 100644 --- a/nymea-app/images.qrc +++ b/nymea-app/images.qrc @@ -153,5 +153,6 @@ ui/images/smartmeter.svg ui/images/radiator.svg ui/images/ev-charger.svg + ui/images/wireless-router.svg diff --git a/nymea-app/resources.qrc b/nymea-app/resources.qrc index e3ef4ff8e..f1882a4ad 100644 --- a/nymea-app/resources.qrc +++ b/nymea-app/resources.qrc @@ -18,7 +18,7 @@ ui/connection/ManualConnectPage.qml ui/connection/ConnectingPage.qml ui/connection/wifisetup/BluetoothDiscoveryPage.qml - ui/connection/wifisetup/WirelessSetupPage.qml + ui/connection/wifisetup/WirelessConnectionStatusPage.qml ui/connection/wifisetup/ConnectWiFiPage.qml ui/connection/wifisetup/NetworkSettingsPage.qml ui/connection/wifisetup/BoxInfoPage.qml @@ -136,5 +136,6 @@ ui/customviews/GenericTypeGraph.qml ui/devicepages/SmartMeterDevicePage.qml ui/devicelistpages/SmartMeterDeviceListPage.qml + ui/connection/wifisetup/CreateAccessPointPage.qml diff --git a/nymea-app/ui/connection/wifisetup/BluetoothDiscoveryPage.qml b/nymea-app/ui/connection/wifisetup/BluetoothDiscoveryPage.qml index 37022d688..76668a58c 100644 --- a/nymea-app/ui/connection/wifisetup/BluetoothDiscoveryPage.qml +++ b/nymea-app/ui/connection/wifisetup/BluetoothDiscoveryPage.qml @@ -32,17 +32,17 @@ Page { function setupDevice() { pageStack.pop(root, StackView.Immediate) if (networkManager.manager.currentConnection) { - print("***** pushing WirelessSetupPage with networkManager:", networkManager) - var page = pageStack.push(Qt.resolvedUrl("WirelessSetupPage.qml"), { networkManagerController: networkManager, nymeaDiscovery: root.nymeaDiscovery } ) + print("***** pushing WirelessConnectionStatusPage with networkManager:", networkManager) + var page = pageStack.push(Qt.resolvedUrl("WirelessConnectionStatusPage.qml"), { networkManagerController: networkManager, nymeaDiscovery: root.nymeaDiscovery } ) page.done.connect(function() { pageStack.pop(root, StackView.Immediate); pageStack.pop(); }) } else { var page = pageStack.push(Qt.resolvedUrl("ConnectWiFiPage.qml"), { networkManagerController: networkManager } ) - page.connected.connect(function() { - setupDevice(); - }) +// page.connected.connect(function() { +// setupDevice(); +// }) } } @@ -238,6 +238,7 @@ Page { Layout.alignment: Qt.AlignHCenter running: true } + Label { id: initializingMessage Layout.fillWidth: true diff --git a/nymea-app/ui/connection/wifisetup/BoxInfoPage.qml b/nymea-app/ui/connection/wifisetup/BoxInfoPage.qml index 71420d7da..8356a5ef6 100644 --- a/nymea-app/ui/connection/wifisetup/BoxInfoPage.qml +++ b/nymea-app/ui/connection/wifisetup/BoxInfoPage.qml @@ -11,7 +11,7 @@ Page { onBackPressed: pageStack.pop() } - property var networkManagerController: null + property NetworkManagerController networkManagerController: null ColumnLayout { anchors { left: parent.left; top: parent.top; right: parent.right } diff --git a/nymea-app/ui/connection/wifisetup/ConnectWiFiPage.qml b/nymea-app/ui/connection/wifisetup/ConnectWiFiPage.qml index 92228db7d..35c699f88 100644 --- a/nymea-app/ui/connection/wifisetup/ConnectWiFiPage.qml +++ b/nymea-app/ui/connection/wifisetup/ConnectWiFiPage.qml @@ -7,7 +7,7 @@ import Nymea 1.0 Page { id: root - property var networkManagerController: null + property NetworkManagerController networkManagerController: null signal connected(); @@ -29,6 +29,13 @@ Page { pageStack.push(Qt.resolvedUrl("NetworkSettingsPage.qml"), {networkManagerController: root.networkManagerController}) } } + + HeaderButton { + imageSource: "../images/refresh.svg" + onClicked: { + networkManagerController.manager.loadNetworks() + } + } } ColumnLayout { @@ -83,8 +90,9 @@ Page { onClicked: { print("Connect to ", model.ssid, " --> ", model.macAddress) - if (model.selectedNetwork) { - pageStack.push(networkInformationPage, { ssid: model.ssid, macAddress: model.macAddress }) + if (networkManagerController.manager.currentConnection && networkManagerController.manager.currentConnection.macAddress === model.macAddress) { + // FIXME: show connection status page again + //pageStack.push(Qt.resolvedUrl("WirelessConnectionStatusPage.qml"), { networkManagerController: networkManager, nymeaDiscovery: root.nymeaDiscovery } ) } else { pageStack.push(authenticationPageComponent, { ssid: model.ssid, macAddress: model.macAddress }) } @@ -184,7 +192,6 @@ Page { id: connectingWifiWaitPage property string ssid - ColumnLayout { anchors { left: parent.left; right: parent.right; verticalCenter: parent.verticalCenter; margins: app.margins } spacing: app.margins * 2 diff --git a/nymea-app/ui/connection/wifisetup/CreateAccessPointPage.qml b/nymea-app/ui/connection/wifisetup/CreateAccessPointPage.qml new file mode 100644 index 000000000..9b64301de --- /dev/null +++ b/nymea-app/ui/connection/wifisetup/CreateAccessPointPage.qml @@ -0,0 +1,95 @@ +import QtQuick 2.4 +import QtQuick.Controls 2.3 +import QtQuick.Layouts 1.3 +import "../../components" +import Nymea 1.0 + +Page { + id: root + header: GuhHeader { + text: qsTr("Create access point") + onBackPressed: pageStack.pop() + } + + property NetworkManagerController networkManagerController: null + + ColumnLayout { + anchors { left: parent.left; top: parent.top; right: parent.right; } + + Label { + Layout.fillWidth: true + Layout.margins: app.margins + text: qsTr("Enter the SSID of access point") + wrapMode: Text.WordWrap + } + + TextField { + id: ssidTextField + Layout.fillWidth: true + Layout.margins: app.margins + } + + Label { + Layout.fillWidth: true + Layout.margins: app.margins + text: qsTr("Enter the password for the access point") + wrapMode: Text.WordWrap + } + + RowLayout { + Layout.leftMargin: app.margins; Layout.rightMargin: app.margins + TextField { + id: passwordTextField + Layout.fillWidth: true + property bool showPassword: false + echoMode: showPassword ? TextInput.Normal : TextInput.Password + } + + ColorIcon { + Layout.preferredHeight: app.iconSize + Layout.preferredWidth: app.iconSize + name: "../images/eye.svg" + color: passwordTextField.showPassword ? app.accentColor : keyColor + MouseArea { + anchors.fill: parent + onClicked: passwordTextField.showPassword = !passwordTextField.showPassword + } + } + } + + Button { + Layout.fillWidth: true + Layout.margins: app.margins + text: qsTr("OK") + enabled: passwordTextField.displayText.length >= 8 && ssidTextField.text != "" + onClicked: { + networkManagerController.manager.startAccessPoint(ssidTextField.text, passwordTextField.text) + pageStack.push(createAccessPointWaitPageComponent, {ssid: ssidTextField.text }) + } + } + } + + Component { + id: createAccessPointWaitPageComponent + + Page { + id: createAccessPointWaitPage + property string ssid + + ColumnLayout { + anchors { left: parent.left; right: parent.right; verticalCenter: parent.verticalCenter; margins: app.margins } + spacing: app.margins * 2 + BusyIndicator { + Layout.alignment: Qt.AlignHCenter + } + + Label { + Layout.fillWidth: true + wrapMode: Text.WordWrap + horizontalAlignment: Text.AlignHCenter + text: qsTr("Creating access point \"%1\" on %2 box").arg(createAccessPointWaitPage.ssid).arg(app.systemName) + } + } + } + } +} diff --git a/nymea-app/ui/connection/wifisetup/NetworkSettingsPage.qml b/nymea-app/ui/connection/wifisetup/NetworkSettingsPage.qml index 90b5b9b51..7d8c3c4ad 100644 --- a/nymea-app/ui/connection/wifisetup/NetworkSettingsPage.qml +++ b/nymea-app/ui/connection/wifisetup/NetworkSettingsPage.qml @@ -11,7 +11,7 @@ Page { onBackPressed: pageStack.pop() } - property var networkManagerController: null + property NetworkManagerController networkManagerController: null ColumnLayout { anchors { left: parent.left; top: parent.top; right: parent.right } @@ -40,5 +40,14 @@ Page { text: qsTr("Trigger a wireless scan on the device.") onClicked: networkManagerController.manager.performWifiScan() } + + Button { + Layout.fillWidth: true + Layout.leftMargin: app.margins + Layout.rightMargin: app.margins + visible: networkManagerController.manager.accessPointModeAvailable + text: qsTr("Create an access point.") + onClicked: pageStack.push(Qt.resolvedUrl("CreateAccessPointPage.qml"), {networkManagerController: root.networkManagerController}) + } } } diff --git a/nymea-app/ui/connection/wifisetup/WirelessSetupPage.qml b/nymea-app/ui/connection/wifisetup/WirelessConnectionStatusPage.qml similarity index 67% rename from nymea-app/ui/connection/wifisetup/WirelessSetupPage.qml rename to nymea-app/ui/connection/wifisetup/WirelessConnectionStatusPage.qml index 321d5b0c6..c11858001 100644 --- a/nymea-app/ui/connection/wifisetup/WirelessSetupPage.qml +++ b/nymea-app/ui/connection/wifisetup/WirelessConnectionStatusPage.qml @@ -7,8 +7,10 @@ import Nymea 1.0 Page { id: root - property var networkManagerController: null - property var nymeaDiscovery: null + property NetworkManagerController networkManagerController: null + property NymeaDiscovery nymeaDiscovery: null + + property bool accessPointMode: root.networkManagerController.manager.wirelessDeviceMode == WirelessSetupManager.WirelessDeviceModeAccessPoint signal done() @@ -57,7 +59,7 @@ Page { } function updateConnectButton() { - if (!root.networkManagerController.manager.currentConnection) { + if (!root.networkManagerController.manager.currentConnection || root.accessPointMode) { connectButton.url = ""; return; } @@ -77,6 +79,7 @@ Page { connectButton.url = ""; } + ColumnLayout { anchors { left: parent.left; top: parent.top; right: parent.right } spacing: app.margins @@ -84,13 +87,35 @@ Page { Layout.preferredHeight: app.iconSize * 2 Layout.preferredWidth: height Layout.alignment: Qt.AlignCenter - name: "../images/tick.svg" + name: root.accessPointMode ? "../images/wireless-router.svg" : "../images/tick.svg" color: app.accentColor } + + Label { + Layout.fillWidth: true + Layout.leftMargin: app.margins; Layout.rightMargin: app.margins + visible: root.accessPointMode + wrapMode: Text.WordWrap + text: root.networkManagerController.manager.currentConnection + ? qsTr("The %1 box is in access point mode").arg(app.systemName) + : "" + } + + Label { + Layout.fillWidth: true + Layout.leftMargin: app.margins; Layout.rightMargin: app.margins + visible: root.accessPointMode + wrapMode: Text.WordWrap + text: root.networkManagerController.manager.currentConnection + ? qsTr("Access point name: %1").arg(root.networkManagerController.manager.currentConnection.ssid) + : "" + } + Label { Layout.fillWidth: true Layout.leftMargin: app.margins; Layout.rightMargin: app.margins wrapMode: Text.WordWrap + visible: !root.accessPointMode text: root.networkManagerController.manager.currentConnection ? qsTr("Your %1 box is connected to %2").arg(app.systemName).arg(root.networkManagerController.manager.currentConnection.ssid) : "" @@ -99,13 +124,13 @@ Page { Label { Layout.fillWidth: true Layout.leftMargin: app.margins; Layout.rightMargin: app.margins - text: qsTr("IP address: %1").arg(root.networkManagerController.manager.currentConnection.hostAddress) + text: root.networkManagerController.manager.currentConnection ? qsTr("IP address: %1").arg(root.networkManagerController.manager.currentConnection.hostAddress) : "" elide: Text.ElideRight } RowLayout { Layout.leftMargin: app.margins; Layout.rightMargin: app.margins - visible: !connectButton.visible + visible: !connectButton.visible && !root.accessPointMode spacing: app.margins Label { Layout.fillWidth: true @@ -115,9 +140,25 @@ Page { BusyIndicator { } } + Button { + id: disconnectButton + Layout.fillWidth: true + Layout.leftMargin: app.margins; Layout.rightMargin: app.margins + text: root.accessPointMode ? qsTr("Shut down access point") : qsTr("Disconnect from this network") + onClicked: { + networkManagerController.manager.disconnectWirelessNetwork() +// var page = pageStack.push(Qt.resolvedUrl("ConnectWiFiPage.qml"), {networkManagerController: root.networkManagerController}) +// page.connected.connect(function() { +// pageStack.pop(root) +// }) + pageStack.pop() + networkManagerController.manager.loadNetworks() + } + } + Button { id: connectButton - visible: url != "" + visible: url != "" && !root.accessPointMode Layout.fillWidth: true Layout.leftMargin: app.margins; Layout.rightMargin: app.margins text: qsTr("Connect to box") @@ -130,6 +171,7 @@ Page { Button { Layout.fillWidth: true Layout.leftMargin: app.margins; Layout.rightMargin: app.margins + visible: !root.accessPointMode text: qsTr("Change network") onClicked: { var page = pageStack.push(Qt.resolvedUrl("ConnectWiFiPage.qml"), {networkManagerController: root.networkManagerController}) diff --git a/nymea-app/ui/images/wireless-router.svg b/nymea-app/ui/images/wireless-router.svg new file mode 100644 index 000000000..fe5494cb6 --- /dev/null +++ b/nymea-app/ui/images/wireless-router.svg @@ -0,0 +1,121 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + From ac74f392c8cfa75e92dadff572d8345014795d0e Mon Sep 17 00:00:00 2001 From: Michael Zanetti Date: Wed, 7 Nov 2018 12:30:43 +0100 Subject: [PATCH 2/4] improve wifi setup flow after AP mode has been added --- .../wifisetup/wirelessaccesspoints.cpp | 5 --- .../wifisetup/wirelessaccesspoints.h | 1 - .../wifisetup/wirelesssetupmanager.cpp | 36 +++++++++++-------- .../wifisetup/BluetoothDiscoveryPage.qml | 6 ++-- .../connection/wifisetup/ConnectWiFiPage.qml | 23 +++++++----- .../wifisetup/CreateAccessPointPage.qml | 27 +++++++++++--- .../wifisetup/NetworkSettingsPage.qml | 8 ----- .../WirelessConnectionStatusPage.qml | 36 ++++++++----------- 8 files changed, 74 insertions(+), 68 deletions(-) diff --git a/libnymea-app-core/wifisetup/wirelessaccesspoints.cpp b/libnymea-app-core/wifisetup/wirelessaccesspoints.cpp index 22d0ffc5e..7f143067b 100644 --- a/libnymea-app-core/wifisetup/wirelessaccesspoints.cpp +++ b/libnymea-app-core/wifisetup/wirelessaccesspoints.cpp @@ -76,11 +76,6 @@ QVariant WirelessAccessPoints::data(const QModelIndex &index, int role) const return QVariant(); } -int WirelessAccessPoints::count() const -{ - return m_wirelessAccessPoints.count(); -} - WirelessAccessPoint *WirelessAccessPoints::getAccessPoint(const QString &ssid) const { foreach (WirelessAccessPoint *accessPoint, m_wirelessAccessPoints) { diff --git a/libnymea-app-core/wifisetup/wirelessaccesspoints.h b/libnymea-app-core/wifisetup/wirelessaccesspoints.h index a40043a35..26d2268e7 100644 --- a/libnymea-app-core/wifisetup/wirelessaccesspoints.h +++ b/libnymea-app-core/wifisetup/wirelessaccesspoints.h @@ -50,7 +50,6 @@ class WirelessAccessPoints : public QAbstractListModel int rowCount(const QModelIndex & parent = QModelIndex()) const; QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const; - int count() const; Q_INVOKABLE WirelessAccessPoint *getAccessPoint(const QString &ssid) const; Q_INVOKABLE WirelessAccessPoint *get(int index); diff --git a/libnymea-app-core/wifisetup/wirelesssetupmanager.cpp b/libnymea-app-core/wifisetup/wirelesssetupmanager.cpp index 277cfc8dc..89adc5415 100644 --- a/libnymea-app-core/wifisetup/wirelesssetupmanager.cpp +++ b/libnymea-app-core/wifisetup/wirelesssetupmanager.cpp @@ -369,10 +369,6 @@ void WirelessSetupManager::checkInitialized() && m_netwokService->state() == QLowEnergyService::ServiceDiscovered && m_wifiService->state() == QLowEnergyService::ServiceDiscovered; } - - if (initialized && m_wirelessEnabled && m_networkingEnabled) { - loadNetworks(); - } } void WirelessSetupManager::setModelNumber(const QString &modelNumber) @@ -615,21 +611,31 @@ void WirelessSetupManager::processWifiResponse(const QVariantMap &response) qDebug() << "Current network connection" << response; QVariantMap currentConnection = response.value("p").toMap();; - // Find current network - m_currentConnection = nullptr; + WirelessAccessPoint *oldCurrent = m_currentConnection; + if (m_currentConnection) { + m_currentConnection->deleteLater(); + m_currentConnection = nullptr; + } + QString macAddress = currentConnection.value("m").toString(); - foreach (WirelessAccessPoint *accessPoint, m_accessPoints->wirelessAccessPoints()) { - if (accessPoint->macAddress() == macAddress) { - // Set the current network - m_currentConnection = accessPoint; - accessPoint->setHostAddress(currentConnection.value("i").toString()); - } + if (!macAddress.isEmpty()) { + // Looks like we are connected to a network which doesn't show up in the wifi scan. perhaps we opened up our own ap or connected to a hidden network. Let's add it now + m_currentConnection = new WirelessAccessPoint(this); + m_currentConnection->setSsid(currentConnection.value("e").toString()); + m_currentConnection->setMacAddress(macAddress); + m_currentConnection->setHostAddress(currentConnection.value("i").toString()); + m_currentConnection->setSignalStrength(currentConnection.value("s").toInt()); + m_currentConnection->setProtected(currentConnection.value("p").toBool()); } qDebug() << "Current connection is:" << m_currentConnection; - emit currentConnectionChanged(); + if (oldCurrent != m_currentConnection) { + emit currentConnectionChanged(); + } - m_initialized = true; - emit initializedChanged(); + if (!m_initialized) { + m_initialized = true; + emit initializedChanged(); + } break; } diff --git a/nymea-app/ui/connection/wifisetup/BluetoothDiscoveryPage.qml b/nymea-app/ui/connection/wifisetup/BluetoothDiscoveryPage.qml index 76668a58c..cb9c46951 100644 --- a/nymea-app/ui/connection/wifisetup/BluetoothDiscoveryPage.qml +++ b/nymea-app/ui/connection/wifisetup/BluetoothDiscoveryPage.qml @@ -40,9 +40,9 @@ Page { }) } else { var page = pageStack.push(Qt.resolvedUrl("ConnectWiFiPage.qml"), { networkManagerController: networkManager } ) -// page.connected.connect(function() { -// setupDevice(); -// }) + page.connected.connect(function() { + setupDevice(); + }) } } diff --git a/nymea-app/ui/connection/wifisetup/ConnectWiFiPage.qml b/nymea-app/ui/connection/wifisetup/ConnectWiFiPage.qml index 35c699f88..edc9dafb3 100644 --- a/nymea-app/ui/connection/wifisetup/ConnectWiFiPage.qml +++ b/nymea-app/ui/connection/wifisetup/ConnectWiFiPage.qml @@ -29,13 +29,6 @@ Page { pageStack.push(Qt.resolvedUrl("NetworkSettingsPage.qml"), {networkManagerController: root.networkManagerController}) } } - - HeaderButton { - imageSource: "../images/refresh.svg" - onClicked: { - networkManagerController.manager.loadNetworks() - } - } } ColumnLayout { @@ -91,14 +84,26 @@ Page { onClicked: { print("Connect to ", model.ssid, " --> ", model.macAddress) if (networkManagerController.manager.currentConnection && networkManagerController.manager.currentConnection.macAddress === model.macAddress) { - // FIXME: show connection status page again - //pageStack.push(Qt.resolvedUrl("WirelessConnectionStatusPage.qml"), { networkManagerController: networkManager, nymeaDiscovery: root.nymeaDiscovery } ) + pageStack.push(networkInformationPage, { ssid: model.ssid, macAddress: model.macAddress }) } else { pageStack.push(authenticationPageComponent, { ssid: model.ssid, macAddress: model.macAddress }) } } } } + + Button { + Layout.fillWidth: true + Layout.bottomMargin: app.margins; Layout.leftMargin: app.margins; Layout.rightMargin: app.margins + visible: networkManagerController.manager.accessPointModeAvailable + text: qsTr("Open access point") + onClicked: { + var page = pageStack.push(Qt.resolvedUrl("CreateAccessPointPage.qml"), {networkManagerController: root.networkManagerController}) + page.apReady.connect(function() { + root.connected(); + }) + } + } } Component { diff --git a/nymea-app/ui/connection/wifisetup/CreateAccessPointPage.qml b/nymea-app/ui/connection/wifisetup/CreateAccessPointPage.qml index 9b64301de..6b317b123 100644 --- a/nymea-app/ui/connection/wifisetup/CreateAccessPointPage.qml +++ b/nymea-app/ui/connection/wifisetup/CreateAccessPointPage.qml @@ -13,12 +13,24 @@ Page { property NetworkManagerController networkManagerController: null + signal apReady(); + + Connections { + target: root.networkManagerController.manager + onCurrentConnectionChanged: { + if (root.networkManagerController.manager.currentConnection) { + print("**** AP ready!") + root.apReady(); + } + } + } + ColumnLayout { anchors { left: parent.left; top: parent.top; right: parent.right; } Label { Layout.fillWidth: true - Layout.margins: app.margins + Layout.topMargin: app.margins; Layout.leftMargin: app.margins; Layout.rightMargin: app.margins text: qsTr("Enter the SSID of access point") wrapMode: Text.WordWrap } @@ -26,12 +38,14 @@ Page { TextField { id: ssidTextField Layout.fillWidth: true - Layout.margins: app.margins + Layout.leftMargin: app.margins; Layout.rightMargin: app.margins + maximumLength: 32 + onAccepted: passwordTextField.focus = true } Label { Layout.fillWidth: true - Layout.margins: app.margins + Layout.leftMargin: app.margins; Layout.rightMargin: app.margins text: qsTr("Enter the password for the access point") wrapMode: Text.WordWrap } @@ -41,8 +55,10 @@ Page { TextField { id: passwordTextField Layout.fillWidth: true + maximumLength: 64 property bool showPassword: false echoMode: showPassword ? TextInput.Normal : TextInput.Password + onAccepted: okButton.clicked() } ColorIcon { @@ -58,10 +74,11 @@ Page { } Button { + id: okButton Layout.fillWidth: true - Layout.margins: app.margins + Layout.leftMargin: app.margins; Layout.rightMargin: app.margins text: qsTr("OK") - enabled: passwordTextField.displayText.length >= 8 && ssidTextField.text != "" + enabled: passwordTextField.displayText.length >= 8 && ssidTextField.displayText != "" onClicked: { networkManagerController.manager.startAccessPoint(ssidTextField.text, passwordTextField.text) pageStack.push(createAccessPointWaitPageComponent, {ssid: ssidTextField.text }) diff --git a/nymea-app/ui/connection/wifisetup/NetworkSettingsPage.qml b/nymea-app/ui/connection/wifisetup/NetworkSettingsPage.qml index 7d8c3c4ad..3e678558e 100644 --- a/nymea-app/ui/connection/wifisetup/NetworkSettingsPage.qml +++ b/nymea-app/ui/connection/wifisetup/NetworkSettingsPage.qml @@ -41,13 +41,5 @@ Page { onClicked: networkManagerController.manager.performWifiScan() } - Button { - Layout.fillWidth: true - Layout.leftMargin: app.margins - Layout.rightMargin: app.margins - visible: networkManagerController.manager.accessPointModeAvailable - text: qsTr("Create an access point.") - onClicked: pageStack.push(Qt.resolvedUrl("CreateAccessPointPage.qml"), {networkManagerController: root.networkManagerController}) - } } } diff --git a/nymea-app/ui/connection/wifisetup/WirelessConnectionStatusPage.qml b/nymea-app/ui/connection/wifisetup/WirelessConnectionStatusPage.qml index c11858001..3feba3f53 100644 --- a/nymea-app/ui/connection/wifisetup/WirelessConnectionStatusPage.qml +++ b/nymea-app/ui/connection/wifisetup/WirelessConnectionStatusPage.qml @@ -50,6 +50,10 @@ Page { onCurrentConnectionChanged: { updateConnectButton(); + + if (!root.networkManagerController.manager.currentConnection) { + networkManagerController.manager.loadNetworks() + } } } @@ -87,6 +91,7 @@ Page { Layout.preferredHeight: app.iconSize * 2 Layout.preferredWidth: height Layout.alignment: Qt.AlignCenter + Layout.topMargin: app.margins name: root.accessPointMode ? "../images/wireless-router.svg" : "../images/tick.svg" color: app.accentColor } @@ -104,21 +109,10 @@ Page { Label { Layout.fillWidth: true Layout.leftMargin: app.margins; Layout.rightMargin: app.margins - visible: root.accessPointMode - wrapMode: Text.WordWrap - text: root.networkManagerController.manager.currentConnection + visible: root.networkManagerController.manager.currentConnection + text: root.accessPointMode ? qsTr("Access point name: %1").arg(root.networkManagerController.manager.currentConnection.ssid) - : "" - } - - Label { - Layout.fillWidth: true - Layout.leftMargin: app.margins; Layout.rightMargin: app.margins - wrapMode: Text.WordWrap - visible: !root.accessPointMode - text: root.networkManagerController.manager.currentConnection - ? qsTr("Your %1 box is connected to %2").arg(app.systemName).arg(root.networkManagerController.manager.currentConnection.ssid) - : "" + : qsTr("Your %1 box is connected to %2").arg(app.systemName).arg(root.networkManagerController.manager.currentConnection.ssid) } Label { @@ -134,7 +128,7 @@ Page { spacing: app.margins Label { Layout.fillWidth: true - text: qsTr("Waiting for the %1 box to appear in your network.").arg(app.systemName) + text: qsTr("Waiting for %1:core to appear in your network.").arg(app.systemName) wrapMode: Text.WordWrap } BusyIndicator { } @@ -147,12 +141,10 @@ Page { text: root.accessPointMode ? qsTr("Shut down access point") : qsTr("Disconnect from this network") onClicked: { networkManagerController.manager.disconnectWirelessNetwork() -// var page = pageStack.push(Qt.resolvedUrl("ConnectWiFiPage.qml"), {networkManagerController: root.networkManagerController}) -// page.connected.connect(function() { -// pageStack.pop(root) -// }) - pageStack.pop() - networkManagerController.manager.loadNetworks() + var page = pageStack.push(Qt.resolvedUrl("ConnectWiFiPage.qml"), {networkManagerController: root.networkManagerController}) + page.connected.connect(function() { + pageStack.pop(root) + }) } } @@ -161,7 +153,7 @@ Page { visible: url != "" && !root.accessPointMode Layout.fillWidth: true Layout.leftMargin: app.margins; Layout.rightMargin: app.margins - text: qsTr("Connect to box") + text: qsTr("Connect to %1").arg(app.systemName) property string url onClicked: { engine.connection.connect(url) From c22acaff981dcb846a30bc98550dfccd938aeadb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20St=C3=BCrz?= Date: Thu, 8 Nov 2018 11:56:31 +0100 Subject: [PATCH 3/4] Fix initialized issue --- libnymea-app-core/wifisetup/wirelesssetupmanager.cpp | 4 +++- libnymea-app-core/wifisetup/wirelesssetupmanager.h | 1 - nymea-app/ui/connection/wifisetup/ConnectWiFiPage.qml | 9 +++++++++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/libnymea-app-core/wifisetup/wirelesssetupmanager.cpp b/libnymea-app-core/wifisetup/wirelesssetupmanager.cpp index 89adc5415..5f6dfd24e 100644 --- a/libnymea-app-core/wifisetup/wirelesssetupmanager.cpp +++ b/libnymea-app-core/wifisetup/wirelesssetupmanager.cpp @@ -369,6 +369,9 @@ void WirelessSetupManager::checkInitialized() && m_netwokService->state() == QLowEnergyService::ServiceDiscovered && m_wifiService->state() == QLowEnergyService::ServiceDiscovered; } + + if (initialized) + loadCurrentConnection(); } void WirelessSetupManager::setModelNumber(const QString &modelNumber) @@ -506,7 +509,6 @@ void WirelessSetupManager::processNetworkResponse(const QVariantMap &response) if (responseCode != NetworkServiceResponseSuccess) { qWarning() << "WifiSetupManager: Got error for command" << command << responseCode; - switch (responseCode) { case NetworkServiceResponseIvalidValue: emit errorOccurred(tr("Invalid value.")); diff --git a/libnymea-app-core/wifisetup/wirelesssetupmanager.h b/libnymea-app-core/wifisetup/wirelesssetupmanager.h index c657fb7c8..8c5338adb 100644 --- a/libnymea-app-core/wifisetup/wirelesssetupmanager.h +++ b/libnymea-app-core/wifisetup/wirelesssetupmanager.h @@ -187,7 +187,6 @@ class WirelessSetupManager : public BluetoothDevice Q_INVOKABLE void disconnectWirelessNetwork(); Q_INVOKABLE void pressPushButton(); - private: QLowEnergyService *m_deviceInformationService = nullptr; QLowEnergyService *m_netwokService = nullptr; diff --git a/nymea-app/ui/connection/wifisetup/ConnectWiFiPage.qml b/nymea-app/ui/connection/wifisetup/ConnectWiFiPage.qml index edc9dafb3..59e9fa179 100644 --- a/nymea-app/ui/connection/wifisetup/ConnectWiFiPage.qml +++ b/nymea-app/ui/connection/wifisetup/ConnectWiFiPage.qml @@ -23,12 +23,21 @@ Page { pageStack.push(Qt.resolvedUrl("BoxInfoPage.qml"), {networkManagerController: root.networkManagerController}) } } + HeaderButton { imageSource: "../images/settings.svg" onClicked: { pageStack.push(Qt.resolvedUrl("NetworkSettingsPage.qml"), {networkManagerController: root.networkManagerController}) } } + + HeaderButton { + imageSource: "../images/refresh.svg" + onClicked: { + networkManagerController.manager.loadNetworks() + //pageStack.push(Qt.resolvedUrl("NetworkSettingsPage.qml"), {networkManagerController: root.networkManagerController}) + } + } } ColumnLayout { From 486f62272f56d7bdc0ac7fe335597a222aa9a513 Mon Sep 17 00:00:00 2001 From: Michael Zanetti Date: Thu, 8 Nov 2018 13:02:34 +0100 Subject: [PATCH 4/4] load all networks, not just the current one --- libnymea-app-core/wifisetup/wirelesssetupmanager.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libnymea-app-core/wifisetup/wirelesssetupmanager.cpp b/libnymea-app-core/wifisetup/wirelesssetupmanager.cpp index 5f6dfd24e..7b7ea6046 100644 --- a/libnymea-app-core/wifisetup/wirelesssetupmanager.cpp +++ b/libnymea-app-core/wifisetup/wirelesssetupmanager.cpp @@ -371,7 +371,7 @@ void WirelessSetupManager::checkInitialized() } if (initialized) - loadCurrentConnection(); + loadNetworks(); } void WirelessSetupManager::setModelNumber(const QString &modelNumber) @@ -629,7 +629,7 @@ void WirelessSetupManager::processWifiResponse(const QVariantMap &response) m_currentConnection->setSignalStrength(currentConnection.value("s").toInt()); m_currentConnection->setProtected(currentConnection.value("p").toBool()); } - qDebug() << "Current connection is:" << m_currentConnection; + qDebug() << "Current connection is:" << m_currentConnection << (m_currentConnection ? m_currentConnection->hostAddress() : ""); if (oldCurrent != m_currentConnection) { emit currentConnectionChanged(); }