105
105
create Layout type QHBoxLayout
106
106
add Layout to Group
107
107
create SystemsCombo
108
+ on select SystemsCombo go to SystemsComboSelect
108
109
add stretch SystemsCombo to Layout
109
110
create ScanSystemsButton text `Scan`
110
111
disable ScanSystemsButton
133
134
create SlaveList
134
135
add SlaveList to Layout
135
136
136
- ! Create the Selected Devices group
137
+ ! Create the Selected Device group
137
138
create Group title `Selected device`
138
139
set the height of Group to 150
139
140
add Group to RightPanel
209
210
210
211
add stretch to RightPanel
211
212
212
- create StatusLabel
213
+ create StatusLabel align right
213
214
gosub to OK
214
215
add StatusLabel to RightPanel
215
216
235
236
variable IPAddr
236
237
variable MyIPAddr
237
238
variable Prompt
239
+ variable SystemConfig
238
240
variable SystemCallResult
239
241
variable StatusMessage
240
242
variable Systems
243
+ variable System
244
+ variable Devices
245
+ variable Device
246
+ variable MasterDevice
247
+ variable MasterSSID
248
+ variable MasterIPAddr
249
+ variable SlaveDevices
241
250
variable RBRFlag
242
251
variable Keys
252
+ variable D
243
253
variable N
244
254
variable P
255
+ variable S
245
256
246
257
! debug step
247
258
248
259
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
249
260
! The main program starts here
250
261
Start:
262
+
263
+ ! Load the main config file or create one if there is none
251
264
put trim system `echo $HOME` cat `/.rbr.conf` into ConfigFile
252
265
load Config from ConfigFile
253
266
if Config is empty put json `{}` into Config else put json Config into Config
254
- ! log `Config: ` cat Config
267
+
268
+ ! Look for the host SSID and password. If they're not found, scan for them
255
269
if Config does not have property `host-ssid`
256
270
begin
257
271
clear RBRFlag
@@ -261,25 +275,45 @@ Start:
261
275
if Config does not have property `host-password` gosub to GetHostPassword
262
276
set property `host-password` of Config to ReturnValue
263
277
end
278
+
279
+ ! Check we're on the right AP. If not, connect to it
264
280
put `Checking current SSID...` into StatusMessage
265
281
gosub to Working
266
282
put trim system `LANG=C nmcli -t -f active,ssid dev wifi | grep ^yes | cut -d: -f2-` into SSID
267
283
if SSID is not property `host-ssid` of Config gosub to ConnectToHost
268
284
put `Connected to ` cat SSID into StatusMessage
269
285
gosub to Idle
270
286
271
- if Config has property `systems`
272
- begin
273
- put property `systems` of Config into Systems
274
- end
287
+ ! Get the list of systems, or create an empty list. Then populate the combo box
288
+ if Config has property `systems` put property `systems` of Config into Systems
275
289
else
276
290
begin
277
291
put json `{}` into Systems
278
292
set property `systems` of Config to Systems
279
293
end
280
-
281
294
gosub to RefreshSystemsCombo
282
295
296
+ ! Read config data for each of the systems
297
+ gosub to GetConfigData
298
+
299
+ ! Select the current system
300
+ if Config has property `current` put property `current` of Config into Name
301
+ else
302
+ begin
303
+ if the count of SystemsCombo is 0 put empty into Name
304
+ else
305
+ begin
306
+ put the keys of Systems into Keys
307
+ put element 0 of Keys into Name
308
+ end
309
+ set property `current` of Config to Name
310
+ end
311
+ if Name is not empty
312
+ begin
313
+ select Name in SystemsCombo
314
+ gosub to SetupSystem
315
+ end
316
+
283
317
enable ScanSystemsButton
284
318
stop
285
319
@@ -319,19 +353,13 @@ ExitClick:
319
353
ScanSystemsClick:
320
354
log `Scan systems`
321
355
gosub to ScanSystems
356
+ gosub to RefreshSystemsCombo
357
+ gosub to GetConfigData
358
+ stop
322
359
323
- RefreshSystemsCombo:
324
- clear SystemsCombo
325
- put the keys of Systems into Keys
326
- put 0 into N
327
- while N is less than the count of Keys
328
- begin
329
- put element N of Keys into Name
330
- add Name to SystemsCombo
331
- enable RemoveSystemButton
332
- increment N
333
- end
334
- return
360
+ SystemsComboSelect:
361
+ set property `current` of Config to SystemsCombo
362
+ stop
335
363
336
364
RemoveSystemClick:
337
365
put SystemsCombo into Name
@@ -421,7 +449,7 @@ SelectSSIDFromList:
421
449
increment N
422
450
end
423
451
add ListBox to Layout
424
- on select in ListBox put the current item in ListBox into Item
452
+ on select ListBox put the current item in ListBox into Item
425
453
create SelectHostButton text `Select`
426
454
on click SelectHostButton
427
455
begin
@@ -477,7 +505,7 @@ GetAccessPoints:
477
505
SN2:
478
506
increment N
479
507
end
480
- log `SSIDs: ` cat List
508
+ ! log `SSIDs: ` cat List
481
509
return
482
510
483
511
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
@@ -506,7 +534,7 @@ ScanSystems:
506
534
increment P
507
535
put left P of MyIPAddr into Value
508
536
put json `[]` into List
509
- put 230 into N
537
+ put 1 into N
510
538
while N is less than 255
511
539
begin
512
540
put Value cat N into IPAddr
@@ -535,6 +563,73 @@ ScanSystems:
535
563
set property `systems` of Config to Systems
536
564
go to OK
537
565
566
+ !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
567
+ ! Get the config data for each of the systems
568
+ GetConfigData:
569
+ put the keys of Systems into Keys
570
+ put 0 into S
571
+ while S is less than the count of Keys
572
+ begin
573
+ put element S of Keys into Name
574
+ put property Name of Systems into SystemConfig
575
+ put property `mac` of SystemConfig into MAC
576
+ put property `password` of SystemConfig into Password
577
+ get Value from url `https://rbrheating.com/ui/resources/php/rest.php/config/`
578
+ cat MAC cat `/` cat Password
579
+ or log `Can't read the config file for ` cat Name
580
+ ! log Value cat newline
581
+ put json Value into Value
582
+ set property `devices` of SystemConfig to property `devices` of Value
583
+ set property Name of Systems to SystemConfig
584
+ increment S
585
+ end
586
+ set property `systems` of Config to Systems
587
+ return
588
+
589
+ !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
590
+ ! Refresh the systems combobox
591
+ RefreshSystemsCombo:
592
+ clear SystemsCombo
593
+ put the keys of Systems into Keys
594
+ put 0 into S
595
+ while S is less than the count of Keys
596
+ begin
597
+ put element S of Keys into Name
598
+ add Name to SystemsCombo
599
+ enable RemoveSystemButton
600
+ increment S
601
+ end
602
+ return
603
+
604
+ !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
605
+ ! Set up the system, given its name
606
+ SetupSystem:
607
+ put property Name of Systems into System
608
+ put property `devices` of System into Devices
609
+ put the keys of Devices into Keys
610
+ put empty into MasterDevice
611
+ put json `[]` into SlaveDevices
612
+ put 0 into D
613
+ while D is less than the count of Keys
614
+ begin
615
+ put element D of Keys into Name
616
+ put property Name of Devices into Device
617
+ if property `master` of Device
618
+ begin
619
+ put Device into MasterDevice
620
+ put property `ssid` of MasterDevice into MasterSSID
621
+ put property `ipaddr` of MasterDevice into MasterIPAddr
622
+ set the text of MasterDeviceLabel to MasterSSID cat ` ` cat Name cat ` ` cat MasterIPAddr
623
+ end
624
+ else
625
+ begin
626
+ append Name to SlaveDevices
627
+ add Name to SlaveList
628
+ end
629
+ increment D
630
+ end
631
+ return
632
+
538
633
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
539
634
! The Status box at the bottom of the screen
540
635
OK:
@@ -545,6 +640,6 @@ Idle:
545
640
return
546
641
547
642
Working:
548
- set the text of StatusLabel to `<font color="#ff8000 ">` cat StatusMessage cat `</font>`
643
+ set the text of StatusLabel to `<font color="#aa4000 ">` cat StatusMessage cat `</font>`
549
644
wait 50 ticks
550
645
return
0 commit comments