105105 create Layout type QHBoxLayout
106106 add Layout to Group
107107 create SystemsCombo
108+ on select SystemsCombo go to SystemsComboSelect
108109 add stretch SystemsCombo to Layout
109110 create ScanSystemsButton text `Scan`
110111 disable ScanSystemsButton
133134 create SlaveList
134135 add SlaveList to Layout
135136
136- ! Create the Selected Devices group
137+ ! Create the Selected Device group
137138 create Group title `Selected device`
138139 set the height of Group to 150
139140 add Group to RightPanel
209210
210211 add stretch to RightPanel
211212
212- create StatusLabel
213+ create StatusLabel align right
213214 gosub to OK
214215 add StatusLabel to RightPanel
215216
235236 variable IPAddr
236237 variable MyIPAddr
237238 variable Prompt
239+ variable SystemConfig
238240 variable SystemCallResult
239241 variable StatusMessage
240242 variable Systems
243+ variable System
244+ variable Devices
245+ variable Device
246+ variable MasterDevice
247+ variable MasterSSID
248+ variable MasterIPAddr
249+ variable SlaveDevices
241250 variable RBRFlag
242251 variable Keys
252+ variable D
243253 variable N
244254 variable P
255+ variable S
245256
246257! debug step
247258
248259!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
249260! The main program starts here
250261Start:
262+
263+ ! Load the main config file or create one if there is none
251264 put trim system `echo $HOME` cat `/.rbr.conf` into ConfigFile
252265 load Config from ConfigFile
253266 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
255269 if Config does not have property `host-ssid`
256270 begin
257271 clear RBRFlag
@@ -261,25 +275,45 @@ Start:
261275 if Config does not have property `host-password` gosub to GetHostPassword
262276 set property `host-password` of Config to ReturnValue
263277 end
278+
279+ ! Check we're on the right AP. If not, connect to it
264280 put `Checking current SSID...` into StatusMessage
265281 gosub to Working
266282 put trim system `LANG=C nmcli -t -f active,ssid dev wifi | grep ^yes | cut -d: -f2-` into SSID
267283 if SSID is not property `host-ssid` of Config gosub to ConnectToHost
268284 put `Connected to ` cat SSID into StatusMessage
269285 gosub to Idle
270286
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
275289 else
276290 begin
277291 put json `{}` into Systems
278292 set property `systems` of Config to Systems
279293 end
280-
281294 gosub to RefreshSystemsCombo
282295
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+
283317 enable ScanSystemsButton
284318 stop
285319
@@ -319,19 +353,13 @@ ExitClick:
319353ScanSystemsClick:
320354 log `Scan systems`
321355 gosub to ScanSystems
356+ gosub to RefreshSystemsCombo
357+ gosub to GetConfigData
358+ stop
322359
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
335363
336364RemoveSystemClick:
337365 put SystemsCombo into Name
@@ -421,7 +449,7 @@ SelectSSIDFromList:
421449 increment N
422450 end
423451 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
425453 create SelectHostButton text `Select`
426454 on click SelectHostButton
427455 begin
@@ -477,7 +505,7 @@ GetAccessPoints:
477505 SN2:
478506 increment N
479507 end
480- log `SSIDs: ` cat List
508+ ! log `SSIDs: ` cat List
481509 return
482510
483511!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
@@ -506,7 +534,7 @@ ScanSystems:
506534 increment P
507535 put left P of MyIPAddr into Value
508536 put json `[]` into List
509- put 230 into N
537+ put 1 into N
510538 while N is less than 255
511539 begin
512540 put Value cat N into IPAddr
@@ -535,6 +563,73 @@ ScanSystems:
535563 set property `systems` of Config to Systems
536564 go to OK
537565
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+
538633!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
539634! The Status box at the bottom of the screen
540635OK:
@@ -545,6 +640,6 @@ Idle:
545640 return
546641
547642Working:
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>`
549644 wait 50 ticks
550645 return
0 commit comments