forked from BlazejosP/huawei-sun2000-API-CLI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.sh
13771 lines (11994 loc) · 542 KB
/
functions.sh
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
#!/bin/bash
#inside this file are all fuctions necessary to connect to Huawei FusionSolarApp API
timezones_adjust_for_huawei_api_question () {
# time of startup/shutdown of inverter is keept inside API in shorter unix format without milisecounds so don't need cuting of last three digits like in other places and regardles to your settings is keep in GMT format so here need timezone adjustment. 7200 secounds is +2 hours which is needed to substract for example for CEST from GMT
local Timezone=$(date +"%z" -d @$(echo $1))
#echo $Timezone
if [ $Timezone == "-1200" ];
then
declare timezone_offset=43200 # UTC-12:00 in secounds 12 hours difference
correct_date=$(echo $(($2+$timezone_offset)))
elif [ $Timezone == "-1100" ];
then
declare timezone_offset=39600 # UTC-11:00 in secounds 11 hours difference
correct_date=$(echo $(($2+$timezone_offset)))
elif [ $Timezone == "-1000" ];
then
declare timezone_offset=72000 # UTC-10:00 in secounds 10 hours difference
correct_date=$(echo $(($2+$timezone_offset)))
elif [ $Timezone == "-0930" ];
then
declare timezone_offset=34200 # UTC-09:30 in secounds 9.5 hours difference
correct_date=$(echo $(($2+$timezone_offset)))
elif [ $Timezone == "-0900" ];
then
declare timezone_offset=32400 # UTC-09:00 in secounds 9 hours difference
correct_date=$(echo $(($2+$timezone_offset)))
elif [ $Timezone == "-0800" ];
then
declare timezone_offset=28800 # UTC-08:00 in secounds 8 hours difference
correct_date=$(echo $(($2+$timezone_offset)))
elif [ $Timezone == "-0700" ];
then
declare timezone_offset=25200 # UTC-07:00 in secounds 7 hours difference
correct_date=$(echo $(($2+$timezone_offset)))
elif [ $Timezone == "-0600" ];
then
declare timezone_offset=21600 # UTC-06:00 in secounds 6 hours difference
correct_date=$(echo $(($2+$timezone_offset)))
elif [ $Timezone == "-0500" ];
then
declare timezone_offset=18000 # UTC-05:00 in secounds 5 hours difference
correct_date=$(echo $(($2+$timezone_offset)))
elif [ $Timezone == "-0400" ];
then
declare timezone_offset=14400 # UTC-04:00 in secounds 4 hours difference
correct_date=$(echo $(($2+$timezone_offset)))
elif [ $Timezone == "-0330" ];
then
declare timezone_offset=12600 # UTC-03:30 in secounds 3.5 hours difference
correct_date=$(echo $(($2+$timezone_offset)))
elif [ $Timezone == "-0300" ];
then
declare timezone_offset=10800 # UTC-03:00 in secounds 3 hours difference
correct_date=$(echo $(($2+$timezone_offset)))
elif [ $Timezone == "-0200" ];
then
declare timezone_offset=7200 # UTC-02:00 in secounds 2 hours difference
correct_date=$(echo $(($2+$timezone_offset)))
elif [ $Timezone == "-0100" ];
then
declare timezone_offset=7200 # UTC-01:00 in secounds 1 hours difference
correct_date=$(echo $(($2+$timezone_offset)))
elif [ $Timezone == "+0000" ];
then
# UTC±00:00 in secounds no difference
correct_date=$(echo $2)
elif [ $Timezone == "+0100" ];
then
declare timezone_offset=7200 # UTC+01:00 in secounds 1 hours difference
correct_date=$(echo $(($2-$timezone_offset)))
elif [ $Timezone == "+0200" ];
then
declare timezone_offset=7200 # UTC+02:00 in secounds 2 hours difference
correct_date=$(echo $(($2-$timezone_offset)))
elif [ $Timezone == "+0300" ];
then
declare timezone_offset=10800 # UTC+03:00 in secounds 3 hours difference
correct_date=$(echo $(($2-$timezone_offset)))
elif [ $Timezone == "+0330" ];
then
declare timezone_offset=12600 # UTC+03:30 in secounds 3.5 hours difference
correct_date=$(echo $(($2-$timezone_offset)))
elif [ $Timezone == "+0400" ];
then
declare timezone_offset=14400 # UTC+04:00 in secounds 4 hours difference
correct_date=$(echo $(($2-$timezone_offset)))
elif [ $Timezone == "+0430" ];
then
declare timezone_offset=16200 # UTC+04:30 in secounds 4.5 hours difference
correct_date=$(echo $(($2-$timezone_offset)))
elif [ $Timezone == "+0500" ];
then
declare timezone_offset=18000 # UTC+05:00 in secounds 5 hours difference
correct_date=$(echo $(($2-$timezone_offset)))
elif [ $Timezone == "+0530" ];
then
declare timezone_offset=19800 # UTC+05:30 in secounds 5.5 hours difference
correct_date=$(echo $(($2-$timezone_offset)))
elif [ $Timezone == "+0545" ];
then
declare timezone_offset=20700 # UTC+05:45 in secounds 5.75 hours difference
correct_date=$(echo $(($2-$timezone_offset)))
elif [ $Timezone == "+0600" ];
then
declare timezone_offset=21600 # UTC+06:00 in secounds 6 hours difference
correct_date=$(echo $(($2-$timezone_offset)))
elif [ $Timezone == "+0630" ];
then
declare timezone_offset=23400 # UTC+06:30 in secounds 6.5 hours difference
correct_date=$(echo $(($2-$timezone_offset)))
elif [ $Timezone == "+0700" ];
then
declare timezone_offset=25200 # UTC+07:00 in secounds 7 hours difference
correct_date=$(echo $(($2-$timezone_offset)))
elif [ $Timezone == "+0800" ];
then
declare timezone_offset=28800 # UTC+08:00 in secounds 8 hours difference
correct_date=$(echo $(($2-$timezone_offset)))
elif [ $Timezone == "+0845" ];
then
declare timezone_offset=31500 # UTC+08:45 in secounds 8.75 hours difference
correct_date=$(echo $(($2-$timezone_offset)))
elif [ $Timezone == "+0900" ];
then
declare timezone_offset=32400 # UTC+09:00 in secounds 9 hours difference
correct_date=$(echo $(($2-$timezone_offset)))
elif [ $Timezone == "+0930" ];
then
declare timezone_offset=34200 # UTC+09:30 in secounds 9.5 hours difference
correct_date=$(echo $(($2-$timezone_offset)))
elif [ $Timezone == "+1000" ];
then
declare timezone_offset=72000 # UTC+10:00 in secounds 10 hours difference
correct_date=$(echo $(($2-$timezone_offset)))
elif [ $Timezone == "+1030" ];
then
declare timezone_offset=37800 # UTC+10:30 in secounds 10.5 hours difference
correct_date=$(echo $(($2-$timezone_offset)))
elif [ $Timezone == "+1100" ];
then
declare timezone_offset=39600 # UTC+11:00 in secounds 11 hours difference
correct_date=$(echo $(($2-$timezone_offset)))
elif [ $Timezone == "+1200" ];
then
declare timezone_offset=43200 # UTC+12:00 in secounds 12 hours difference
correct_date=$(echo $(($2-$timezone_offset)))
elif [ $Timezone == "+1245" ];
then
declare timezone_offset=45900 # UTC+12:45 in secounds 12.75 hours difference
correct_date=$(echo $(($2-$timezone_offset)))
elif [ $Timezone == "+1300" ];
then
declare timezone_offset=46800 # UTC+13:00 in secounds 13 hours difference
correct_date=$(echo $(($2-$timezone_offset)))
elif [ $Timezone == "+1400" ];
then
declare timezone_offset=50400 # UTC+14:00 in secounds 14 hours difference
correct_date=$(echo $(($2-$timezone_offset)))
else
#if there is no data UTC is used as default
# UTC±00:00 in secounds no difference
correct_date=$(echo $2)
fi
}
inverter_state () {
# List of possible Inverter Status (inverter_state) Description by Huawei. Based on documentation SmartPVMS.V300R006C10_API_Northbound.Interface.Reference.1.pdf pages 87-88 and my own obserations of device status and new documentation SmartPVMS V500R007C00 Northbound Interface Reference.pdf pages 97-98
#both documents
if [ $1 == "000" ] || [ $1 == "0" ];
then
printf "Standby: initializing"
elif [ $1 == "001" ] || [ $1 == "1" ];
then
printf "Standby: insulation resistance detection"
elif [ $1 == "002" ] || [ $1 == "2" ];
then
printf "Standby: sunlight detection"
elif [ $1 == "003" ] || [ $1 == "3" ];
then
printf "Standby: power grid detection"
#SmartPVMS V500R007C00 version
elif [ $1 == "256" ];
then
printf "Start"
elif [ $1 == "512" ];
then
printf "Grid-connected"
elif [ $1 == "513" ];
then
printf "Grid connection: limited power"
elif [ $1 == "514" ];
then
printf "Grid connection: self-derating"
elif [ $1 == "768" ];
then
printf "Shutdown: unexpected shutdown"
elif [ $1 == "769" ];
then
printf "Shutdown: commanded shutdown"
elif [ $1 == "770" ];
then
printf "Shutdown: OVGR"
elif [ $1 == "771" ];
then
printf "Shutdown: communication disconnection"
elif [ $1 == "772" ];
then
printf "Shutdown: limited power"
elif [ $1 == "773" ];
then
printf "Shutdown: manual startup is required"
elif [ $1 == "774" ];
then
printf "Shutdown: DC switch disconnected"
elif [ $1 == "1025" ];
then
printf "Grid schedule: cosφ-P curve"
elif [ $1 == "1026" ];
then
printf "Grid schedule: Q-U curve"
elif [ $1 == "1280" ];
then
printf "Spot-check ready"
elif [ $1 == "1281" ];
then
printf "Spot-checking"
elif [ $1 == "1536" ];
then
printf "Inspecting"
elif [ $1 == "1792" ];
then
printf "AFCI self-check"
elif [ $1 == "2048" ];
then
printf "I-V scanning"
elif [ $1 == "2304" ];
then
printf "DC input detection"
elif [ $1 == "40960" ];
then
printf "Standby: No sunlight"
elif [ $1 == "45056" ];
then
printf "Communication disconnection (written by the SmartLogger)"
elif [ $1 == "49152" ];
then
printf "Loading (written by the SmartLogger)"
#SmartPVMS V300R006C10 version
elif [ $1 == "100" ];
then
printf "Startup"
elif [ $1 == "200" ];
then
printf "On-grid"
elif [ $1 == "201" ];
then
printf "Grid connection: power limited"
elif [ $1 == "202" ];
then
printf "Grid connection: self-derating"
elif [ $1 == "300" ];
then
printf "Shutdown: unexpected shutdown"
elif [ $1 == "301" ];
then
printf "Shutdown: commanded shutdown"
elif [ $1 == "302" ];
then
printf "Shutdown: OVGR"
elif [ $1 == "303" ];
then
printf "Shutdown: communication disconnection"
elif [ $1 == "304" ];
then
printf "Shutdown: limited power"
elif [ $1 == "305" ];
then
printf "Shutdown: manual startup is required"
elif [ $1 == "306" ];
then
printf "Shutdown: DC switch disconnected"
elif [ $1 == "401" ];
then
printf "Grid schedule: cosφ-P curve"
elif [ $1 == "402" ];
then
printf "Grid schedule: Q-U curve"
elif [ $1 == "500" ];
then
printf "Spot-check ready"
elif [ $1 == "501" ];
then
printf "Spot-checking"
elif [ $1 == "600" ];
then
printf "Inspecting"
elif [ $1 == "700" ];
then
printf "AFCI self-test"
elif [ $1 == "800" ];
then
printf "I-V scanning"
elif [ $1 == "900" ];
then
printf "DC input detection"
elif [ $1 == "a000" ] || [ $1 == "A000" ];
then
printf "Standby: No sunlight"
elif [ $1 == "b000" ] || [ $1 == "B000" ];
then
printf "Communication disconnection (written by the SmartLogger)"
elif [ $1 == "c000" ] || [ $1 == "C000" ];
then
printf "Loading (written by the SmartLogger)"
else
printf "Unknown state"
fi
}
Device_type_ID () {
# List of possible smart devices in Power Plant by Huawei. Based on documentation SmartPVMS.V300R006C10_API_Northbound.Interface.Reference.1.pdf pages 28-30 and SmartPVMS V500R007C00 Northbound Interface Reference.pdf pages 41-42
if [ -z "$2" ];
then
#SmartPVMS V500R007C00 version
if [ $1 == "1" ];
then
printf "String Inverter"
elif [ $1 == "8" ];
then
printf "Transformer"
elif [ $1 == "10" ];
then
printf "EMI"
elif [ $1 == "13" ];
then
printf "Protocol converter"
elif [ $1 == "16" ];
then
printf "General device"
elif [ $1 == "17" ];
then
printf "Grid meter"
elif [ $1 == "22" ];
then
printf "PID"
elif [ $1 == "37" ];
then
printf "Pinnet data logger"
elif [ $1 == "38" ];
then
printf "Residential inverter"
elif [ $1 == "39" ];
then
printf "Battery"
elif [ $1 == "40" ];
then
printf "Backup Box"
elif [ $1 == "45" ];
then
printf "PLC"
elif [ $1 == "46" ];
then
printf "Optimizer"
elif [ $1 == "47" ];
then
printf "Power Sensor"
elif [ $1 == "62" ];
then
printf "Dongle"
elif [ $1 == "63" ];
then
printf "Distributed SmartLogger"
elif [ $1 == "70" ];
then
printf "Safety box"
#SmartPVMS V300R006C10 version
elif [ $1 == "2" ];
then
printf "SmartLogger"
elif [ $1 == "3" ];
then
printf "String"
elif [ $1 == "6" ];
then
printf "Bay"
elif [ $1 == "7" ];
then
printf "Busbar"
elif [ $1 == "9" ];
then
printf "Transformer meter"
elif [ $1 == "11" ];
then
printf "AC combiner box"
elif [ $1 == "14" ];
then
printf "Central Inverter"
elif [ $1 == "15" ];
then
printf "DC combiner box"
elif [ $1 == "18" ];
then
printf "Step-up station"
elif [ $1 == "19" ];
then
printf "Factory-used energy generation area meter"
elif [ $1 == "20" ];
then
printf "Solar power forecasting system"
elif [ $1 == "21" ];
then
printf "Factory-used energy non-generation area meter"
elif [ $1 == "23" ];
then
printf "Virtual device of plant monitoring system"
elif [ $1 == "24" ];
then
printf "Power quality device"
elif [ $1 == "25" ];
then
printf "Step-up transformer"
elif [ $1 == "26" ];
then
printf "Photovoltaic grid-connection cabinet"
elif [ $1 == "27" ];
then
printf "Photovoltaic grid-connection panel"
elif [ $1 == "52" ];
then
printf "SAJ data logger"
elif [ $1 == "53" ];
then
printf "High voltage bay of the main transformer"
elif [ $1 == "54" ];
then
printf "Main transformer"
elif [ $1 == "55" ];
then
printf "Low voltage bay of the main transformer"
elif [ $1 == "56" ];
then
printf "Bus bay"
elif [ $1 == "57" ];
then
printf "Line bay"
elif [ $1 == "58" ];
then
printf "Plant transformer bay"
elif [ $1 == "59" ];
then
printf "SVC/SVG bay"
elif [ $1 == "60" ];
then
printf "Bus tie/section bay"
elif [ $1 == "61" ];
then
printf "Plant power supply device"
#not documented based on users contribution
elif [ $1 == "23032" ];
then
printf "Huawei LUNA2000 Battery"
else
printf "Unknown Device"
fi
elif [ ! -z "$2" ] && [ $2 == "no_whitespace" ];
then
if [ $1 == "1" ];
then
printf "String_Inverter"
elif [ $1 == "2" ];
then
printf "SmartLogger"
elif [ $1 == "3" ];
then
printf "String"
elif [ $1 == "6" ];
then
printf "Bay"
elif [ $1 == "7" ];
then
printf "Busbar"
elif [ $1 == "8" ];
then
printf "Transformer"
elif [ $1 == "9" ];
then
printf "Transformer_meter"
elif [ $1 == "10" ];
then
printf "EMI"
elif [ $1 == "11" ];
then
printf "AC_combiner_box"
elif [ $1 == "13" ];
then
printf "Protocol_converter"
elif [ $1 == "14" ];
then
printf "Central_Inverter"
elif [ $1 == "15" ];
then
printf "DC_combiner_box"
elif [ $1 == "16" ];
then
printf "General_device"
elif [ $1 == "17" ];
then
printf "Grid_meter"
elif [ $1 == "18" ];
then
printf "Step-up station"
elif [ $1 == "19" ];
then
printf "Factory-used_energy_generation_area_meter"
elif [ $1 == "20" ];
then
printf "Solar_power_forecasting_system"
elif [ $1 == "21" ];
then
printf "Factory-used_energy_non-generation_area_meter"
elif [ $1 == "22" ];
then
printf "PID"
elif [ $1 == "23" ];
then
printf "Virtual_device_of_plant_monitoring_system"
elif [ $1 == "24" ];
then
printf "Power_quality_device"
elif [ $1 == "25" ];
then
printf "Step-up_transformer"
elif [ $1 == "26" ];
then
printf "Photovoltaic_grid-connection_cabinet"
elif [ $1 == "27" ];
then
printf "Photovoltaic_grid-connection_panel"
elif [ $1 == "37" ];
then
printf "Pinnet_data_logger"
elif [ $1 == "38" ];
then
printf "Residential_inverter"
elif [ $1 == "39" ];
then
printf "Battery"
elif [ $1 == "40" ];
then
printf "Backup_Box"
elif [ $1 == "45" ];
then
printf "PLC"
elif [ $1 == "46" ];
then
printf "Optimizer"
elif [ $1 == "47" ];
then
printf "Power_Sensor"
elif [ $1 == "52" ];
then
printf "SAJ_data_logger"
elif [ $1 == "53" ];
then
printf "High_voltage_bay_of_the_main_transformer"
elif [ $1 == "54" ];
then
printf "Main_transformer"
elif [ $1 == "55" ];
then
printf "Low_voltage_bay_of_the_main_transformer"
elif [ $1 == "56" ];
then
printf "Bus_bay"
elif [ $1 == "57" ];
then
printf "Line_bay"
elif [ $1 == "58" ];
then
printf "Plant_transformer_bay"
elif [ $1 == "59" ];
then
printf "SVC/SVG_bay"
elif [ $1 == "60" ];
then
printf "Bus_tie/section_bay"
elif [ $1 == "61" ];
then
printf "Plant_power_supply_device"
elif [ $1 == "62" ];
then
printf "Dongle"
elif [ $1 == "63" ];
then
printf "Distributed_SmartLogger"
elif [ $1 == "70" ];
then
printf "Safety_box"
#not documented based on users contribution
elif [ $1 == "23032" ];
then
printf "Huawei_LUNA2000_Battery"
else
printf "Unknown_Device"
fi
else
printf "Error"
fi
}
Error_Codes_List () {
#Errors which are possible during login and connection to Huawei SolarFussion API based on documentation SmartPVMS V500R007C00 Northbound Interface Reference.pdf pages 100-101 and own observations and tests.
if [ "$1" == "0" ];
then
if [ ! -z "$DIALOG" ];
then
info_for_dialog_screen=$info_for_dialog_screen"\nNormal Status"
else
echo "Normal Status"
fi
elif [ "$1" == "20001" ];
then
if [ ! -z "$DIALOG" ];
then
info_for_dialog_screen=$info_for_dialog_screen"\nThe third-party system ID does not exist."
else
echo "The third-party system ID does not exist."
fi
elif [ "$1" == "305" ] || [ "$1" = "306" ];
then
if [ ! -z "$DIALOG" ];
then
info_for_dialog_screen=$info_for_dialog_screen"\nYou are not in the login state. You need to log in again."
else
echo "You are not in the login state. You need to log in again."
fi
elif [ "$1" == "401" ];
then
if [ ! -z "$DIALOG" ];
then
info_for_dialog_screen=$info_for_dialog_screen"\nYou do not have the permission on the related data interface."
else
echo "You do not have the permission on the related data interface."
fi
elif [ "$1" == "407" ];
then
if [ ! -z "$DIALOG" ];
then
info_for_dialog_screen=$info_for_dialog_screen"\nThe interface access frequency is too high."
else
echo "The interface access frequency is too high."
fi
elif [ "$1" == "413" ];
then
if [ ! -z "$DIALOG" ];
then
info_for_dialog_screen=$info_for_dialog_screen"\nYour IP is locked."
else
echo "Your IP is locked."
fi
elif [ "$1" == "20002" ];
then
if [ ! -z "$DIALOG" ];
then
info_for_dialog_screen=$info_for_dialog_screen"\nThe third-party system has been disabled."
else
echo "The third-party system has been disabled."
fi
elif [ "$1" == "20003" ];
then
if [ ! -z "$DIALOG" ];
then
info_for_dialog_screen=$info_for_dialog_screen"\nThe third-party system has expired."
else
echo "The third-party system has expired."
fi
elif [ "$1" == "20004" ];
then
if [ ! -z "$DIALOG" ];
then
info_for_dialog_screen=$info_for_dialog_screen"\nThe server is abnormal."
else
echo "The server is faulty."
fi
elif [ "$1" == "20005" ];
then
if [ ! -z "$DIALOG" ];
then
info_for_dialog_screen=$info_for_dialog_screen"\nThe device ID cannot be empty."
else
echo "The device ID cannot be empty."
fi
elif [ "$1" == "20006" ];
then
if [ ! -z "$DIALOG" ];
then
info_for_dialog_screen=$info_for_dialog_screen"\nSome devices do not match the device type."
else
echo "Some devices do not match the device type."
fi
elif [ "$1" == "20007" ];
then
if [ ! -z "$DIALOG" ];
then
info_for_dialog_screen=$info_for_dialog_screen"\nThe system does not have the related power plant resources."
else
echo "The system does not have the related power plant resources."
fi
elif [ "$1" == "20008" ];
then
if [ ! -z "$DIALOG" ];
then
info_for_dialog_screen=$info_for_dialog_screen"\nThe system does not have the related device resources."
else
echo "The system does not have the related device resources."
fi
elif [ "$1" == "20009" ];
then
if [ ! -z "$DIALOG" ];
then
info_for_dialog_screen=$info_for_dialog_screen"\nThe system does not have the permission to query related interfaces. Contact the system administrator to configure the permission."
else
echo "The system does not have the permission to query related interfaces. Contact the system administrator to configure the permission."
fi
elif [ "$1" == "20010" ];
then
if [ ! -z "$DIALOG" ];
then
info_for_dialog_screen=$info_for_dialog_screen"\nThe plant list cannot be empty."
else
echo "The plant list cannot be empty."
fi
elif [ "$1" == "20011" ];
then
if [ ! -z "$DIALOG" ];
then
info_for_dialog_screen=$info_for_dialog_screen"\nThe device list cannot be empty."
else
echo "The device list cannot be empty."
fi
elif [ "$1" == "20012" ];
then
if [ ! -z "$DIALOG" ];
then
info_for_dialog_screen=$info_for_dialog_screen"\nThe query time cannot be empty."
else
echo "The query time cannot be empty."
fi
elif [ "$1" == "20013" ];
then
if [ ! -z "$DIALOG" ];
then
info_for_dialog_screen=$info_for_dialog_screen"\nThe device type is incorrect. The interface does not support operations on the devices."
else
echo "The device type is incorrect. The interface does not support operations on the devices."
fi
elif [ "$1" == "20014" ] || [ "$1" = "20015" ];
then
if [ ! -z "$DIALOG" ];
then
info_for_dialog_screen=$info_for_dialog_screen"\nA maximum of 100 plants can be queried at a time."
else
echo "A maximum of 100 plants can be queried at a time."
fi
elif [ "$1" == "20016" ] || [ "$1" = "20017" ];
then
if [ ! -z "$DIALOG" ];
then
info_for_dialog_screen=$info_for_dialog_screen"\nA maximum of 100 devices can be queried at a time."
else
echo "A maximum of 100 devices can be queried at a time."
fi
elif [ "$1" == "20018" ];
then
if [ ! -z "$DIALOG" ];
then
info_for_dialog_screen=$info_for_dialog_screen"\nA maximum of 10 devices can be manipulated at a time."
else
echo "A maximum of 10 devices can be manipulated at a time."
fi
elif [ "$1" == "20019" ];
then
if [ ! -z "$DIALOG" ];
then
info_for_dialog_screen=$info_for_dialog_screen"\nThe switch type is incorrect. (1: switch-on; 2: switch-off)"
else
echo "The switch type is incorrect. (1: switch-on; 2: switch-off)"
fi
elif [ "$1" == "20020" ];
then
if [ ! -z "$DIALOG" ];
then
info_for_dialog_screen=$info_for_dialog_screen"\nThe upgrade package corresponding to the device version cannot be found."
else
echo "The upgrade package corresponding to the device version cannot be found."
fi
elif [ "$1" == "20021" ];
then
if [ ! -z "$DIALOG" ];
then
info_for_dialog_screen=$info_for_dialog_screen"\nThe upgrade file does not exist."
else
echo "The upgrade file does not exist."
fi
elif [ "$1" == "20022" ];
then
if [ ! -z "$DIALOG" ];
then
info_for_dialog_screen=$info_for_dialog_screen"\nNo upgrade record of the related device is found."
else
echo "No upgrade record of the related device is found."
fi
elif [ "$1" == "20023" ];
then
if [ ! -z "$DIALOG" ];
then
info_for_dialog_screen=$info_for_dialog_screen"\nThe query start time cannot be later than the query end time."
else
echo "The query start time cannot be later than the query end time."
fi
elif [ "$1" == "20024" ];
then
if [ ! -z "$DIALOG" ];
then
info_for_dialog_screen=$info_for_dialog_screen"\nThe language cannot be empty."
else
echo "The language cannot be empty."
fi
elif [ "$1" == "20025" ];
then
if [ ! -z "$DIALOG" ];
then
info_for_dialog_screen=$info_for_dialog_screen"\nThe value of the language parameter is incorrect."
else
echo "The value of the language parameter is incorrect."
fi
elif [ "$1" == "20026" ];
then
if [ ! -z "$DIALOG" ];
then
info_for_dialog_screen=$info_for_dialog_screen"\nOnly data of the latest 365 days can be queried."
else
echo "Only data of the latest 365 days can be queried."
fi
elif [ "$1" == "20027" ];
then
if [ ! -z "$DIALOG" ];
then
info_for_dialog_screen=$info_for_dialog_screen"\nThe query period cannot be longer than 31 days."
else
echo "The query period cannot be longer than 31 days."
fi
else
if [ ! -z "$DIALOG" ];
then
info_for_dialog_screen=$info_for_dialog_screen"\nUnknown error."
else
echo "Unknown error."
fi
fi
}
function in_case_of_error_with_connection_to_API {
local immediately=$(echo ''$1'' | jq '.data.immediately' )
if [[ $immediately == true ]];
then
local when_relogin="NOW"
elif [[ $immediately == false ]];
then
local when_relogin="NOT NOW"
else
local when_relogin="Don't know when"
fi
local message=$(echo ''$1'' | jq '.data.message' )
if [[ ! $message =~ "null" ]];
then
if [ ! -z "$DIALOG" ];
then
info_for_dialog_screen=$info_for_dialog_screen"\nMessage: "$when_relogin" "$message
else
echo "Message: "$when_relogin" "$message
fi
fi
}
function login_to_API {
#check if data about dialog is active are delivered into function
#echo $1
#echo $DIALOG
# window for dialog TUI progress of login or simple echo in case if dialog TUI wasn't in use.
if [ ! -z "$DIALOG" ];
then
if [ $DIALOG == "whiptail" ]
then
TERM=ansi $DIALOG --title " Please wait connecting!" \
--backtitle "Huawei FusionSolarApp API" \
--infobox "\nConnection to API" 10 30
else
$DIALOG --title " Please wait connecting!" \
--backtitle "Huawei FusionSolarApp API" \
--infobox "\nConnection to API" 10 30
fi
else
echo ""
echo "Please wait connecting!"
echo "Connection to API"
echo ""
fi
#checking if username&password imported from config.conf contains space character and correcting this removing spaces in memory
if [[ "${huawei_account_login["$1"]}" == *" "* ]] || [[ "${huawei_account_login["$2"]}" == *" "* ]];
then
#correcting username
huawei_account_login["$1"]="$(echo "${huawei_account_login["$1"]}" | tr -d '[:space:]')"
#correcting password
huawei_account_login["$2"]="$(echo "${huawei_account_login["$2"]}" | tr -d '[:space:]')"
fi
# Login to FusionSolarAPI with Username and Password
local logowanie=$(echo '{"userName": "'${huawei_account_login["$1"]}'", "systemCode": "'${huawei_account_login["$2"]}'"}'| http --print=hb --follow --timeout 7200 POST 'https://eu5.fusionsolar.huawei.com/thirdData/login' Content-Type:'application/json' Cookie:'Cookie_1=value; web-auth=true;')
#show as answer of of API for question
#echo $logowanie
#coping a long string with answer to new variable from which we extract JOSN answer
local logowanie_for_josn_extraction=$logowanie
local josn=$logowanie
#show for tests header in request
#echo $logowanie_for_josn_extraction
#echo $josn
IFS=':'
local array=( $logowanie )
# showing diffrent values experimenting with postion in array
#echo ""
#echo ""
#echo "value = ${array[22]}"