From 275ea54a85b9901b03344c30b51a861c15743889 Mon Sep 17 00:00:00 2001 From: dogmaphobic Date: Sat, 30 Apr 2016 02:38:09 -0400 Subject: [PATCH] Support for new firmware. Added setting to set the WiFi mode (AP or Station) --- .../Common/ESP8266Component.qml | 32 ++++++++++++++++--- .../Common/ESP8266ComponentController.cc | 29 +++++++++++++---- .../Common/ESP8266ComponentController.h | 21 ++++++------ 3 files changed, 62 insertions(+), 20 deletions(-) diff --git a/src/AutoPilotPlugins/Common/ESP8266Component.qml b/src/AutoPilotPlugins/Common/ESP8266Component.qml index ea191452f..e13a137b1 100644 --- a/src/AutoPilotPlugins/Common/ESP8266Component.qml +++ b/src/AutoPilotPlugins/Common/ESP8266Component.qml @@ -41,7 +41,7 @@ QGCView { QGCPalette { id: palette; colorGroupEnabled: panel.enabled } property int _firstColumn: ScreenTools.defaultFontPixelWidth * 20 - property int _secondColumn: ScreenTools.defaultFontPixelWidth * 12 + property int _secondColumn: ScreenTools.defaultFontPixelWidth * 18 readonly property string dialogTitle: qsTr("controller WiFi Bridge") property int stStatus: XMLHttpRequest.UNSENT property int stErrorCount: 0 @@ -64,15 +64,19 @@ QGCView { function updateStatus() { timer.stop() var req = new XMLHttpRequest; - var url = "http://192.168.4.1/status.json" + var url = "http://" + url += controller.wifiIPAddress + url += "/status.json" if(stResetCounters) { url = url + "?r=1" stResetCounters = false } + console.log(url) req.open("GET", url); req.onreadystatechange = function() { stStatus = req.readyState; if (stStatus === XMLHttpRequest.DONE) { + console.log(req.responseText) var objectArray = JSON.parse(req.responseText); if (objectArray.errors !== undefined) { console.log(qsTr("Error fetching WiFi Bridge Status: %1").arg(objectArray.errors[0].message)) @@ -107,6 +111,7 @@ QGCView { timer.triggered.connect(updateStatus) } + property Fact wifiMode: controller.getParameterFact(controller.componentID, "WIFI_MODE", false) //-- Don't bitch about missing as this is new property Fact wifiChannel: controller.getParameterFact(controller.componentID, "WIFI_CHANNEL") property Fact hostPort: controller.getParameterFact(controller.componentID, "WIFI_UDP_HPORT") property Fact clientPort: controller.getParameterFact(controller.componentID, "WIFI_UDP_CPORT") @@ -149,6 +154,24 @@ QGCView { id: wifiCol anchors.verticalCenter: parent.verticalCenter spacing: ScreenTools.defaultFontPixelHeight / 2 + Row { + visible: wifiMode + spacing: ScreenTools.defaultFontPixelWidth + QGCLabel { + text: qsTr("WiFi Mode") + width: _firstColumn + anchors.baseline: modeField.baseline + } + QGCComboBox { + id: modeField + width: _secondColumn + model: ["Access Point Mode", "Station Mode"] + currentIndex: wifiMode ? wifiMode.value : 0 + onActivated: { + wifiMode.value = index + } + } + } Row { spacing: ScreenTools.defaultFontPixelWidth QGCLabel { @@ -159,6 +182,7 @@ QGCView { QGCComboBox { id: channelField width: _secondColumn + enabled: wifiMode && wifiMode.value === 0 model: controller.wifiChannels currentIndex: wifiChannel ? wifiChannel.value - 1 : 0 onActivated: { @@ -395,8 +419,8 @@ QGCView { } } QGCButton { - text: stEnabled ? qsTr("Hide Status") : qsTr("Show Status") - width: ScreenTools.defaultFontPixelWidth * 16 + text: stEnabled ? qsTr("Hide Status") : qsTr("Show Status") + width: ScreenTools.defaultFontPixelWidth * 16 onClicked: { stEnabled = !stEnabled if(stEnabled) diff --git a/src/AutoPilotPlugins/Common/ESP8266ComponentController.cc b/src/AutoPilotPlugins/Common/ESP8266ComponentController.cc index c2e83626d..7b8c33dea 100644 --- a/src/AutoPilotPlugins/Common/ESP8266ComponentController.cc +++ b/src/AutoPilotPlugins/Common/ESP8266ComponentController.cc @@ -1,24 +1,24 @@ /*===================================================================== - + QGroundControl Open Source Ground Control Station - + (c) 2009, 2016 QGROUNDCONTROL PROJECT - + This file is part of the QGROUNDCONTROL project - + QGROUNDCONTROL is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - + QGROUNDCONTROL is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + You should have received a copy of the GNU General Public License along with QGROUNDCONTROL. If not, see . - + ======================================================================*/ /// @file @@ -74,6 +74,21 @@ ESP8266ComponentController::version() return versionString; } +//----------------------------------------------------------------------------- +QString +ESP8266ComponentController::wifiIPAddress() +{ + if(_ipAddress.isEmpty()) { + if(parameterExists(MAV_COMP_ID_UDP_BRIDGE, "WIFI_IPADDRESS")) { + QHostAddress address(ntohl(getParameterFact(MAV_COMP_ID_UDP_BRIDGE, "WIFI_IPADDRESS")->rawValue().toUInt())); + _ipAddress = address.toString(); + } else { + _ipAddress = "192.168.4.1"; + } + } + return _ipAddress; +} + //----------------------------------------------------------------------------- QString ESP8266ComponentController::wifiSSID() diff --git a/src/AutoPilotPlugins/Common/ESP8266ComponentController.h b/src/AutoPilotPlugins/Common/ESP8266ComponentController.h index 1256f9bdb..65fb3c5a0 100644 --- a/src/AutoPilotPlugins/Common/ESP8266ComponentController.h +++ b/src/AutoPilotPlugins/Common/ESP8266ComponentController.h @@ -1,24 +1,24 @@ /*===================================================================== - + QGroundControl Open Source Ground Control Station - + (c) 2009, 2016 QGROUNDCONTROL PROJECT - + This file is part of the QGROUNDCONTROL project - + QGROUNDCONTROL is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - + QGROUNDCONTROL is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + You should have received a copy of the GNU General Public License along with QGROUNDCONTROL. If not, see . - + ======================================================================*/ @@ -45,26 +45,28 @@ namespace Ui { class ESP8266ComponentController : public FactPanelController { Q_OBJECT - + public: ESP8266ComponentController (); ~ESP8266ComponentController (); Q_PROPERTY(int componentID READ componentID CONSTANT) Q_PROPERTY(QString version READ version NOTIFY versionChanged) + Q_PROPERTY(QString wifiIPAddress READ wifiIPAddress CONSTANT) Q_PROPERTY(QString wifiSSID READ wifiSSID WRITE setWifiSSID NOTIFY wifiSSIDChanged) Q_PROPERTY(QString wifiPassword READ wifiPassword WRITE setWifiPassword NOTIFY wifiPasswordChanged) Q_PROPERTY(QStringList wifiChannels READ wifiChannels CONSTANT) Q_PROPERTY(QStringList baudRates READ baudRates CONSTANT) Q_PROPERTY(int baudIndex READ baudIndex WRITE setBaudIndex NOTIFY baudIndexChanged) Q_PROPERTY(bool busy READ busy NOTIFY busyChanged) - Q_PROPERTY(Vehicle* vehicle READ vehicle CONSTANT) + Q_PROPERTY(Vehicle* vehicle READ vehicle CONSTANT) Q_INVOKABLE void restoreDefaults(); Q_INVOKABLE void reboot (); int componentID () { return MAV_COMP_ID_UDP_BRIDGE; } QString version (); + QString wifiIPAddress (); QString wifiSSID (); QString wifiPassword (); QStringList wifiChannels () { return _channels; } @@ -100,6 +102,7 @@ private: QTimer _timer; QStringList _channels; QStringList _baudRates; + QString _ipAddress; enum { WAIT_FOR_NOTHING, -- 2.22.0