QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
ESP8266Component.qml
Go to the documentation of this file.
1import QtQuick
2import QtQuick.Controls
3import QtQuick.Dialogs
4import QtQuick.Layouts
5
6import QGroundControl
7import QGroundControl.FactControls
8import QGroundControl.Controls
9
10Item {
11
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
18
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
23
24 ESP8266ComponentController {
25 id: controller
26 }
27
28 Timer {
29 id: timer
30 }
31
32 function thisThingHasNoNumberLocaleSupport(n) {
33 return n.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",").replace(",,", ",")
34 }
35
36 function updateStatus() {
37 timer.stop()
38 var req = new XMLHttpRequest;
39 var url = "http://"
40 url += controller.wifiIPAddress
41 url += "/status.json"
42 if(stResetCounters) {
43 url = url + "?r=1"
44 stResetCounters = false
45 }
46 req.open("GET", url);
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
54 if(stErrorCount < 2)
55 timer.start()
56 } else {
57 //-- This should work but it doesn't
58 // var n = 34523453.345
59 // n.toLocaleString()
60 // "34,523,453.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"])
67 stErrorCount = 0
68 timer.start()
69 }
70 }
71 }
72 req.send()
73 }
74
75 Component.onCompleted: {
76 timer.interval = 1000
77 timer.repeat = true
78 timer.triggered.connect(updateStatus)
79 timer.start()
80 }
81
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")
86
87 Item {
88 id: panel
89 anchors.fill: parent
90
91 Flickable {
92 clip: true
93 anchors.fill: parent
94 contentHeight: mainCol.height
95 flickableDirection: Flickable.VerticalFlick
96 Column {
97 id: mainCol
98 spacing: _margins
99 anchors.horizontalCenter: parent.horizontalCenter
100 Item { width: 1; height: _margins * 0.5; }
101 QGCLabel {
102 text: qsTr("ESP WiFi Bridge Settings")
103 font.bold: true
104 }
105 Rectangle {
106 color: qgcPal.windowShade
107 width: statusLayout.width + _margins * 4
108 height: settingsRow.height + _margins * 2
109 Row {
110 id: settingsRow
111 spacing: _margins * 4
112 anchors.centerIn: parent
113 QGCColoredImage {
114 color: qgcPal.text
115 width: ScreenTools.defaultFontPixelWidth * 12
116 height: width * 1.45
117 sourceSize.height: width * 1.45
118 mipmap: true
119 fillMode: Image.PreserveAspectFit
120 source: wifiMode ? (wifiMode.value === 0 ? "/qmlimages/APMode.svg" : "/qmlimages/StationMode.svg") : "/qmlimages/APMode.svg"
121 anchors.verticalCenter: parent.verticalCenter
122 }
123 Column {
124 spacing: _margins * 0.5
125 anchors.verticalCenter: parent.verticalCenter
126 Row {
127 visible: wifiMode
128 QGCLabel {
129 text: qsTr("WiFi Mode")
130 width: _middleRowWidth
131 anchors.baseline: modeField.baseline
132 }
133 QGCComboBox {
134 id: modeField
135 width: _editFieldWidth
136 model: ["Access Point Mode", "Station Mode"]
137 currentIndex: wifiMode ? wifiMode.value : 0
138 onActivated: (index) => {
139 wifiMode.value = index
140 }
141 }
142 }
143 Row {
144 QGCLabel {
145 text: qsTr("WiFi Channel")
146 width: _middleRowWidth
147 anchors.baseline: channelField.baseline
148 }
149 QGCComboBox {
150 id: channelField
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
157 }
158 }
159 }
160 Row {
161 QGCLabel {
162 text: qsTr("WiFi AP SSID")
163 width: _middleRowWidth
164 anchors.baseline: ssidField.baseline
165 }
166 QGCTextField {
167 id: ssidField
168 width: _editFieldWidth
169 text: controller.wifiSSID
170 maximumLength: 16
171 onEditingFinished: {
172 controller.wifiSSID = text
173 }
174 }
175 }
176 Row {
177 QGCLabel {
178 text: qsTr("WiFi AP Password")
179 width: _middleRowWidth
180 anchors.baseline: passwordField.baseline
181 }
182 QGCTextField {
183 id: passwordField
184 width: _editFieldWidth
185 text: controller.wifiPassword
186 maximumLength: 16
187 onEditingFinished: {
188 controller.wifiPassword = text
189 }
190 }
191 }
192 Row {
193 QGCLabel {
194 text: qsTr("WiFi STA SSID")
195 width: _middleRowWidth
196 anchors.baseline: stassidField.baseline
197 }
198 QGCTextField {
199 id: stassidField
200 width: _editFieldWidth
201 text: controller.wifiSSIDSta
202 maximumLength: 16
203 enabled: wifiMode && wifiMode.value === 1
204 onEditingFinished: {
205 controller.wifiSSIDSta = text
206 }
207 }
208 }
209 Row {
210 QGCLabel {
211 text: qsTr("WiFi STA Password")
212 width: _middleRowWidth
213 anchors.baseline: passwordStaField.baseline
214 }
215 QGCTextField {
216 id: passwordStaField
217 width: _editFieldWidth
218 text: controller.wifiPasswordSta
219 maximumLength: 16
220 enabled: wifiMode && wifiMode.value === 1
221 onEditingFinished: {
222 controller.wifiPasswordSta = text
223 }
224 }
225 }
226 Row {
227 QGCLabel {
228 text: qsTr("UART Baud Rate")
229 width: _middleRowWidth
230 anchors.baseline: baudField.baseline
231 }
232 QGCComboBox {
233 id: baudField
234 width: _editFieldWidth
235 model: controller.baudRates
236 currentIndex: controller.baudIndex
237 onActivated: (index) => {
238 controller.baudIndex = index
239 }
240 }
241 }
242 Row {
243 QGCLabel {
244 text: qsTr("QGC UDP Port")
245 width: _middleRowWidth
246 anchors.baseline: qgcportField.baseline
247 }
248 QGCTextField {
249 id: qgcportField
250 width: _editFieldWidth
251 text: hostPort ? hostPort.valueString : ""
252 validator: IntValidator {bottom: 1024; top: 65535;}
253 inputMethodHints: Qt.ImhDigitsOnly
254 onEditingFinished: {
255 hostPort.value = text
256 }
257 }
258 }
259 }
260 }
261 }
262 QGCLabel {
263 text: qsTr("ESP WiFi Bridge Status")
264 font.bold: true
265 }
266 Rectangle {
267 color: qgcPal.windowShade
268 width: statusLayout.width + _margins * 4
269 height: statusLayout.height + _margins * 2
270 GridLayout {
271 id: statusLayout
272 columns: 3
273 columnSpacing: _margins * 2
274 anchors.centerIn: parent
275 QGCLabel {
276 text: qsTr("Bridge/Vehicle Link")
277 Layout.alignment: Qt.AlignHCenter
278 }
279 QGCLabel {
280 text: qsTr("Bridge/QGC Link")
281 Layout.alignment: Qt.AlignHCenter
282 }
283 QGCLabel {
284 text: qsTr("QGC/Bridge Link")
285 Layout.alignment: Qt.AlignHCenter
286 }
287 Row {
288 spacing: _margins
289 QGCLabel {
290 text: qsTr("Messages Received")
291 font.pointSize: _smallFont
292 width: _labelWidth
293 }
294 QGCLabel {
295 id: vpackets
296 font.pointSize: _smallFont
297 width: _statusWidth
298 horizontalAlignment: Text.AlignRight
299 }
300 }
301 Row {
302 spacing: _margins
303 QGCLabel {
304 font.pointSize: _smallFont
305 text: qsTr("Messages Received")
306 width: _labelWidth
307 }
308 QGCLabel {
309 id: gpackets
310 font.pointSize: _smallFont
311 width: _statusWidth
312 horizontalAlignment: Text.AlignRight
313 }
314 }
315 Row {
316 spacing: _margins
317 QGCLabel {
318 font.pointSize: _smallFont
319 text: qsTr("Messages Received")
320 width: _labelWidth
321 }
322 QGCLabel {
323 font.pointSize: _smallFont
324 text: controller.vehicle ? thisThingHasNoNumberLocaleSupport(controller.vehicle.messagesReceived) : 0
325 width: _statusWidth
326 horizontalAlignment: Text.AlignRight
327 }
328 }
329 Row {
330 spacing: _margins
331 QGCLabel {
332 text: qsTr("Messages Lost")
333 font.pointSize: _smallFont
334 width: _labelWidth
335 }
336 QGCLabel {
337 id: vlost
338 width: _statusWidth
339 horizontalAlignment: Text.AlignRight
340 font.pointSize: _smallFont
341 }
342 }
343 Row {
344 spacing: _margins
345 QGCLabel {
346 text: qsTr("Messages Lost")
347 font.pointSize: _smallFont
348 width: _labelWidth
349 }
350 QGCLabel {
351 id: glost
352 width: _statusWidth
353 horizontalAlignment: Text.AlignRight
354 font.pointSize: _smallFont
355 }
356 }
357 Row {
358 spacing: _margins
359 QGCLabel {
360 text: qsTr("Messages Lost")
361 font.pointSize: _smallFont
362 width: _labelWidth
363 }
364 QGCLabel {
365 text: controller.vehicle ? thisThingHasNoNumberLocaleSupport(controller.vehicle.messagesLost) : 0
366 width: _statusWidth
367 horizontalAlignment: Text.AlignRight
368 font.pointSize: _smallFont
369 }
370 }
371 Row {
372 spacing: _margins
373 QGCLabel {
374 text: qsTr("Messages Sent")
375 font.pointSize: _smallFont
376 width: _labelWidth
377 }
378 QGCLabel {
379 id: vsent
380 width: _statusWidth
381 horizontalAlignment: Text.AlignRight
382 font.pointSize: _smallFont
383 }
384 }
385 Row {
386 spacing: _margins
387 QGCLabel {
388 text: qsTr("Messages Sent")
389 font.pointSize: _smallFont
390 width: _labelWidth
391 }
392 QGCLabel {
393 id: gsent
394 width: _statusWidth
395 horizontalAlignment: Text.AlignRight
396 font.pointSize: _smallFont
397 }
398 }
399 Row {
400 spacing: _margins
401 QGCLabel {
402 text: qsTr("Messages Sent")
403 font.pointSize: _smallFont
404 width: _labelWidth
405 }
406 QGCLabel {
407 text: controller.vehicle ? thisThingHasNoNumberLocaleSupport(controller.vehicle.messagesSent) : 0
408 width: _statusWidth
409 horizontalAlignment: Text.AlignRight
410 font.pointSize: _smallFont
411 }
412 }
413 }
414 }
415 Row {
416 spacing: _margins
417 anchors.horizontalCenter: parent.horizontalCenter
418 QGCButton {
419 text: qsTr("Restore Defaults")
420 width: _editFieldWidth
421 onClicked: {
422 controller.restoreDefaults()
423 }
424 }
425 QGCButton {
426 text: qsTr("Restart WiFi Bridge")
427 enabled: !controller.busy
428 width: _editFieldWidth
429 onClicked: {
430 rebootDialog.visible = true
431 }
432 MessageDialog {
433 id: rebootDialog
434 visible: false
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) {
439 switch (button) {
440 case MessageDialog.Yes:
441 controller.reboot()
442 rebootDialog.visible = false
443 break;
444 case MessageDialog.No:
445 rebootDialog.visible = false
446 break;
447 }
448 }
449 }
450 }
451 QGCButton {
452 text: qsTr("Reset Counters")
453 width: _editFieldWidth
454 onClicked: {
455 stResetCounters = true;
456 updateStatus()
457 if(controller.vehicle)
458 controller.vehicle.resetCounters()
459 }
460 }
461 }
462 }
463 }
464 }
465}