-
Notifications
You must be signed in to change notification settings - Fork 12
/
PHY62x2BTHome.html
2556 lines (2357 loc) · 217 KB
/
PHY62x2BTHome.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<html class="phy6222Class"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>PHY62x2 BTHome v1.6</title>
<!--<link rel="stylesheet" type="text/css" href="styles.css" />
<link rel="stylesheet" type="text/css" href="chart.css" />
<script type="text/javascript" src="dygraph.min.js" /></script> /-->
<!--link rel="stylesheet" type="text/css" href="https://dygraphs.com/dist/dygraph.min.css /-->
<!--script type="text/javascript" src="https://dygraphs.com/dist/dygraph.min.js" /></script-->
<style type="text/css">
/* basic sytles */
body {
font-family: Arial, 'Open Sans', sans-serif;
color: #204056;
}
h1 {
font-size: 28px;
font-weight: 400;
text-align: center;
margin-top: 12px;
margin-bottom: 18px;
}
hr {
height: 10px;
border: 0;
box-shadow: 0 10px 10px -10px #8c8b8b inset;
}
span#info {
font-style: italic;
}
.button, [type='button'] {
background-color: #1a73e8;
border: none;
border-radius: 4px;
color: white;
padding: 8px 24px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 14px;
margin: 6px 6px;
cursor: pointer;
box-shadow: 0 3px 1px -2px #0003, 0 2px 2px #00000024, 0 1px 5px #0000001f;
}
.button, [type='button'].ok {
background-color: #4CAF50; /* Green */
color: white;
border-color: #4CAF50;
}
.button, [type='button'].danger {
background-color: #f44336; /* Red */
color: white;
border-color: #f44336;
}
.button, [type='button']:disabled {
cursor: not-allowed;
opacity: 0.6;
}
input[type="checkbox"] + label {
margin-right: 8px;
}
div#div_v {
height:400px;
margin-top: 16px;
margin-bottom: 16px;
}
div#labdiv {
margin-top: 16px;
margin-bottom: 16px;
}
div#log {
padding: 12px;
font-style: italic;
font-size: 16px;
}
div#MAC {
font-style: smaller;
margin: 8px;
}
div#txtStatus {
font-style: italic;
font-size: 16px;
text-align: center;
background-color: #eef6fc;
padding-top: 5px;
padding-bottom: 5px;
margin-top: 8px;
}
div#tempHumiData{
text-align: center;
background-color: #eef6fc;
padding-top: 5px;
padding-bottom: 5px;
}
input {
padding: 4px;
margin: 4px;
}
select {
padding: 4px;
}
/* menu */
.navbar {
width: 95%;
/* box-shadow: 0 1px 4px rgb(146 161 176 / 15%);*/
position: absolute;
top: 0;
}
.nav-container {
display: flex;
justify-content: space-between;
align-items: center;
height: 62px;
}
.navbar .menu-items {
display: flex;
}
.navbar .nav-container li {
list-style: none;
}
.navbar .nav-container a {
font-size: 1.0rem;
font-weight: 400;
}
.navbar .nav-container a:hover{
font-weight: bolder;
}
.nav-container {
display: block;
position: relative;
height: 60px;
}
.nav-container .checkbox {
position: absolute;
display: block;
height: 32px;
width: 32px;
top: 20px;
left: 20px;
z-index: 5;
opacity: 0;
cursor: pointer;
}
.nav-container .hamburger-lines {
display: block;
height: 26px;
width: 32px;
position: absolute;
top: 17px;
left: 20px;
z-index: 2;
display: flex;
flex-direction: column;
justify-content: space-between;
}
.nav-container .hamburger-lines .line {
display: block;
height: 4px;
width: 100%;
border-radius: 10px;
background: #0e2431;
}
.nav-container .hamburger-lines .line1 {
transform-origin: 0% 0%;
transition: transform 0.4s ease-in-out;
}
.nav-container .hamburger-lines .line2 {
transition: transform 0.2s ease-in-out;
}
.nav-container .hamburger-lines .line3 {
transform-origin: 0% 100%;
transition: transform 0.4s ease-in-out;
}
.navbar .menu-items {
position: relative;
padding-top: 55px;
box-shadow: 5px 3px 13px 0px rgb(204 204 204 / 80%);
min-height: 100vh;
width: 60%;
transform: translate(-150%);
display: flex;
flex-direction: column;
transition: transform 0.5s ease-in-out;
text-align: center;
z-index: 1;
background: white;
}
.navbar .menu-items li {
margin-bottom: 12px;
font-size: 1.2rem;
font-weight: 800;
}
.nav-container input[type="checkbox"]:checked ~ .menu-items {
transform: translateX(0);
}
.nav-container input[type="checkbox"]:checked ~ .hamburger-lines .line1 {
transform: rotate(45deg);
}
.nav-container input[type="checkbox"]:checked ~ .hamburger-lines .line2 {
transform: scaleY(0);
}
.nav-container input[type="checkbox"]:checked ~ .hamburger-lines .line3 {
transform: rotate(-45deg);
}
.nav-container input[type="checkbox"]:checked ~ .logo{
display: none;
}
.shadowbox {
width: 15em;
border: 1px solid #333;
box-shadow: 8px 8px 5px #444;
padding: 8px 12px;
background-image: linear-gradient(180deg, #fff, #ddd 40%, #ccc);
}
.shadowprogress {
width: 15em;
border: 1px solid #333;
/* box-shadow: 8px 8px 5px #444; */
padding: 8px 12px;
/* background-image: linear-gradient(180deg, #fff, #ddd 40%, #ccc); */
}
.shadowerror {
color: red;
width: 15em;
border: 1px solid #333;
box-shadow: 8px 8px 5px #444;
padding: 8px 12px;
background-image: linear-gradient(180deg, #fff, #ddd 40%, #ccc);
}
/* Style the tab */
.tab {
overflow: hidden;
border: 1px solid #ccc;
background-color: #f1f1f1;
}
/* Style the buttons inside the tab */
.tab button {
background-color: inherit;
float: left;
border: none;
border-radius: 4px;
outline: none;
cursor: pointer;
padding: 10px 20px;
transition: 0.3s;
font-size: 14px;
}
/* Change background color of buttons on hover */
.tab button:hover {
/* background-color: #ddd; */
background-color: #1a73e8;
}
/* Create an active/current tablink class */
.tab button.active {
/* background-color: #ccc; */
background-color: #4aa3ff;
}
/* Style the tab content */
.tabcontent {
display: none;
padding: 6px 12px;
border: 1px solid #ccc;
border-top: none;
}
/* Create equal columns that floats next to each other */
.column {
float: left;
padding: 5px;
}
/* Clear floats after the columns */
.row:after {
content: "";
display: table;
clear: both;
}
/**
* Default styles for the dygraphs charting library.
*/
.dygraph-legend {
position: relative;
font-size: 12px;
z-index: 10;
width: 250px; /* divLabelsWidth */
/*
dygraphs determines these based on the presence of chart labels.
It might make more sense to create a wrapper div around the chart proper.
top: 0px;
right: 2px;
*/
background: white;
line-height: normal;
text-align: center;
overflow: hidden;
}
/* styles for a solid line in the legend */
.dygraph-legend-line {
display: inline-block;
position: relative;
bottom: .5ex;
padding-left: 1em;
height: 1px;
border-bottom-width: 2px;
border-bottom-style: solid;
/* border-bottom-color is set based on the series color */
}
/* styles for a dashed line in the legend, e.g. when strokePattern is set */
.dygraph-legend-dash {
display: inline-block;
position: relative;
bottom: .5ex;
height: 1px;
border-bottom-width: 2px;
border-bottom-style: solid;
/* border-bottom-color is set based on the series color */
/* margin-right is set based on the stroke pattern */
/* padding-left is set based on the stroke pattern */
}
.dygraph-roller {
position: absolute;
z-index: 10;
}
/* This class is shared by all annotations, including those with icons */
.dygraph-annotation {
position: absolute;
z-index: 10;
overflow: hidden;
}
/* This class only applies to annotations without icons */
/* Old class name: .dygraphDefaultAnnotation */
.dygraph-default-annotation {
border: 1px solid black;
background-color: white;
text-align: center;
}
.dygraph-axis-label {
/* position: absolute; */
/* font-size: 14px; */
z-index: 10;
line-height: normal;
overflow: hidden;
color: black; /* replaces old axisLabelColor option */
}
.dygraph-axis-label-x {
}
.dygraph-axis-label-y {
color: green;
}
.dygraph-axis-label-y2 {
color: blue;
}
.dygraph-title {
font-weight: bold;
z-index: 10;
text-align: center;
/* font-size: based on titleHeight option */
}
.dygraph-xlabel {
text-align: center;
/* font-size: based on xLabelHeight option */
}
/* For y-axis label */
.dygraph-label-rotate-left {
text-align: center;
/* See http://caniuse.com/#feat=transforms2d */
transform: rotate(90deg);
-webkit-transform: rotate(90deg);
-moz-transform: rotate(90deg);
-o-transform: rotate(90deg);
-ms-transform: rotate(90deg);
}
/* For y2-axis label */
.dygraph-label-rotate-right {
text-align: center;
/* See http://caniuse.com/#feat=transforms2d */
transform: rotate(-90deg);
-webkit-transform: rotate(-90deg);
-moz-transform: rotate(-90deg);
-o-transform: rotate(-90deg);
-ms-transform: rotate(-90deg);
}
div#divChart {
height: 100%;
width: 100%;
margin-top: 16px;
margin-bottom: 16px;
}
</style>
</head>
<body>
<script>
const i18n = (() => {
const lang = getUserLang();
const tags = {
PREFIX: { en: 'Prefix named after devices(а)' },
CONNECT: { en: 'Connect' },
DISCONNECT: { en: 'Disconnect', ru: 'Отключение' },
RECONNECT: { en: 'Reconnect', ru: 'Переподключение' },
TIME: { en: 'Time' },
TEMPERATURE: { en: 'Temperature', ru: 'Температура' },
HUMIDITY: { en: 'Humidity', ru: 'Влажность' },
BATTERYSTATE: { en: 'Battery level' },
SHOW_TIME: { en: 'Show time' },
SHOW_SMILEY: { en: 'Show smiley' },
SHOW_TRIGGER: { en: 'Show trigger' },
DISCONNECT_DISPLAY: { en: 'Disconnect display' },
ENCRYPTED_AD: { en: 'Encrypted advertising' },
MS: { en: 'ms' },
AD_INTERVAL: { en: 'Advertizing interval' },
MEASUREMENT_STEP: { en: 'Measurement step' },
BAT_INTERVAL: { en: 'Battery survey interval' },
HISTORY_INTERVAL: { en: 'History interval' },
READ: { en: 'Read' },
WRITE: { en: 'Write' },
RESTORE: { en: 'Restore' },
GET_DEVICETIME: { en: 'Get device time' },
SET_DEVICETIME: { en: 'Set device time', ru: 'Авто установка часов устройства' },
COMFORT: { en: 'Comfort' },
TRIGGER: { en: 'Trigger' },
HYSTERESIS: { en: 'Hysteresis' },
OUTPUT_INVERTED: { en: 'Inverted output' },
SENSOR_PARAMS: { en: 'Sensor parameters' },
CORRECTION_COEFF: { en: 'Correction coefficients' },
CORRECTION_DISPLAY: { en: 'Display correction' },
FILE: { en: 'File', ru: 'Файл' },
NO_FILE: { en: '(no file)', ru: 'не загружен' },
SELECT_UPLOAD: { en: 'Select OTA file' },
START: { en: 'Start', ru: 'Старт' },
START_OTA: { en: 'Start OTA flashing', ru: 'Старт программирования' },
SHOW_HISTORY: { en: 'Show stored history' },
MEM_RW: { en: 'Read / write memory' },
ADDRESS: { en: 'Address', ru: 'адрес' },
DATA: { en: 'Data' },
COMMAND: { en: 'Command' },
SEND: { en: 'Send' },
DEVICENAME: { en: 'Device name' },
CLEAN_LOG: { en: 'Purge log file' },
BASIC_INST: { en: 'Basic configuration' },
FROMTO_FROM: { en: 'from', ru: 'из' },
FROMTO_TO: { en: 'to' },
CONNECTION_FAILED: { en: 'Connection failed', ru: 'Подключиться не удалось' },
SEARCH_DEVICES: { en: 'Searching for devices', ru: 'Поиск устройств' },
FOUND: { en: 'Found', ru: 'Найден' },
UNKNOWN_RESPONSE: { en: 'Unknown resonse from device', ru: 'Странный ответ устройства' },
CONNECTED: { en: 'Connected', ru: 'Устройство подключено' },
NOT_CONNECTED: { en: 'Not connected', ru: 'Не подключено' },
MODE: { en: 'Mode', ru: 'Режим' },
SWITCH_TO: { en: 'Switch to', ru: 'Переключение на' },
WAIT_CON_TO: { en: 'Waiting for connection to', ru: 'Ожидание соединения с' },
SERVER: { en: 'server', ru: 'сервер' },
WRONG_DEVICE: { en: 'Wrong device selected', ru: 'Выбрано неверное устройтво' },
DEVICE_DISABLED: { en: 'Device is disconnected', ru: 'Устройство отключено' },
STATE: { en: 'State', ru: 'Состояние' },
ERROR: { en: 'Error', ru: 'Ошибка' },
IMPROPER_FIRMWARE_SIZE: { en: 'Improper size of binary firmware', ru: 'Неправильный размер двоичной прошивки' },
FIRMWARE_TOO_BIG: { en: 'Firmware is bigger than %s', ru: 'Размер прошивки более %s кбайт' },
IMPROPER_FIRMWARE: { en: 'Inappropriate format of the firmware file size', ru: 'Неверный формат размера файла для прошивки' },
SPECIAL_FIRMWARE: { en: 'Special firmware', ru: 'специальная прошивка' },
SEGMENTS: { en: 'Segments', ru: 'Сегментов' },
SIZE: { en: 'Size', ru: 'Размер' },
WRONG_NUMOF_SEGMENTS: { en: 'Wrong number of segments', ru: 'Неверное количество сегментов в заголовке' },
WRONG_HEADER_SIZE: { en: 'Wrong header size', ru: 'Неверный размер в заголовке' },
FILE_CRC_ERROR: { en: 'CRC error in file', ru: '' },
CALCULATED: { en: 'calculated', ru: 'Расчет' },
NOT_UPLOADED: { en: 'not uploaded', ru: 'не загружен' },
FILESIZE: { en: 'Filesize', ru: 'Размер файла' },
BYTES: { en: 'bytes', ru: 'байт' },
COUNTER: { en: 'Counter', ru: 'Счетчик' },
BLOCKS: { en: 'blocks', ru: 'блоков' },
WRONG_COMMAND: { en: 'Wrong command', ru: 'Неверная команда' },
START_NOT_SET: { en: 'Start not set', ru: 'Не задан старт' },
PARAMS_NOT_SET: { en: 'Parameters not set', ru: 'Не заданы параметры' },
WRONG_PARAMS: { en: 'Wrong parameters', ru: 'Неверные параметры' },
WRONG_PACKET_SIZE: { en: 'Wrong packet size', ru: 'Неправильный размер пакета' },
PACKAGE_CRC_ERROR: { en: 'Package CRC Error', ru: 'Ошибка CRC16 пакета' },
PACKAGE_LOSS: { en: 'Package loss', ru: 'Потеря пакетов' },
FLASH_WRITE_ERROR: { en: 'Flash write error', ru: 'Ошибка записи в Flash' },
PACKAGE_SIZE_ERROR: { en: 'Package size error', ru: 'Ошибка в номере пакета' },
IDENTIFIER_ERROR: { en: 'identifier error in program file', ru: 'Ошибка идентификатора в файле программы' },
PROGRAM_CRC_ERROR: { en: 'CRC Error in program file', ru: 'Ошибка CRC32 переданной программы' },
UNKNOWN_ERROR: { en: 'Enknown error', ru: 'Неизвестная ошибка' },
NO_FILE_ERROR: { en: 'Error: No file selected', ru: '"Не выбран файл' },
FLASH_FINISHED: { en: 'Flash finished in %s seconds', ru: 'Программирование завершено за %s секунды' },
RELOAD_COMMAND_FAILED: { en: 'Reload command failed', ru: 'Ошибка передачи команды перезагрузки после ' },
ON_BLOCK: { en: 'during block transmission', ru: 'на передаче блока' },
SUCCEEDED: { en: 'succeeded', ru: 'успеха' },
SECONDS: { en: 'seconds', ru: 'сек' },
MINUTES: { en: 'minutes', ru: 'минут' },
TOTAL_TIME: { en: 'total time', ru: 'время от старта' },
BLOCK_TRANSFERRED: { en: 'Block transferred', ru: 'Передан блок' },
ERROR_SENDING_DATA: { en: 'Error sending data', ru: 'Ошибка при отправке данных' },
READING_BYTES: { en: 'Reading %s bytes at', ru: 'Чтение %s байт по адресу' },
WRITING_BYTES: { en: 'Writing %s bytes at', ru: 'Запись %s байт по адресу' },
BLOCK_LENGTH_RANGE: { en: 'Block length must be 1 to 16 bytes', ru: 'длина блока от 1 до 16 байт' },
COMMAND_LENGTH_RANGE: { en: 'Command length must be 1 to 20 bytes', ru: 'длина команды от 1 до 20 байт' },
BATTERY: { en: 'Battery', ru: 'Батарея' },
MILLIVOLT: { en: 'mV', ru: 'мВ' },
MEMO_EMPTY: { en: 'Memo is empty', ru: 'Пока нет истории' },
NO_MEMO_SERVICE: { en: 'No memo service', ru: 'Нет сервиса записи истории' },
FLAGS: { en: 'flags', ru: 'флаги' },
TIME_ON_DEVICE: { en: 'Time on device', ru: 'Время на устройстве' },
DIFFERENCE: { en: 'Difference', ru: 'Уход' },
CONFIG_DATA: { en: 'Configuration data', ru: 'Строка конфигурации' },
DATA_AT_ADDRESS: { en: 'Data at address', ru: 'Данные по адресу' },
REGISTER_AT_ADDRESS: { en: 'Register at address', ru: 'Регистр по адресу' },
SERIALNUM: { en: 'Serial number', ru: 'Серийный номер' },
READ_ERROR: { en: 'Read error', ru: 'Ошибка чтения' },
NOT_SUPPORTED: { en: 'Not supported', ru: 'Не поддерживается' },
LAST_TIME_SETTING: { en: 'Last time setting', ru: 'Последняя установка времени' },
PASSED_ON_DEVICE: { en: 'Passed on device', ru: 'Прошло на устройстве' },
MIN_TIME_CALC: { en: 'Minimum time period is 3 hours', ru: 'Минимальный перод для расчета ухода часов 3 часа' },
CLOCK_ADVANCE_ERR: { en: 'The clock must be set in advance', ru: 'Часы необходимо настроить заранее' },
UPDATE: { en: 'Update', ru: 'Обновление' },
TRIGGER_DATA: { en: 'Trigger settings line', ru: 'Строка настроек триггера' },
COMFORT_TEMPERATURE: { en: 'Comfort temperature', ru: 'Комфорт Температура' },
DEVICE: { en: 'Device', ru: 'Устройство' },
COMMAND_RESPONSE: { en: 'Command response', ru: 'Ответ на команду' },
SET_DEVICE_TIME: { en: 'Set device time', ru: 'Установка времени на устройстве' },
TIME_IS_SYNCED: { en: 'Device time is synchronized', ru: 'Время на устройстве синхронизировано' },
SENDING_NEW_MAC: { en: 'Sending new MAC address', ru: 'Передача нового MAC' },
INVALID_MAC_LENGTH: { en: 'MAX length must be 6 bytes (hex)', ru: 'Строка MAC должна быть 6 байт в HEX виде' },
DEPRECATED_FIRMWARE: { en: 'Firware versions below 1.1 are not supported', ru: 'Версия прошивки с номером менее 1.1 не поддерживается' },
CORRECT_DEVICENAME_LENGTH: { en: 'Devicename length is OK', ru: 'Имя устройства должно быть от 1 до 19 символов, включая кодирование UTF-8' },
INVALID_DEVICENAME_LENGTH: { en: 'Devicename length must be 1 to 19 bytes (UTF-8 characters consume 2 bytes)', ru: 'Имя устройства должно быть от 1 до 19 символов, включая кодирование UTF-8' },
INVALID_BINDKEY_LENGTH: { en: 'Bindkey must be 16 bytes, hex encoded (=32 characters)', ru: 'BindKey должен соднержать 16 байт в HEX виде (32 символа)' },
UPLOAD_FIRMWARE: { en: 'Download firmware file', ru: 'Загрузка firmware файла' },
WARNING_BOOT_FW: { en: 'Attention!: Uploading boot FW is not safe. In order to avoid firmware failure use a fresh battery!', ru: 'Внимание!: Обновление Boot fw не безопасно. Во избежание сбоя прошивки желательно использование полной батареи!' },
MEMO_OFF: {en: 'Disabled', ru: 'Отключено'},
SHOW_TEMPF: {en: 'Show Temperature in Fahrenheit', ru: 'Показывать температуру в градусах Фаренгейта'},
};
function getUserLang() {
const userLang = window.navigator.language.toLowerCase();
if (userLang === 'ru') {
return 'ru';
}
return 'en';
}
function getTag(tagName) {
const entry = tags[tagName];
if(!entry) {
console.error(`Unknown i18n tag "${tagName}"`);
}
return entry && entry[lang] ? entry[lang] : '';
}
function updatePage() {
for (const element of document.querySelectorAll('[data-i18ntag]')) {
const newText = getTag(element.getAttribute('data-i18ntag'));
if (newText) {
element.innerHTML = newText;
}
}
}
return {
getTag,
updatePage
};
})();
//BLE values
const FLASH_SIZE = 0x80000;
const OTA_MAX_SIZE = 0x30000; // 196608
const SERVICE_OTA = 0x00000001; // funtion OTA
const SERVICE_OTA_EXT = 0x00000002; // expanded function OTA
const SERVICE_PINCODE = 0x00000004; // installation pin-code
const SERVICE_BINDKEY = 0x00000008; // encryption
const SERVICE_HISTORY = 0x00000010; // Record of history
const SERVICE_SCREEN = 0x00000020; // screen
const SERVICE_LE_LR = 0x00000040; // Advertising support in LE Long Range
const SERVICE_THS = 0x00000080; // temperature and humidity sensor
const SERVICE_RDS = 0x00000100; // Serving Hocon/Impulse accounts
const SERVICE_KEY = 0x00000200; // button
const SERVICE_OUTS = 0x00000400; // The service of the output for Pins
const SERVICE_INS = 0x00000800; // Maintenance of input pins
const SERVICE_TIME_ADJUST = 0x00001000; // Time account correction function
const SERVICE_HARD_CLOC = 0x00002000; // Real hours RTC
const SERVICE_TH_TRG = 0x00004000; // temperature and humidity
var bluetoothDevice, gattServer, otaCharacteristic, cmdCharacteristic, infoService;
var hwver_id = null;
var otafiles = { loaded: false };
var devInfo = {};
var devSrv = { services: 0 };
var devCfg = {};
var devSens = {};
var devTrig = {};
var devTime = {};
var devKeys = {};
var devName = "";
var isConnected = false;
var isChartEnabled = true;
var isMemoActive = false;
var startTime = 0;
var memoCount = 0;
var ota = {
fwArray: null,
fwname: "",
fwsize: 0,
// fwmaxsize: 196608,
ext_flg: false,
blockCount: 0,
program_offset: 0x11010000
};
var flashBuffer = null;
//Connection values
var connectRetries = 0;
var $ = function(id) { return document.getElementById(id);}
const isEmpty = str => !str.trim().length;
function resetVariables() {
gattServer = null;
hwver_id = null;
mainService = null;
otaCharacteristic = null;
cmdCharacteristic = null;
$('btnDisconnect').disabled = true;
$('btnStartDFU').disabled = true;
}
function handleError(text) {
showError(text);
resetVariables();
if ((bluetoothDevice != null) && (connectRetries < 5)) {
addLog(`${i18n.getTag('RECONNECT')} ${connectRetries} / 5`)
$('btnDisconnect').disabled = true;
$('btnReconnect').disabled = true;
connectRetries++;
doConnect();
} else {
addLog(`${i18n.getTag('CONNECTION_FAILED')}!`);
connectRetries = 0;
$('btnConnect').disabled = false;
}
}
function connect() {
var deviceOptions = {
optionalServices: [0x1800, 0x180a, 0x180f, 0x181a, 0xfcd2],
services: [0x1800, 0x180a, 0x180f, 0x181a, 0xfcd2],
acceptAllDevices: true };
const namePrefix = $('inpNamePrefix').value;
if (namePrefix) {
deviceOptions.acceptAllDevices = false;
deviceOptions.filters = namePrefix.split(",")
.map((x) => ({ namePrefix: x }));
}
console.log(deviceOptions);
if (bluetoothDevice != null) bluetoothDevice.gatt.disconnect();
chartData.length = 0;
resetVariables();
bluetoothDevice = null;
$('btnReconnect').disabled = true;
$('tabConfig').style.display = "none";
if(typeof(navigator.bluetooth) != "undefined") {
$('btnConnect').disabled = true;
showState(i18n.getTag('SEARCH_DEVICES'));
connectRetries = 0;
//console.log()
navigator.bluetooth.requestDevice(deviceOptions).then(device => {
bluetoothDevice = device;
bluetoothDevice.addEventListener('gattserverdisconnected', onDisconnected);
//addLog("Connecting to: " + bluetoothDevice.name);
doConnect();
}).catch(handleError);
} else {
showError("Browser doesn't support BLE API");
}
}
function disconnect() {
addLog(i18n.getTag('DISCONNECT'));
isConnected = false;
if (bluetoothDevice != null)
bluetoothDevice.gatt.disconnect();
}
function reconnect() {
addLog(i18n.getTag('RECONNECT'));
if (bluetoothDevice != null) {
bluetoothDevice.gatt.disconnect();
isConnected = false;
}
$('btnConnect').disabled = true;
$('btnReconnect').disabled = true;
connectRetries = 0;
doConnect();
}
function getStrCharacteristic(infosrv, suuid) {
return new Promise((resolve, reject) => {
infosrv.getCharacteristic(suuid).then(characteristic => {
characteristic.readValue().then(value => {
return resolve(new TextDecoder("utf-8").decode(value));
}).catch(error => {console.log(error); return resolve(null); });
}).catch(error => {console.log(error); return resolve(null); });
})};
function getDevInfo(devInfEnabled) {
return new Promise((resolve, reject) => {
devInfo.nrstr = null;
devInfo.srstr = null;
devInfo.frstr = null;
devInfo.hrstr = null;
devInfo.vrstr = null;
if (devInfEnabled == true) {
gattServer.getPrimaryService(0x180a).then(service => {
console.log(`${i18n.getTag('FOUND')} Device Information Service`);
infoService = service;
return getStrCharacteristic(infoService, 0x2a24).then(value => {
devInfo.nrstr = value;
//DOMException: getCharacteristic(s) called with blocklisted UUID. https://goo.gl/4NeimX
//return getStrCharacteristic(infoService, 0x2a25).then(value => {
// devInfo.srstr = value;
return getStrCharacteristic(infoService, 0x2a26).then(value => {
devInfo.frstr = value;
return getStrCharacteristic(infoService, 0x2a27).then(value => {
devInfo.hrstr = value;
return getStrCharacteristic(infoService, 0x2a28).then(value => {
devInfo.vrstr = value;
return resolve(devInfo.flg);
}).catch(error => { console.log(error); return resolve(null);});
}).catch(error => { console.log(error); return resolve(null);});
}).catch(error => { console.log(error); return resolve(null);});
//}).catch(error => { console.log(error); return resolve(null);});
}).catch(error => { console.log(error); return resolve(null);});
}).catch(error => { console.log(error); return resolve(null);});
} else return resolve(null);
}).catch(error => { console.log(error); return resolve(null);});
}
function linkOta() {
return new Promise((resolve, reject) => {
mainService.getCharacteristic(0xfff3).catch(error => { console.log(error); return resolve(null);})
.then(characteristic => {
console.log(`${i18n.getTag('FOUND')} OTA Characteristic`);
otaCharacteristic = characteristic;
return otaCharacteristic.addEventListener('characteristicvaluechanged', event => parseBlkOTA(event.target.value));
}).then(_ => {
return otaCharacteristic.readValue();
}).then(value => {
if(value.byteLength > 1) {
addLog("OTA ver: "+ hex(value.getUint8(1),2));
$("btnStartDFU").value = i18n.getTag('START_OTA');
}
return resolve(null);});
}).catch(error => { console.log(error); return resolve(null);});
}
function phyConnect(info_flg) {
return getDevInfo(info_flg).then(_ => {
if(devInfo.nrstr != null)
addLog("Model: "+devInfo.nrstr);
if(devInfo.srstr != null)
addLog("Serial: "+devInfo.srstr);
if(devInfo.frstr != null)
addLog("Firmware: "+devInfo.frstr);
if(devInfo.hrstr != null)
addLog("Hardware: "+devInfo.hrstr);
if(devInfo.vrstr != null)
addLog("Software: "+devInfo.vrstr);
return gattServer.getPrimaryService(0xfcd2);
}).then(service => {
console.log(`${i18n.getTag('FOUND')} Main Service`);
mainService = service;
cmdCharacteristic = null;
return mainService.getCharacteristic(0xfff4);
}).then(characteristic => {
console.log(`${i18n.getTag('FOUND')} CMD Characteristic`);
cmdCharacteristic = characteristic;
return cmdCharacteristic.addEventListener('characteristicvaluechanged', event => parseBlkCustom(event.target.value));
}).then(_ => {
return cmdCharacteristic.startNotifications();
}).then(_ => {
return cmdCharacteristic.readValue();
}).then(value => {
if(value.byteLength >= 10)
if(value.getUint8(0) != 0)
addLog(`${i18n.getTag('UNKNOWN_RESPONSE')}!`);
else if((value.getUint32(8, true) & 1) != 0) // SERVICE_OTA ?
return linkOta();
otaCharacteristic = null;
}).then(_ => {
showState(`${i18n.getTag('CONNECTED')}.`);
isConnected = true;
// $('btnConnect').disabled = true;
$('btnDisconnect').disabled = false;
// $('btnReconnect').disabled = false;
disableControls(false);
// selectConfigTab();
// $('tabConfig').style.display = "block";
let el = $('btnStartDFU');
if (otaCharacteristic != null) {
el.disabled = ota.fwArray == null;
el.innerHTML = i18n.getTag('START');
el.title = i18n.getTag('START_OTA');
} else {
el.innerHTML = `${i18n.getTag('MODE')} OTA`;
el.title = `${i18n.getTag('SWITCH_TO')} BootLoader ...`
}
return cmdCharacteristic.writeValue(new Uint8Array([0x33])); // get measure
}).catch(handleError);
}
function doConnect() {
isConnected = false;
showState(`${i18n.getTag('WAIT_CON_TO')} ${bluetoothDevice.name}`)
return bluetoothDevice.gatt.connect().then(server => {
console.log(`${i18n.getTag('FOUND')} GATT ${i18n.getTag('SERVER')}`);
gattServer = server;
gattServer.getPrimaryServices().then(services => {
let phy = false;
let info = false;
for (var i = 0; i < services.length; i++) {
console.log("Services: " + services[i].uuid);
if (services[i].uuid == "0000180a-0000-1000-8000-00805f9b34fb")
info = true;
else if (services[i].uuid == "0000fcd2-0000-1000-8000-00805f9b34fb")
phy = true;
}
if(phy)
return phyConnect(true);
addLog(`${i18n.getTag('WRONG_DEVICE')}!`);
bluetoothDevice.gatt.disconnect();
connectRetries = 10;
return null;
}).catch(handleError);
}).catch(handleError);
}
function auxControls(state)
{
if ( devSrv.services & SERVICE_SCREEN ) {
$('tblChkCfg').style.display = "block";
$('tblComfort').style.display = "block";
} else {
$('tblChkCfg').style.display = "none";
$('tblComfort').style.display = "none";
}
if ( devSrv.services & SERVICE_BINDKEY ) {
$('labBindKey').style.display = "block";
$('divBindKey').style.display = "block";
} else {
$('labBindKey').style.display = "none";
$('divBindKey').style.display = "none";
}
if ( devSrv.services & SERVICE_TH_TRG )
$('tblTrigger').style.display = "block";
else
$('tblTrigger').style.display = "none";
if (devSrv.services & (SERVICE_SCREEN | SERVICE_TH_TRG)) {
$('tblTriggerKeys').style.display = "block";
$('hrPres').style.display = "block";
} else {
$('tblTriggerKeys').style.display = "none";
$('hrPres').style.display = "none";
}
}
function disableControls(state)
{
//--debug devSrv.services = SERVICE_SCREEN|SERVICE_TH_TRG;
auxControls(state);
if(state) { // hide
$('hrSensorData').style.display = "none";
$('tblSensorData').style.display = "none";
} else { // show
$('hrSensorData').style.display = "block";
$('tblSensorData').style.display = "block";
}
$('btnGetDev').disabled = state;
$('btnSetDev').disabled = state;
$('btnRstDev').disabled = state;
$('btnGetSens').disabled = state;
$('btnSetSens').disabled = state;
$('btnRstSens').disabled = state;
$('btnGetDevTime').disabled = state;
$('btnSetDevTime').disabled = state;
$('btnReadAddr').disabled = state;
$('btnWriteAddr').disabled = state;
$('btnSendCommand').disabled = state;
$('btnGetMAC').disabled = state;
$('btnSetMAC').disabled = state;
$('btnGetName').disabled = state;
$('btnSetName').disabled = state;
$('btnRstName').disabled = state;
}
function onDisconnected() {
isConnected = false;
resetVariables();
showState(`${i18n.getTag('DEVICE_DISABLED')}.`);
$('btnConnect').disabled = false;
$('btnReconnect').disabled = false;
// $('tabConfig').style.display = "none";
disableControls(true);
}
function startDFU() {
if(otaCharacteristic != null && ota.ind.version == 1 && (devSrv.services & SERVICE_OTA) == SERVICE_OTA) {
addLog(`${i18n.getTag('START_OTA')}...`);
updateBegin();
} else {
addLog(`${i18n.getTag('SWITCH_TO')}...`);
if(cmdCharacteristic != null) {
cmdCharacteristic.writeValue(new Uint8Array([0x72,0x55])).then(_ => {
console.log('Reboot command sent to bootloader');
reconnect();
}).catch(error => { addLog(error); });
}
}
}
function addLog(logTXT) {