223
223
224
224
variable Config
225
225
variable ConfigFile
226
+ variable Hosts
226
227
variable Name
227
228
variable Value
228
229
variable ReturnValue
232
233
variable Item
233
234
variable HostSSID
234
235
variable HostPassword
236
+ variable SystemHostSSID
235
237
variable SSID
236
238
variable MAC
237
239
variable Password
@@ -292,18 +294,26 @@ Start:
292
294
put trim system `echo $HOME` cat `/.rbr.conf` into ConfigFile
293
295
load Config from ConfigFile
294
296
if Config is empty put json `{}` into Config else put json Config into Config
297
+ if Config does not have property `hosts` set property `hosts` of Config to json `{}`
298
+ if Config does not have property `systems` set property `systems` of Config to json `{}`
299
+ if Config does not have property `current-system` set property `current-system` of Config to empty
300
+ put property `hosts` of Config into Hosts
295
301
296
- ! Look for the host SSID and password. If they're not found, scan for them
297
- if Config does not have property `host-ssid` gosub to GetHost
298
-
299
- put property `host-ssid` of Config into HostSSID
300
- put property `host-password` of Config into HostPassword
301
-
302
- ! Check we're on the right AP. If not, connect to it
303
- put `Checking current SSID...` into StatusMessage
302
+ ! Get the host SSID
303
+ put `Getting host SSID...` into StatusMessage
304
304
gosub to Working
305
305
put trim system `LANG=C nmcli -t -f active,ssid dev wifi | grep ^yes | cut -d: -f2-` into HostSSID
306
- if HostSSID is not property `host-ssid` of Config gosub to ConnectToHost
306
+ if Hosts has property HostSSID put property HostSSID of Hosts into HostPassword
307
+ else
308
+ begin
309
+ gosub to GetHostPassword
310
+ if HostPassword is not empty
311
+ begin
312
+ set property HostSSID of Hosts to HostPassword
313
+ set property `hosts` of Config to Hosts
314
+ end
315
+ end
316
+ save prettify Config to ConfigFile
307
317
put `Connected to ` cat HostSSID into StatusMessage
308
318
gosub to Idle
309
319
@@ -316,8 +326,7 @@ Start:
316
326
end
317
327
gosub to RefreshSystemsCombo
318
328
319
- ! gosub to GetAllConfigData
320
- if ErrorFlag stop
329
+ put empty into SystemHostSSID
321
330
322
331
! Select the current system
323
332
if the count of SystemsCombo is 0 put empty into SystemName
@@ -326,7 +335,7 @@ Start:
326
335
put the keys of Systems into Keys
327
336
put element 0 of Keys into SystemName
328
337
end
329
- set property `current` of Config to SystemName
338
+ set property `current-system ` of Config to SystemName
330
339
if SystemName is not empty
331
340
begin
332
341
select SystemName in SystemsCombo
@@ -361,7 +370,6 @@ ScanSystemsClick:
361
370
log `Scan for system controllers`
362
371
disable ScanSystemsButton
363
372
gosub to ScanSystems
364
- ! if SystemName is not empty gosub to GetConfigData
365
373
gosub to RefreshSystemsCombo
366
374
gosub to PostConfigData
367
375
gosub to ManageButtonStates
@@ -395,21 +403,50 @@ ScanSystems:
395
403
increment P
396
404
put from P of Result into SystemName
397
405
put json `{}` into SystemConfig
406
+ set property `host-ssid` of SystemConfig to HostSSID
407
+ set property `host-password` of SystemConfig to HostPassword
398
408
set property `ipaddr` of SystemConfig to IPAddr
399
409
set property `mac` of SystemConfig to SystemMAC
400
410
set property `password` of SystemConfig to SystemPassword
401
411
set property `devices` of SystemConfig to json `{}`
402
412
log `Adding ` cat SystemName cat ` to Systems`
403
413
gosub UpdateSystems
414
+ log prettify SystemConfig
404
415
gosub to GetConfigData
405
416
SS2:
406
417
wait 10 ticks
407
418
increment N
408
419
end
409
- set property `current` of Config to SystemName
420
+ set property `current-system ` of Config to SystemName
410
421
log `After scan: ` cat prettify Config
411
422
go to OK
412
423
424
+ !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
425
+ ! Get the config data for a system
426
+ GetConfigData:
427
+ gosub to SetBusy
428
+ if SystemName is empty return
429
+ log `Get the config data for ` cat SystemName
430
+ put property `devices` of SystemConfig into Devices
431
+ get Value from url `https://rbrheating.com/ui/resources/php/rest.php/config/`
432
+ cat SystemMAC cat `/` cat SystemPassword
433
+ or
434
+ begin
435
+ put `Can't read the config file for ` cat SystemName cat `(` cat MAC cat `/` cat Password cat `)` into StatusMessage
436
+ go to Error
437
+ end
438
+ ! If the server has data, use it instead of the local config
439
+ if Value is empty put `{}` into Value
440
+ if Value is not `{}`
441
+ begin
442
+ log `Use config data from the server`
443
+ put json Value into SystemConfig
444
+ gosub to UpdateSystems
445
+ end
446
+ log prettify SystemConfig
447
+ gosub to PostConfigData
448
+ return
449
+
413
450
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
414
451
! Refresh the systems combobox
415
452
RefreshSystemsCombo:
@@ -433,11 +470,12 @@ SystemsComboSelect:
433
470
if SystemName is not empty
434
471
begin
435
472
log `Select system ` cat SystemName
436
- set property `current` of Config to SystemName
473
+ set property `current-system ` of Config to SystemName
437
474
put property SystemName of Systems into SystemConfig
438
475
gosub to PopulateSystemInfo
439
476
end
440
477
gosub to ManageButtonStates
478
+ if not ErrorFlag gosub to OK
441
479
stop
442
480
443
481
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
@@ -456,8 +494,9 @@ RemoveSystemClick:
456
494
remove the current item from SystemsCombo
457
495
delete property SystemName of Systems
458
496
put empty into SystemName
459
- set property `current` of Config to SystemsCombo
497
+ set property `current-system ` of Config to SystemsCombo
460
498
set property `systems` of Config to Systems
499
+ put empty into SystemHostSSID
461
500
gosub to PostConfigData
462
501
end
463
502
if the count of SystemsCombo is 0 disable RemoveSystemButton
@@ -468,38 +507,6 @@ RemoveSystemClick:
468
507
gosub to ManageButtonStates
469
508
stop
470
509
471
- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
472
- ! Get the config data for a system
473
- GetConfigData:
474
- gosub to SetBusy
475
- if SystemName is empty return
476
- log `Get the config data for ` cat SystemName
477
- ! put property `systems` of Config into Systems
478
- put property SystemName of Systems into SystemConfig
479
- put property `mac` of SystemConfig into SystemMAC
480
- put property `devices` of SystemConfig into Devices
481
- put property `password` of SystemConfig into SystemPassword
482
- get Value from url `https://rbrheating.com/ui/resources/php/rest.php/config/`
483
- cat SystemMAC cat `/` cat SystemPassword
484
- or
485
- begin
486
- put `Can't read the config file for ` cat SystemName cat `(` cat MAC cat `/` cat Password cat `)` into StatusMessage
487
- go to Error
488
- end
489
- ! If the server has data, use it instead of the local config
490
- ! put json Value into Value
491
- ! log `Value: ` cat prettify Value
492
- ! return
493
- ! put empty into Value
494
- if Value is not empty
495
- begin
496
- log `Use config data from the server`
497
- put json Value into SystemConfig
498
- gosub to UpdateSystems
499
- end
500
- gosub to PostConfigData
501
- return
502
-
503
510
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
504
511
! Clear all the data for the selected system
505
512
ClearSystemClick:
@@ -787,6 +794,28 @@ CreateDevice:
787
794
! Populate the system information fields
788
795
PopulateSystemInfo:
789
796
log `Populate fields for ` cat SystemName
797
+ put property `host-ssid` of SystemConfig into SystemHostSSID
798
+ if SystemHostSSID is not HostSSID
799
+ begin
800
+ put property SystemHostSSID of Hosts into Password
801
+ put `Connect to host ` cat SystemHostSSID cat ` with password ` cat Password into StatusMessage
802
+ gosub to Working
803
+ put system `nmcli dev wifi connect ` cat SystemHostSSID cat ` password ` cat Password into SystemCallResult
804
+ split SystemCallResult on ` `
805
+ if the elements of SystemCallResult is greater than 2
806
+ begin
807
+ index SystemCallResult to 2
808
+ if SystemCallResult is `successfully`
809
+ begin
810
+ put SystemHostSSID into HostSSID
811
+ put HostSSID into CurrentSSID
812
+ put `Connected to ` cat HostSSID into StatusMessage
813
+ go to Idle
814
+ end
815
+ end
816
+ put `Failed to connect to ` cat HostSSID into StatusMessage
817
+ go to Error
818
+ end
790
819
put property `mac` of SystemConfig into SystemMAC
791
820
put property `password` of SystemConfig into SystemPassword
792
821
put property `devices` of SystemConfig into Devices
@@ -926,7 +955,9 @@ GetHostPassword:
926
955
log `Get the host password`
927
956
put `Type the host password:` into Prompt
928
957
put `Host password` into Title
929
- go to GetRequestedText
958
+ gosub to GetRequestedText
959
+ put ReturnValue into HostPassword
960
+ return
930
961
931
962
GetRequestedText:
932
963
create VLayout type QVBoxLayout
@@ -942,15 +973,14 @@ GetRequestedText:
942
973
on click OKButton
943
974
begin
944
975
put LineInput into ReturnValue
945
- put `OK` into Result
946
976
close Dialog
947
977
return
948
978
end
949
979
add OKButton to HLayout
950
980
create CancelButton text `Cancel` size 6
951
981
on click CancelButton
952
982
begin
953
- put `Cancel` into Result
983
+ put empty into ReturnValue
954
984
close Dialog
955
985
return
956
986
end
@@ -998,8 +1028,6 @@ GetAccessPoints:
998
1028
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
999
1029
! Connect to the host router
1000
1030
ConnectToHost:
1001
- put property `host-ssid` of Config into HostSSID
1002
- put property `host-password` of Config into HostPassword
1003
1031
put `Connect to host ` cat HostSSID cat ` with password ` cat HostPassword into StatusMessage
1004
1032
gosub to Working
1005
1033
put system `nmcli dev wifi connect ` cat HostSSID cat ` password ` cat HostPassword into SystemCallResult
@@ -1011,22 +1039,18 @@ ConnectToHost:
1011
1039
begin
1012
1040
put HostSSID into CurrentSSID
1013
1041
put `Connected to ` cat HostSSID into StatusMessage
1014
- log StatusMessage
1015
- go to Working
1042
+ go to Idle
1016
1043
end
1017
1044
end
1018
1045
put `Failed to connect to ` cat HostSSID into StatusMessage
1019
- ! Fall into GetHost
1020
-
1021
- GetHost:
1022
1046
gosub to GetAccessPoints
1023
1047
put `Select HostSSID` into Title
1024
1048
put `Select the home router for this system` into Prompt
1025
1049
gosub to SelectSSIDFromList
1026
1050
if HostSSID is empty go to Start
1027
1051
set property `host-ssid` of Config to HostSSID
1028
1052
if Config does not have property `host-password` gosub to GetHostPassword
1029
- set property `host-password` of Config to ReturnValue
1053
+ set property `host-password` of Config to HostPassword
1030
1054
go to ConnectToHost
1031
1055
1032
1056
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
@@ -1263,6 +1287,8 @@ Error:
1263
1287
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1264
1288
! Enable or disable the various buttons
1265
1289
ManageButtonStates:
1290
+ if SystemHostSSID is not empty
1291
+ if SystemHostSSID is not HostSSID go to SetBusy
1266
1292
! ScanDevicesButton
1267
1293
if the count of SystemsCombo is 0 disable ScanDevicesButton else enable ScanDevicesButton
1268
1294
! ClearSystemButton
0 commit comments