18
18
label Label
19
19
label RelayStateLabel
20
20
label StatusLabel
21
+ label SSIDLabel
21
22
pushbutton ResetConfigButton
22
23
pushbutton ScanDevicesButton
23
24
pushbutton ClearSystemButton
24
- pushbutton DeleteSlaveButton
25
+ pushbutton RemoveSlaveButton
25
26
pushbutton UpdateDeviceButton
26
27
pushbutton DeleteFileButton
27
28
pushbutton ExitButton
30
31
pushbutton MasterDeviceButton
31
32
pushbutton RelayOffButton
32
33
pushbutton RelayOnButton
33
- pushbutton SaveWidgetDataButton
34
+ pushbutton UpdateWidgetDataButton
34
35
pushbutton OKButton
35
36
pushbutton CancelButton
36
37
lineinput LineInput
37
38
lineinput DeviceNameInput
38
- lineinput ChannelInput
39
39
lineinput LEDPinInput
40
40
lineinput RelayPinInput
41
41
lineinput DHT22PinInput
82
82
add DeleteFileButton to LeftPanel
83
83
on click DeleteFileButton go to DeleteFileClick
84
84
85
- create DeleteSlaveButton text `Delete slave`
86
- add DeleteSlaveButton to LeftPanel
87
- on click DeleteSlaveButton go to DeleteSlaveClick
85
+ create RemoveSlaveButton text `Remove slave`
86
+ add RemoveSlaveButton to LeftPanel
87
+ on click RemoveSlaveButton go to RemoveSlaveClick
88
88
89
89
add stretch to LeftPanel
90
90
152
152
add Label to Layout
153
153
create DeviceNameInput size 40
154
154
add DeviceNameInput to Layout
155
- create Label text `Channel :`
155
+ create Label text `SSID :`
156
156
add Label to Layout
157
- create ChannelInput size 5
158
- add ChannelInput to Layout
157
+ create SSIDLabel
158
+ add SSIDLabel to Layout
159
159
add stretch to Layout
160
160
161
161
create Layout type QHBoxLayout
199
199
create Label text `Path:`
200
200
add Label to Layout
201
201
create PathInput size 60
202
+ set the width of PathInput to 250
202
203
add PathInput to Layout
203
204
add stretch to Layout
204
205
205
- ! The 'Save' button
206
- create Layout type QVBoxLayout
207
- add Layout to DeviceHPanel
208
- create SaveWidgetDataButton text `Save`
209
- on click SaveWidgetDataButton go to SaveWidgetData
210
- add SaveWidgetDataButton to Layout
206
+ ! The 'Update' button
207
+ create UpdateWidgetDataButton text `Update`
208
+ on click UpdateWidgetDataButton go to UpdateWidgetDataClick
209
+ add UpdateWidgetDataButton to DeviceHPanel
211
210
212
211
add stretch to RightPanel
213
212
222
221
223
222
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
224
223
224
+ stack Stack
225
225
variable Config
226
226
variable ConfigFile
227
227
variable Name
248
248
variable Message2
249
249
variable Response
250
250
variable Systems
251
- variable System
252
251
variable Devices
253
252
variable Device
254
253
variable MasterDevice
278
277
variable Pins
279
278
variable Pin
280
279
variable D
280
+ variable K
281
281
variable N
282
282
variable P
283
283
variable S
@@ -291,7 +291,7 @@ Start:
291
291
! Disable various buttons
292
292
disable ClearSystemButton
293
293
disable ScanDevicesButton
294
- disable DeleteSlaveButton
294
+ disable RemoveSlaveButton
295
295
disable UpdateDeviceButton
296
296
disable DeleteFileButton
297
297
@@ -345,7 +345,6 @@ Start:
345
345
begin
346
346
select Name in SystemsCombo
347
347
enable ClearSystemButton
348
- gosub to SetupSystem
349
348
end
350
349
351
350
enable ScanSystemsButton
@@ -390,7 +389,6 @@ ClearSystemClick:
390
389
put json `{}` into Devices
391
390
set property `devices` of SystemConfig to Devices
392
391
set property Name of Systems to SystemConfig
393
- set property `systems` of Config to Systems
394
392
set the text of MasterDeviceButton to `(none)`
395
393
put empty into MasterSSID
396
394
clear SlaveList
@@ -484,7 +482,6 @@ ScanForDevicesClick:
484
482
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
485
483
! Show information about the master device
486
484
MasterDeviceClick:
487
- log MasterDeviceButton
488
485
if MasterDeviceButton is not empty
489
486
begin
490
487
log `Select the master device`
@@ -497,9 +494,10 @@ MasterDeviceClick:
497
494
! Show information about a slave device
498
495
SelectSlaveClick:
499
496
log `Select ` cat SlaveList
500
- set the text of DeviceNameInput to SlaveList
497
+ put property SlaveList of Devices into Device
498
+ gosub to PopulateDeviceInfo
501
499
enable UpdateDeviceButton
502
- enable DeleteSlaveButton
500
+ enable RemoveSlaveButton
503
501
enable DeleteFileButton
504
502
stop
505
503
@@ -511,8 +509,32 @@ DeleteFileClick:
511
509
log `Delete a file on the selected device`
512
510
stop
513
511
514
- DeleteSlaveClick:
515
- log `Delete the selected slave device`
512
+ !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
513
+ ! Remove a slave from the list
514
+ RemoveSlaveClick:
515
+ log `Remove the selected slave device`
516
+ put SlaveList into Name
517
+ log Name
518
+ remove the selected item from SlaveList
519
+ put the keys of Devices into Keys
520
+ put 0 into D
521
+ while D is less than the count of Keys
522
+ begin
523
+ put element D of Keys into Name
524
+ put property Name of Devices into Device
525
+ if property `master` of Device is false
526
+ begin
527
+ if property `name` of Device is Name
528
+ begin
529
+ delete property Name of Devices
530
+ ! set property `devices` of SystemConfig to Devices
531
+ put property `name` of SystemConfig into Name
532
+ set property Name of Systems to SystemConfig
533
+ stop
534
+ end
535
+ end
536
+ increment D
537
+ end
516
538
stop
517
539
518
540
ScanSystemsClick:
@@ -540,7 +562,7 @@ RemoveSystemClick:
540
562
show MessageBox giving Value
541
563
if Value is `Yes`
542
564
begin
543
- remove current item from SystemsCombo
565
+ remove the current item from SystemsCombo
544
566
delete property Name of Systems
545
567
set property `systems` of Config to Systems
546
568
end
@@ -551,8 +573,13 @@ SaveHostInfoClick:
551
573
log `Save the host information`
552
574
stop
553
575
554
- SaveWidgetDataClick:
555
- log `Save the widget data`
576
+ UpdateWidgetDataClick:
577
+ log Device
578
+ set property `name` of Device to DeviceNameInput
579
+ log Device
580
+ put property `ssid` of Device into SSID
581
+ put from 8 of SSID into MAC
582
+ gosub to SendConfigFile
556
583
stop
557
584
558
585
RelayOffClick:
@@ -565,7 +592,8 @@ RelayOnClick:
565
592
566
593
ExitClick:
567
594
log `Exit the configurator`
568
- save stringify Config to ConfigFile
595
+ ! delete property `(none)` of Config
596
+ save prettify Config to ConfigFile
569
597
close Window
570
598
exit
571
599
@@ -766,21 +794,32 @@ GetConfigData:
766
794
while S is less than the count of Keys
767
795
begin
768
796
put element S of Keys into Name
797
+ ! SystemConfig holds the data for a single system; Systems holds all of the SystemConfigs by system name
798
+ ! Get the data for this system
769
799
put property Name of Systems into SystemConfig
770
- put property `mac` of SystemConfig into MAC
771
- put property `password` of SystemConfig into Password
800
+ put property `mac` of SystemConfig into SystemMAC
801
+ put property `password` of SystemConfig into SystemPassword
772
802
get Value from url `https://rbrheating.com/ui/resources/php/rest.php/config/`
773
- cat MAC cat `/` cat Password
803
+ cat SystemMAC cat `/` cat SystemPassword
774
804
or
775
805
begin
776
806
put `Can't read the config file for ` cat Name cat `(` cat MAC cat `/` cat Password cat `)` into StatusMessage
777
807
go to Error
778
808
end
779
- ! log Value cat newline
780
809
put json Value into Value
781
- if Value has property `devices`
782
- set property `devices` of SystemConfig to property `devices` of Value
783
- else set property `devices` of SystemConfig to json `{}`
810
+ push Name onto Stack
811
+ push Keys onto Stack
812
+ put the keys of Value into Keys
813
+ put 0 into K
814
+ while K is less than the count of Keys
815
+ begin
816
+ put element K of Keys into Name
817
+ put property Name of Value into Item
818
+ set property Name of SystemConfig to Item
819
+ increment K
820
+ end
821
+ pop Keys from Stack
822
+ pop Name from Stack
784
823
set property Name of Systems to SystemConfig
785
824
increment S
786
825
end
@@ -806,10 +845,10 @@ RefreshSystemsCombo:
806
845
! Set up the system, given its name
807
846
SetupSystem:
808
847
if Name is empty return
809
- put property Name of Systems into System
810
- put property `mac` of System into SystemMAC
811
- put property `password` of System into SystemPassword
812
- put property `devices` of System into Devices
848
+ put property Name of Systems into SystemConfig
849
+ put property `mac` of SystemConfig into SystemMAC
850
+ put property `password` of SystemConfig into SystemPassword
851
+ put property `devices` of SystemConfig into Devices
813
852
put the keys of Devices into Keys
814
853
put empty into MasterDevice
815
854
set the text of MasterDeviceButton to `(none)`
@@ -890,17 +929,14 @@ SetupDevice:
890
929
if MasterSSID is empty
891
930
begin
892
931
set IsMaster
893
- log `Deal with slave ` cat Name
932
+ log `Deal with master ` cat Name
894
933
put SSID into MasterSSID
895
934
put Name into MasterDeviceName
896
935
gosub to CreateDevice
897
936
put Device into MasterDevice
898
- ! Send the config data to the device
899
- put `config.json` into FileName
900
- put stringify MasterDevice into Content
901
937
put MAC into MasterMAC
902
938
put IPAddr into MasterIPAddr
903
- gosub to SendFileToDevice
939
+ gosub to SendConfigFile
904
940
if SendFail return
905
941
gosub to RequestReset
906
942
if SendFail return
@@ -911,6 +947,8 @@ SetupDevice:
911
947
put MasterSSID cat ` ` cat MasterName into StatusMessage
912
948
gosub to Working
913
949
disable MasterDeviceButton
950
+
951
+ ! Get the master IP address
914
952
put `http://` cat MasterIPAddr cat `/?mac=` cat MasterMAC cat `&msg=ipaddr` into URL
915
953
put `Interrogate the master device` into StatusMessage
916
954
gosub to Working
@@ -926,33 +964,27 @@ SetupDevice:
926
964
gosub to Idle
927
965
set the text of MasterDeviceButton to MasterSSID cat ` ` cat MasterName cat ` ` cat MasterIPAddr cat ` ` cat Name
928
966
set property `ipaddr` of MasterDevice to MasterIPAddr
929
- set property MasterName of Devices to MasterDevice
930
- set property `devices` of Config to Devices
931
967
end
932
968
else
933
969
begin
934
- delete property Name of Devices
935
- set property `devices` of Config to Devices
936
970
put `Failed to get Master ip address` into StatusMessage
937
971
go to Error
938
972
end
939
- disable DeleteSlaveButton
973
+ disable RemoveSlaveButton
940
974
enable MasterDeviceButton
941
975
put MasterDevice into Device
942
976
gosub to PopulateDeviceInfo
943
977
end
944
978
else
945
979
begin
980
+ clear IsMaster
946
981
log `Deal with slave ` cat Name
982
+ put the position of ` ` in Name into N
983
+ increment N
984
+ put from N of Name into Name
947
985
append SSID cat ` ` cat Name to SlaveDevices
948
986
set SlaveList to SlaveDevices
949
- clear IsMaster
950
987
gosub to CreateDevice
951
- put `config.json` into FileName
952
- put stringify Device into Content
953
- put from 8 of SSID into MAC
954
- gosub to SendFileToDevice
955
- gosub to RequestReset
956
988
end
957
989
return
958
990
@@ -987,7 +1019,9 @@ CreateDevice:
987
1019
set property `dht22` of Pins to Pin
988
1020
set property `pins` of Device to Pins
989
1021
set property Name of Devices to Device
990
- set property `devices` of Config to Devices
1022
+ set property `devices` of SystemConfig to Devices
1023
+ set property Name of Systems to SystemConfig
1024
+ set property `systems` of Config to Systems
991
1025
return
992
1026
993
1027
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
@@ -1011,12 +1045,22 @@ ConnectToDevice:
1011
1045
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1012
1046
! Populate the device information fields
1013
1047
PopulateDeviceInfo:
1014
- log `Populate device ` cat property `name` of Device
1015
- set the text of DeviceNameInput to property `name` of Device
1016
- enable UpdateDeviceButton
1017
- enable DeleteFileButton
1048
+ if Device has property `name`
1049
+ begin
1050
+ log `Populate device ` cat property `name` of Device
1051
+ set the text of DeviceNameInput to property `name` of Device
1052
+ set the text of SSIDLabel to property `ssid` of Device
1053
+ enable UpdateDeviceButton
1054
+ enable DeleteFileButton
1055
+ end
1018
1056
return
1019
1057
1058
+ !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1059
+ ! Send the config file to a device
1060
+ SendConfigFile:
1061
+ put `config.json` into FileName
1062
+ put stringify Device into Content
1063
+
1020
1064
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1021
1065
! Send a file to a device
1022
1066
SendFileToDevice:
@@ -1128,7 +1172,7 @@ SendRBRMessage:
1128
1172
SendMessageToDevice:
1129
1173
gosub to GetDeviceData
1130
1174
put left 30 of Message into Message2
1131
- ! log `Send '` cat Message2 cat `' to ` cat Name
1175
+ log `Send '` cat Message2 cat `' to ` cat Name
1132
1176
put Message into Message2
1133
1177
if Path is not empty
1134
1178
begin
@@ -1147,6 +1191,7 @@ SendMessageToDevice:
1147
1191
end
1148
1192
end
1149
1193
put `http://` cat MasterIPAddr cat `/?mac=` cat MAC cat `&msg=` cat Message2 into URL
1194
+ log URL
1150
1195
get Response from url URL
1151
1196
or begin
1152
1197
put `Could not message ` cat Name into StatusMessage
0 commit comments