7import QGroundControl.FactControls
8import QGroundControl.Controls
12 property real _margins: ScreenTools.defaultFontPixelHeight
13 property real _middleRowWidth: ScreenTools.defaultFontPixelWidth * 18
14 property real _editFieldWidth: ScreenTools.defaultFontPixelWidth * 16
15 property real _labelWidth: ScreenTools.defaultFontPixelWidth * 10
16 property real _statusWidth: ScreenTools.defaultFontPixelWidth * 6
17 property real _smallFont: ScreenTools.smallFontPointSize
19 readonly property string dialogTitle: qsTr("controller WiFi Bridge")
20 property int stStatus: XMLHttpRequest.UNSENT
21 property int stErrorCount: 0
22 property bool stResetCounters:false
24 ESP8266ComponentController {
32 function thisThingHasNoNumberLocaleSupport(n) {
33 return n.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",").replace(",,", ",")
36 function updateStatus() {
38 var req = new XMLHttpRequest;
40 url += controller.wifiIPAddress
44 stResetCounters = false
47 req.onreadystatechange = function() {
48 stStatus = req.readyState;
49 if (stStatus === XMLHttpRequest.DONE) {
50 var objectArray = JSON.parse(req.responseText);
51 if (objectArray.errors !== undefined) {
52 console.log(qsTr("Error fetching WiFi Bridge Status: %1").arg(objectArray.errors[0].message))
53 stErrorCount = stErrorCount + 1
57 //-- This should work but it doesn't
58 // var n = 34523453.345
61 vpackets.text = thisThingHasNoNumberLocaleSupport(objectArray["vpackets"])
62 vsent.text = thisThingHasNoNumberLocaleSupport(objectArray["vsent"])
63 vlost.text = thisThingHasNoNumberLocaleSupport(objectArray["vlost"])
64 gpackets.text = thisThingHasNoNumberLocaleSupport(objectArray["gpackets"])
65 gsent.text = thisThingHasNoNumberLocaleSupport(objectArray["gsent"])
66 glost.text = thisThingHasNoNumberLocaleSupport(objectArray["glost"])
75 Component.onCompleted: {
78 timer.triggered.connect(updateStatus)
82 property Fact wifiMode: controller.getParameterFact(controller.componentID, "WIFI_MODE", false) //-- Don't bitch about missing as this is new
83 property Fact wifiChannel: controller.getParameterFact(controller.componentID, "WIFI_CHANNEL")
84 property Fact hostPort: controller.getParameterFact(controller.componentID, "WIFI_UDP_HPORT")
85 property Fact clientPort: controller.getParameterFact(controller.componentID, "WIFI_UDP_CPORT")
94 contentHeight: mainCol.height
95 flickableDirection: Flickable.VerticalFlick
99 anchors.horizontalCenter: parent.horizontalCenter
100 Item { width: 1; height: _margins * 0.5; }
102 text: qsTr("ESP WiFi Bridge Settings")
106 color: qgcPal.windowShade
107 width: statusLayout.width + _margins * 4
108 height: settingsRow.height + _margins * 2
111 spacing: _margins * 4
112 anchors.centerIn: parent
115 width: ScreenTools.defaultFontPixelWidth * 12
117 sourceSize.height: width * 1.45
119 fillMode: Image.PreserveAspectFit
120 source: wifiMode ? (wifiMode.value === 0 ? "/qmlimages/APMode.svg" : "/qmlimages/StationMode.svg") : "/qmlimages/APMode.svg"
121 anchors.verticalCenter: parent.verticalCenter
124 spacing: _margins * 0.5
125 anchors.verticalCenter: parent.verticalCenter
129 text: qsTr("WiFi Mode")
130 width: _middleRowWidth
131 anchors.baseline: modeField.baseline
135 width: _editFieldWidth
136 model: ["Access Point Mode", "Station Mode"]
137 currentIndex: wifiMode ? wifiMode.value : 0
138 onActivated: (index) => {
139 wifiMode.value = index
145 text: qsTr("WiFi Channel")
146 width: _middleRowWidth
147 anchors.baseline: channelField.baseline
151 width: _editFieldWidth
152 enabled: wifiMode ? wifiMode.value === 0 : true
153 model: controller.wifiChannels
154 currentIndex: wifiChannel ? wifiChannel.value - 1 : 0
155 onActivated: (index) => {
156 wifiChannel.value = index + 1
162 text: qsTr("WiFi AP SSID")
163 width: _middleRowWidth
164 anchors.baseline: ssidField.baseline
168 width: _editFieldWidth
169 text: controller.wifiSSID
172 controller.wifiSSID = text
178 text: qsTr("WiFi AP Password")
179 width: _middleRowWidth
180 anchors.baseline: passwordField.baseline
184 width: _editFieldWidth
185 text: controller.wifiPassword
188 controller.wifiPassword = text
194 text: qsTr("WiFi STA SSID")
195 width: _middleRowWidth
196 anchors.baseline: stassidField.baseline
200 width: _editFieldWidth
201 text: controller.wifiSSIDSta
203 enabled: wifiMode && wifiMode.value === 1
205 controller.wifiSSIDSta = text
211 text: qsTr("WiFi STA Password")
212 width: _middleRowWidth
213 anchors.baseline: passwordStaField.baseline
217 width: _editFieldWidth
218 text: controller.wifiPasswordSta
220 enabled: wifiMode && wifiMode.value === 1
222 controller.wifiPasswordSta = text
228 text: qsTr("UART Baud Rate")
229 width: _middleRowWidth
230 anchors.baseline: baudField.baseline
234 width: _editFieldWidth
235 model: controller.baudRates
236 currentIndex: controller.baudIndex
237 onActivated: (index) => {
238 controller.baudIndex = index
244 text: qsTr("QGC UDP Port")
245 width: _middleRowWidth
246 anchors.baseline: qgcportField.baseline
250 width: _editFieldWidth
251 text: hostPort ? hostPort.valueString : ""
252 validator: IntValidator {bottom: 1024; top: 65535;}
253 inputMethodHints: Qt.ImhDigitsOnly
255 hostPort.value = text
263 text: qsTr("ESP WiFi Bridge Status")
267 color: qgcPal.windowShade
268 width: statusLayout.width + _margins * 4
269 height: statusLayout.height + _margins * 2
273 columnSpacing: _margins * 2
274 anchors.centerIn: parent
276 text: qsTr("Bridge/Vehicle Link")
277 Layout.alignment: Qt.AlignHCenter
280 text: qsTr("Bridge/QGC Link")
281 Layout.alignment: Qt.AlignHCenter
284 text: qsTr("QGC/Bridge Link")
285 Layout.alignment: Qt.AlignHCenter
290 text: qsTr("Messages Received")
291 font.pointSize: _smallFont
296 font.pointSize: _smallFont
298 horizontalAlignment: Text.AlignRight
304 font.pointSize: _smallFont
305 text: qsTr("Messages Received")
310 font.pointSize: _smallFont
312 horizontalAlignment: Text.AlignRight
318 font.pointSize: _smallFont
319 text: qsTr("Messages Received")
323 font.pointSize: _smallFont
324 text: controller.vehicle ? thisThingHasNoNumberLocaleSupport(controller.vehicle.messagesReceived) : 0
326 horizontalAlignment: Text.AlignRight
332 text: qsTr("Messages Lost")
333 font.pointSize: _smallFont
339 horizontalAlignment: Text.AlignRight
340 font.pointSize: _smallFont
346 text: qsTr("Messages Lost")
347 font.pointSize: _smallFont
353 horizontalAlignment: Text.AlignRight
354 font.pointSize: _smallFont
360 text: qsTr("Messages Lost")
361 font.pointSize: _smallFont
365 text: controller.vehicle ? thisThingHasNoNumberLocaleSupport(controller.vehicle.messagesLost) : 0
367 horizontalAlignment: Text.AlignRight
368 font.pointSize: _smallFont
374 text: qsTr("Messages Sent")
375 font.pointSize: _smallFont
381 horizontalAlignment: Text.AlignRight
382 font.pointSize: _smallFont
388 text: qsTr("Messages Sent")
389 font.pointSize: _smallFont
395 horizontalAlignment: Text.AlignRight
396 font.pointSize: _smallFont
402 text: qsTr("Messages Sent")
403 font.pointSize: _smallFont
407 text: controller.vehicle ? thisThingHasNoNumberLocaleSupport(controller.vehicle.messagesSent) : 0
409 horizontalAlignment: Text.AlignRight
410 font.pointSize: _smallFont
417 anchors.horizontalCenter: parent.horizontalCenter
419 text: qsTr("Restore Defaults")
420 width: _editFieldWidth
422 controller.restoreDefaults()
426 text: qsTr("Restart WiFi Bridge")
427 enabled: !controller.busy
428 width: _editFieldWidth
430 rebootDialog.visible = true
435 buttons: MessageDialog.Yes | MessageDialog.No
436 title: qsTr("Reboot WiFi Bridge")
437 text: qsTr("This will restart the WiFi Bridge so the settings you've changed can take effect. Note that you may have to change your computer WiFi settings and QGroundControl link settings to match these changes. Are you sure you want to restart it?")
438 onButtonClicked: function (button, role) {
440 case MessageDialog.Yes:
442 rebootDialog.visible = false
444 case MessageDialog.No:
445 rebootDialog.visible = false
452 text: qsTr("Reset Counters")
453 width: _editFieldWidth
455 stResetCounters = true;
457 if(controller.vehicle)
458 controller.vehicle.resetCounters()