diff options
-rw-r--r-- | app/Settings.qml | 2 | ||||
-rw-r--r-- | app/wifi/Wifi.qml | 118 |
2 files changed, 79 insertions, 41 deletions
diff --git a/app/Settings.qml b/app/Settings.qml index b3a622a..0d74c3b 100644 --- a/app/Settings.qml +++ b/app/Settings.qml @@ -49,6 +49,8 @@ ApplicationWindow { if (!app.isSetting) continue settingsModel.append({'icon': app.icon, 'title': app.title, 'checkable': app.checkable, 'app': app}) app.visible = false + + if (app.isWifi) app.activateWifi() } } diff --git a/app/wifi/Wifi.qml b/app/wifi/Wifi.qml index b4e3357..d21cccc 100644 --- a/app/wifi/Wifi.qml +++ b/app/wifi/Wifi.qml @@ -27,6 +27,8 @@ SettingPage { icon: '/wifi/images/HMI_Settings_WifiIcon.svg' title: 'Wifi' checkable: true + readonly property bool isWifi: true + property bool isInitializing: true property string wifiAPIpath: bindingAddress + '/wifi-manager/' //http://localhost:12345/api @@ -48,6 +50,8 @@ SettingPage { property string request_str: "" property string status_str: "" + + WebSocket { id: websocket url: address_str @@ -122,6 +126,13 @@ SettingPage { } } + else if (verb_str == "status") { + + var status = "OFF" + status = (message_json[2].response).Power + + checked = (status === "ON") ? true : false + } } else console.log("Unhadled websocket message", message_json[0]) } @@ -136,7 +147,35 @@ SettingPage { } else if (websocket.status == WebSocket.Open) { status_str = "Socket opened; sending message..." + //first get the status + verb_str = "status" + parameterJson = 'None' + sendSocketMesage(verb_str, parameterJson) + + + + } else if (websocket.status == WebSocket.Closed) { + status_str = "Socket closed" + console.log("Socket closed, bye.") + + websocket.active = false + + } + + console.log(status_str) + } + active: false + } + + onCheckedChanged: { + console.log("Wifi set to", checked) + + if (websocket.active) { + + if (checked == true) { + //subscribe for events + var parameterJson //network list updated event verb_str = "eventadd" @@ -182,60 +221,53 @@ SettingPage { parameterJson = 'None' sendSocketMesage(verb_str, parameterJson) + } else { - } else if (websocket.status == WebSocket.Closed) { - status_str = "Socket closed" - console.log("Socket closed, bye.") - - } - - console.log(status_str) - } - active: false - } - - onCheckedChanged: { - console.log("Wifi set to", checked) + if (!isInitializing) { - if (checked == true) { - //activating is done when socket is opened - websocket.active = true + networkList.clear() - } else { - networkList.clear() + verb_str = "deactivate" + parameterJson = 'None' + sendSocketMesage(verb_str, parameterJson) - verb_str = "deactivate" - var parameterJson = 'None' - sendSocketMesage(verb_str, parameterJson) + verb_str = "eventunsub" + parameterJson = { + tag: 'passkey' + } + sendSocketMesage(verb_str, parameterJson) - verb_str = "eventunsub" - parameterJson = { - tag: 'passkey' - } - sendSocketMesage(verb_str, parameterJson) + verb_str = "eventdel" + parameterJson = { + tag: 'passkey' + } + sendSocketMesage(verb_str, parameterJson) - verb_str = "eventdel" - parameterJson = { - tag: 'passkey' - } - sendSocketMesage(verb_str, parameterJson) + verb_str = "eventunsub" + parameterJson = { + tag: 'networkList' + } + sendSocketMesage(verb_str, parameterJson) - verb_str = "eventunsub" - parameterJson = { - tag: 'networkList' - } - sendSocketMesage(verb_str, parameterJson) + verb_str = "eventdel" + parameterJson = { + tag: 'networkList' + } + sendSocketMesage(verb_str, parameterJson) - verb_str = "eventdel" - parameterJson = { - tag: 'networkList' - } + } + } + isInitializing = false + } - websocket.active = false + else { + console.log("Websocket not active.") + websocket.active = true } + } @@ -444,4 +476,8 @@ SettingPage { } } + function activateWifi(){ + websocket.active = true + } + } |