Repository navigation
Expand file tree
/
Copy pathRscpExampleMain.cpp
More file actions
executable file
·2530 lines (2232 loc) · 113 KB
/
Copy pathRscpExampleMain.cpp
File metadata and controls
executable file
·2530 lines (2232 loc) · 113 KB
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
#include <sys/stat.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <unistd.h>
#include <math.h>
#include "RscpProtocol.h"
#include "RscpTags.h"
#include "SocketConnection.h"
#include "AES.h"
#include <time.h>
#include "E3DC_CONF.h"
//#include "MQTTClient.h"
//#include "json.hpp"
// for convenience
// using json = nlohmann::json;
#define AES_KEY_SIZE 32
#define AES_BLOCK_SIZE 32
// json j;
static int iSocket = -1;
static int iAuthenticated = 0;
static int iBattPowerStatus = 0; // Status, ob schon mal angefragt,
static int iWBStatus = 0; // Status, WB schon mal angefragt, 0 inaktiv, 1 aktiv, 2 regeln
static int iLMStatus = 0; // Status, Load Management negativer Wert in Sekunden = Anforderung + Warten bis zur nächsten Anforderung, der angeforderte Wert steht in iE3DC_Req_Load
static int iLMStatus2 = 0; // Status, Load Management Peakshaving > 0 ist aktiv
static float fAvBatterie,fAvBatterie900;
static int iAvBatt_Count = 0;
static int iAvBatt_Count900 = 0;
static uint8_t WBchar[8];
static uint8_t WBchar6[6]; // Steuerstring zur Wallbox
const uint16_t iWBLen = 6;
static AES aesEncrypter;
static AES aesDecrypter;
static uint8_t ucEncryptionIV[AES_BLOCK_SIZE];
static uint8_t ucDecryptionIV[AES_BLOCK_SIZE];
// static int32_t iPower_Grid;
static uint8_t iCurrent_WB;
static uint8_t iCurrent_Set_WB;
static float fPower_Grid;
static float fAvPower_Grid,fAvPower_Grid3600,fAvPower_Grid600,fAvPower_Grid60; // Durchschnitt ungewichtete Netzleistung der letzten 10sec
static int iAvPower_GridCount = 0;
static float fPower_WB;
static int32_t iPower_PV, iPower_PV_E3DC;
static int32_t iPower_Bat;
static uint8_t iPhases_WB;
static uint8_t iCyc_WB;
static int32_t iBattLoad;
static int iPowerBalance,iPowerHome;
static uint8_t iNotstrom = 0;
static time_t tE3DC, tWBtime;
static int32_t iFc, iMinLade,iMinLade2; // Mindestladeladeleistung des E3DC Speichers
static float_t fL1V=230,fL2V=230,fL3V=230;
static int iDischarge = -1;
char cWBALG;
static bool bWBLademodus; // Lademodus der Wallbox; z.B. Sonnenmodus
static bool bWBConnect; // True = Dose ist verriegelt x08
static bool bWBStart; // True Laden ist gestartet x10
static bool bWBCharge; // True Laden ist gestartet x20
static bool bWBSonne; // Sonnenmodus x80
static bool bWBStopped; // Laden angehalten x40
static bool bWBmaxLadestrom; // Ladestrom der Wallbox per App eingestellt.; 32=ON 31 = OFF
static int32_t iE3DC_Req_Load,iE3DC_Req_Load_alt; // Leistung, mit der der E3DC-Seicher geladen oder entladen werden soll
FILE * pFile;
e3dc_config_t e3dc_config;
char Log[300];
int WriteLog()
{
static time_t t,t_alt = 0;
int day,hour;
char fname[127];
time(&t);
FILE *fp;
struct tm * ptm;
ptm = gmtime(&t);
day = (t%(24*3600*4))/(24*3600);
hour = (t%(24*3600))/(3600*4)*4;
if (e3dc_config.debug) {
if (hour!=t_alt) // neuer Tag
{
// int tt = (t%(24*3600)+12*3600);
sprintf(fname,"%s.%i.%i.txt",e3dc_config.logfile,day,hour);
fp = fopen(fname,"w"); // altes logfile löschen
fclose(fp);
}
sprintf(fname,"%s.%i.%i.txt",e3dc_config.logfile,day,hour);
fp = fopen(fname, "a");
if(!fp)
fp = fopen(fname, "w");
if(fp)
fprintf(fp,"%s\n",Log);
fclose(fp);}
t_alt = hour;
;
return(0);
}
int MQTTsend(char buffer[127])
{
char cbuf[127];
if (e3dc_config.openWB) {
sprintf(cbuf, "mosquitto_pub -r -h %s -t %s", e3dc_config.openWBhost,buffer);
system(cbuf);
}
return(0);
}
int ControlLoadData(SRscpFrameBuffer * frameBuffer,int32_t Power,int32_t Mode ) {
RscpProtocol protocol;
SRscpValue rootValue;
// The root container is create with the TAG ID 0 which is not used by any device.
protocol.createContainerValue(&rootValue, 0);
// request Power Meter information
SRscpValue PMContainer;
// Power = Power*-1;
protocol.createContainerValue(&PMContainer, TAG_EMS_REQ_SET_POWER);
protocol.appendValue(&PMContainer, TAG_EMS_REQ_SET_POWER_MODE,Mode);
if (Mode > 0)
protocol.appendValue(&PMContainer, TAG_EMS_REQ_SET_POWER_VALUE,Power);
// append sub-container to root container
protocol.appendValue(&rootValue, PMContainer);
// free memory of sub-container as it is now copied to rootValue
protocol.destroyValueData(PMContainer);
// create buffer frame to send data to the S10
protocol.createFrameAsBuffer(frameBuffer, rootValue.data, rootValue.length, true); // true to calculate CRC on for transfer
// the root value object should be destroyed after the data is copied into the frameBuffer and is not needed anymore
protocol.destroyValueData(rootValue);
return 0;
}
int ControlLoadData2(SRscpFrameBuffer * frameBuffer,int32_t iPower) {
RscpProtocol protocol;
SRscpValue rootValue;
uint32_t uPower;
if (iPower < 0) uPower = 0; else if (iPower>e3dc_config.maximumLadeleistung) uPower = e3dc_config.maximumLadeleistung; else uPower = iPower;
// The root container is create with the TAG ID 0 which is not used by any device.
protocol.createContainerValue(&rootValue, 0);
// request Power Meter information
SRscpValue PMContainer;
protocol.createContainerValue(&PMContainer, TAG_EMS_REQ_SET_POWER_SETTINGS);
protocol.appendValue(&PMContainer, TAG_EMS_POWER_LIMITS_USED,true);
protocol.appendValue(&PMContainer, TAG_EMS_MAX_CHARGE_POWER,uPower);
// protocol.appendValue(&PMContainer, TAG_EMS_MAX_DISCHARGE_POWER,300);
// protocol.appendValue(&PMContainer, TAG_EMS_DISCHARGE_START_POWER,70);
// append sub-container to root container
protocol.appendValue(&rootValue, PMContainer);
// free memory of sub-container as it is now copied to rootValue
protocol.destroyValueData(PMContainer);
// create buffer frame to send data to the S10
protocol.createFrameAsBuffer(frameBuffer, rootValue.data, rootValue.length, true); // true to calculate CRC on for transfer
// the root value object should be destroyed after the data is copied into the frameBuffer and is not needed anymore
protocol.destroyValueData(rootValue);
return 0;
}
int Control_MAX_DISCHARGE(SRscpFrameBuffer * frameBuffer,int32_t iPower) {
RscpProtocol protocol;
SRscpValue rootValue;
uint32_t uPower;
if (iPower < 0) uPower = 0; else if (iPower>e3dc_config.maximumLadeleistung) uPower = e3dc_config.maximumLadeleistung; else uPower = iPower;
// The root container is create with the TAG ID 0 which is not used by any device.
protocol.createContainerValue(&rootValue, 0);
// request Power Meter information
SRscpValue PMContainer;
protocol.createContainerValue(&PMContainer, TAG_EMS_REQ_SET_POWER_SETTINGS);
protocol.appendValue(&PMContainer, TAG_EMS_POWER_LIMITS_USED,true);
if (uPower < 65)
protocol.appendValue(&PMContainer, TAG_EMS_DISCHARGE_START_POWER,uPower);
else
protocol.appendValue(&PMContainer, TAG_EMS_DISCHARGE_START_POWER,uint32_t(65));
protocol.appendValue(&PMContainer, TAG_EMS_MAX_DISCHARGE_POWER,uPower);
// append sub-container to root container
protocol.appendValue(&rootValue, PMContainer);
// free memory of sub-container as it is now copied to rootValue
protocol.destroyValueData(PMContainer);
// create buffer frame to send data to the S10
protocol.createFrameAsBuffer(frameBuffer, rootValue.data, rootValue.length, true); // true to calculate CRC on for transfer
// the root value object should be destroyed after the data is copied into the frameBuffer and is not needed anymore
protocol.destroyValueData(rootValue);
return 0;
}
int createRequestWBData(SRscpFrameBuffer * frameBuffer) {
RscpProtocol protocol;
SRscpValue rootValue;
iWBStatus=7;
// The root container is create with the TAG ID 0 which is not used by any device.
protocol.createContainerValue(&rootValue, 0);
// request Power Meter information
SRscpValue WBContainer;
SRscpValue WB2Container;
// request Wallbox data
protocol.createContainerValue(&WBContainer, TAG_WB_REQ_DATA) ;
// add index 0 to select first wallbox
protocol.appendValue(&WBContainer, TAG_WB_INDEX,0);
protocol.createContainerValue(&WB2Container, TAG_WB_REQ_SET_EXTERN);
protocol.appendValue(&WB2Container, TAG_WB_EXTERN_DATA_LEN,6);
protocol.appendValue(&WB2Container, TAG_WB_EXTERN_DATA,WBchar6,iWBLen);
protocol.appendValue(&WBContainer, WB2Container);
// free memory of sub-container as it is now copied to rootValue
protocol.destroyValueData(WB2Container);
// append sub-container to root container
protocol.appendValue(&rootValue, WBContainer);
// protocol.appendValue(&rootValue, WB2Container);
// free memory of sub-container as it is now copied to rootValue
protocol.destroyValueData(WBContainer);
// create buffer frame to send data to the S10
protocol.createFrameAsBuffer(frameBuffer, rootValue.data, rootValue.length, true); // true to calculate CRC on for transfer
// the root value object should be destroyed after the data is copied into the frameBuffer and is not needed anymore
protocol.destroyValueData(rootValue);
return 0;
}
static float fBatt_SOC, fBatt_SOC_alt;
static float_t fSavedtoday, fSavedyesderday,fSavedtotal,fSavedWB; // Überschussleistung
static int32_t iDiffLadeleistung, iDiffLadeleistung2;
static time_t tLadezeit_alt,tLadezeitende_alt,tE3DC_alt;
static time_t t = 0;
static time_t tm_CONF_dt;
static bool bCheckConfig;
bool CheckConfig()
{
struct stat stats;
time_t tm_dt;
stat(e3dc_config.conffile,&stats);
tm_dt = *(&stats.st_mtime);
if (tm_dt==tm_CONF_dt)
return false; else return true;
}
bool GetConfig()
{
// ermitteln location der conf-file
// get conf parameters
bool fpread=false;
struct stat stats;
FILE *fp;
fp = fopen(e3dc_config.conffile, "r");
if(!fp) {
sprintf(e3dc_config.conffile,"%s",CONF_FILE);
fp = fopen(CONF_FILE, "r");
}
if(fp) {
stat(e3dc_config.conffile,&stats);
tm_CONF_dt = *(&stats.st_mtime);
char var[128], value[128], line[256];
e3dc_config.wallbox = false;
e3dc_config.openWB = false;
e3dc_config.ext1 = false;
e3dc_config.ext2 = false;
e3dc_config.ext3 = false;
e3dc_config.ext7 = false;
sprintf(e3dc_config.logfile,"logfile");
sprintf(e3dc_config.openWBhost,"%s",OPENWB);
e3dc_config.debug = false;
e3dc_config.wurzelzaehler = 0;
e3dc_config.untererLadekorridor = UNTERERLADEKORRIDOR;
e3dc_config.obererLadekorridor = OBERERLADEKORRIDOR;
e3dc_config.minimumLadeleistung = MINIMUMLADELEISTUNG;
e3dc_config.maximumLadeleistung = MAXIMUMLADELEISTUNG;
e3dc_config.wrleistung = WRLEISTUNG;
e3dc_config.speichergroesse = SPEICHERGROESSE;
e3dc_config.winterminimum = WINTERMINIMUM;
e3dc_config.sommermaximum = SOMMERMAXIMUM;
e3dc_config.sommerladeende = SOMMERLADEENDE;
e3dc_config.einspeiselimit = EINSPEISELIMIT;
e3dc_config.ladeschwelle = LADESCHWELLE;
e3dc_config.ladeende = LADEENDE;
e3dc_config.ladeende2 = LADEENDE2;
e3dc_config.unload = 100;
e3dc_config.ht = 0;
e3dc_config.htsat = false;
e3dc_config.htsun = false;
e3dc_config.hton = 0;
e3dc_config.htoff = 24*3600; // in Sekunden
e3dc_config.htsockel = 0;
e3dc_config.peakshave = 0;
e3dc_config.wbmode = 4;
e3dc_config.wbminlade = 1000;
while (fgets(line, sizeof(line), fp)) {
fpread = true;
memset(var, 0, sizeof(var));
memset(value, 0, sizeof(value));
if(sscanf(line, "%[^ \t=]%*[\t ]=%*[\t ]%[^\n]", var, value) == 2) {
if(strcmp(var, "server_ip") == 0)
strcpy(e3dc_config.server_ip, value);
else if(strcmp(var, "server_port") == 0)
e3dc_config.server_port = atoi(value);
else if(strcmp(var, "e3dc_user") == 0)
strcpy(e3dc_config.e3dc_user, value);
else if(strcmp(var, "e3dc_password") == 0)
strcpy(e3dc_config.e3dc_password, value);
else if(strcmp(var, "aes_password") == 0)
strcpy(e3dc_config.aes_password, value);
else if(strcmp(var, "openWBhost") == 0)
strcpy(e3dc_config.openWBhost, value);
else if(strcmp(var, "wurzelzaehler") == 0)
e3dc_config.wurzelzaehler = atoi(value);
else if((strcmp(var, "wallbox") == 0)&&
(strcmp(value, "true") == 0))
e3dc_config.wallbox = true;
else if((strcmp(var, "openWB") == 0)&&
(strcmp(value, "true") == 0))
e3dc_config.openWB = true;
else if((strcmp(var, "ext1") == 0)&&
(strcmp(value, "true") == 0))
e3dc_config.ext1 = true;
else if((strcmp(var, "ext2") == 0)&&
(strcmp(value, "true") == 0))
e3dc_config.ext2 = true;
else if((strcmp(var, "ext3") == 0)&&
(strcmp(value, "true") == 0))
e3dc_config.ext3 = true;
else if((strcmp(var, "ext7") == 0)&&
(strcmp(value, "true") == 0))
e3dc_config.ext7 = true;
else if(strcmp(var, "logfile") == 0)
strcpy(e3dc_config.logfile, value);
else if((strcmp(var, "debug") == 0)&&
(strcmp(value, "true") == 0))
{e3dc_config.debug = true;
}
else if(strcmp(var, "untererLadekorridor") == 0)
e3dc_config.untererLadekorridor = atoi(value);
else if(strcmp(var, "obererLadekorridor") == 0)
e3dc_config.obererLadekorridor = atoi(value);
else if(strcmp(var, "minimumLadeleistung") == 0)
e3dc_config.minimumLadeleistung = atoi(value);
else if(strcmp(var, "maximumLadeleistung") == 0)
e3dc_config.maximumLadeleistung = atoi(value);
else if(strcmp(var, "wrleistung") == 0)
e3dc_config.wrleistung = atoi(value);
else if(strcmp(var, "speichergroesse") == 0)
e3dc_config.speichergroesse = atof(value);
else if(strcmp(var, "winterminimum") == 0)
e3dc_config.winterminimum = atof(value);
else if(strcmp(var, "sommermaximum") == 0)
e3dc_config.sommermaximum = atof(value);
else if(strcmp(var, "sommerladeende") == 0)
e3dc_config.sommerladeende = atof(value);
else if(strcmp(var, "einspeiselimit") == 0)
e3dc_config.einspeiselimit = atof(value);
else if(strcmp(var, "ladeschwelle") == 0)
e3dc_config.ladeschwelle = atoi(value);
else if(strcmp(var, "ladeende") == 0)
e3dc_config.ladeende = atoi(value);
else if(strcmp(var, "ladeende2") == 0)
e3dc_config.ladeende2 = atoi(value);
else if(strcmp(var, "unload") == 0)
e3dc_config.unload = atoi(value);
else if(strcmp(var, "htmin") == 0)
e3dc_config.ht = atoi(value);
else if(strcmp(var, "htsockel") == 0)
e3dc_config.htsockel = atoi(value);
else if(strcmp(var, "wbmode") == 0)
e3dc_config.wbmode = atoi(value);
else if(strcmp(var, "wbminlade") == 0)
e3dc_config.wbminlade = atoi(value);
else if(strcmp(var, "peakshave") == 0)
e3dc_config.peakshave = atoi(value); // in Watt
else if(strcmp(var, "hton") == 0)
e3dc_config.hton = atof(value)*3600; // in Sekunden
else if(strcmp(var, "htoff") == 0)
e3dc_config.htoff = atof(value)*3600; // in Sekunden
else if((strcmp(var, "htsat") == 0)&&
(strcmp(value, "true") == 0))
e3dc_config.htsat = true;
else if((strcmp(var, "htsun") == 0)&&
(strcmp(value, "true") == 0))
e3dc_config.htsun = true;
}
}
// printf("e3dc_user %s\n",e3dc_config.e3dc_user);
// printf("e3dc_password %s\n",e3dc_config.e3dc_password);
// printf("aes_password %s\n",e3dc_config.aes_password);
fclose(fp);
}
if ((!fp)||not (fpread)) printf("Configurationsdatei %s nicht gefunden",CONF_FILE);
return fpread;
}
int LoadDataProcess(SRscpFrameBuffer * frameBuffer) {
// const int cLadezeitende1 = 12.5*3600; // Sommerzeit -2h da GMT = MEZ - 2
printf("\n");
tm *ts;
ts = gmtime(&tE3DC);
int hh,mm,ss;
hh = t % (24*3600)/3600;
mm = t % (3600)/60;
ss = t % (60);
if (((tE3DC % (24*3600))+12*3600)<t) {
// Erstellen Statistik, Eintrag Logfile
sprintf(Log,"Time %s U:%0.04f td:%0.04f yd:%0.04f WB%0.04f", strtok(asctime(ts),"\n"),fSavedtotal/3600000,fSavedtoday/3600000,fSavedyesderday/3600000,fSavedWB/3600000);
WriteLog();
if (fSavedtoday > 0)
{
FILE *fp;
fp = fopen("savedtoday.txt", "a");
if(!fp)
fp = fopen("savedtoday.txt", "w");
if(fp){
fprintf(fp,"%s\n",Log);
fclose(fp);}
}
fSavedyesderday=fSavedtoday; fSavedtoday=0;
fSavedtotal=0; fSavedWB=0;
}
t = tE3DC % (24*3600);
static time_t t_config = tE3DC;
if ((tE3DC-t_config) > 10)
{
if (CheckConfig()) // Config-Datei hat sich geändert;
{
// printf("Config geändert");
GetConfig();
bCheckConfig = true;
// printf("Config neu eingelesen");
}
t_config = tE3DC;
}
float fLadeende = e3dc_config.ladeende;
float fLadeende2 = e3dc_config.ladeende2;
float fLadeende3 = e3dc_config.unload;
if (cos((ts->tm_yday+9)*2*3.14/365) > 0)
{
fLadeende = (cos((ts->tm_yday+9)*2*3.14/365))*((100+e3dc_config.ladeende2)/2-fLadeende)+fLadeende;
fLadeende2 = (cos((ts->tm_yday+9)*2*3.14/365))*(100-fLadeende2)+fLadeende2;
fLadeende3 = (cos((ts->tm_yday+9)*2*3.14/365))*(100-fLadeende3)+fLadeende3;
}
int cLadezeitende1 = (e3dc_config.winterminimum+(e3dc_config.sommermaximum-e3dc_config.winterminimum)/2)*3600;
int cLadezeitende2 = (e3dc_config.winterminimum+0.5+(e3dc_config.sommerladeende-e3dc_config.winterminimum-0.5)/2)*3600; // eine halbe Stunde Später
int cLadezeitende3 = (e3dc_config.winterminimum-(e3dc_config.sommermaximum-e3dc_config.winterminimum)/2)*3600; //Unload
time_t tLadezeitende,tLadezeitende1,tLadezeitende2,tLadezeitende3; // dynamische Ladezeitberechnung aus dem Cosinus des lfd Tages. 23 Dez = Minimum, 23 Juni = Maximum
int32_t tZeitgleichung;
tLadezeitende1 = cLadezeitende1+cos((ts->tm_yday+9)*2*3.14/365)*-((e3dc_config.sommermaximum-e3dc_config.winterminimum)/2)*3600;
tLadezeitende2 = cLadezeitende2+cos((ts->tm_yday+9)*2*3.14/365)*-((e3dc_config.sommerladeende-e3dc_config.winterminimum-0.5)/2)*3600;
tLadezeitende3 = cLadezeitende3-cos((ts->tm_yday+9)*2*3.14/365)*-((e3dc_config.sommermaximum-e3dc_config.winterminimum)/2)*3600;
// float fht = e3dc_config.ht * cos((ts->tm_yday+9)*2*3.14/365);
float fht = e3dc_config.htsockel + (e3dc_config.ht-e3dc_config.htsockel) * cos((ts->tm_yday+9)*2*3.14/365);
// HT Endeladeleistung freigeben
// Mo-Fr wird während der Hochtarif der Speicher zwischen hton und htoff endladen
// Samstag und Sonntag nur wenn htsat und htsun auf true gesetzt sind.
// Damit kann gleich eine intelligente Notstromreserve realisiert werden.
// Die in ht eingestellte Reserve wird zwischen diesem Wert und 0% zur Tag-Nachtgleiche gesetzt
// Die Notstromreserve im System ist davon unberührt
if (iLMStatus == 1) {
if ((((ts->tm_wday>0&&ts->tm_wday<6) ||
((ts->tm_wday==0)&&e3dc_config.htsun)
||
((ts->tm_wday==6)&&e3dc_config.htsat) )&&
(
((e3dc_config.hton > e3dc_config.htoff) &&
((e3dc_config.hton < t) ||
(e3dc_config.htoff > t )))
||
((e3dc_config.hton < e3dc_config.htoff) &&
(e3dc_config.hton < t && e3dc_config.htoff > t )))
)
||
(fht<fBatt_SOC)
||(iNotstrom==1) //Notstrom
||(iNotstrom==4) //Inselbetrieb
){
// ENdladen einschalten)
if ((iPower_Bat == 0)&&(fPower_Grid>100))
{ sprintf(Log,"BAT %s %0.02f %i %i% 0.02f",strtok(asctime(ts),"\n"),fBatt_SOC, iE3DC_Req_Load, iPower_Bat, fPower_Grid);
WriteLog();
iLMStatus = 10;
}
if (iDischarge < e3dc_config.maximumLadeleistung) {
Control_MAX_DISCHARGE(frameBuffer,e3dc_config.maximumLadeleistung);
iBattPowerStatus = 0;
iLMStatus = 5;
sprintf(Log,"Ein %s %0.02f %0.02f %i", strtok(asctime(ts),"\n"),fht,fBatt_SOC, iE3DC_Req_Load);
WriteLog();
}
} else {
// Endladen ausschalten
if (iDischarge >1)
// Ausschalten nur wenn nicht im Notstrom/Inselbetrieb
{ Control_MAX_DISCHARGE(frameBuffer,0);
iBattPowerStatus = 0;
iLMStatus = 5;
sprintf(Log,"AUS %s %0.02f %0.02f %i", strtok(asctime(ts),"\n"),fht,fBatt_SOC, iE3DC_Req_Load);
WriteLog();
;}
}}
// HT Endeladeleistung freigeben ENDE
// Berechnung freie Ladekapazität bis 90% bzw. Ladeende
tZeitgleichung = (-0.171*sin(0.0337 * ts->tm_yday + 0.465) - 0.1299*sin(0.01787 * ts->tm_yday - 0.168))*3600;
tLadezeitende1 = tLadezeitende1 - tZeitgleichung;
tLadezeitende2 = tLadezeitende2 - tZeitgleichung;
tLadezeitende3 = tLadezeitende3 - tZeitgleichung;
tLadezeitende = tLadezeitende1;
printf("RB %2ld:%2ld %0.1f%% ",tLadezeitende3/3600,tLadezeitende3%3600/60,fLadeende3);
printf("RE %2ld:%2ld %0.1f%% ",tLadezeitende1/3600,tLadezeitende1%3600/60,fLadeende);
printf("LE %2ld:%2ld %0.1f%%\n",tLadezeitende2/3600,tLadezeitende2%3600/60,fLadeende2);
// Überwachungszeitraum für das Überschussladen übschritten und Speicher > Ladeende
// Dann wird langsam bis Abends der Speicher bis 93% geladen und spätestens dann zum Vollladen freigegeben.
if (t < tLadezeitende3) {
// tLadezeitende = tLadezeitende3;
// Vor Regelbeginn. Ist der SoC > fLadeende3 wird entladen
// wenn die Abweichung vom SoC < 0.3% ist wird als Ziel der aktuelle SoC genommen
// damit wird ein Wechsel von Laden/Endladen am Ende der Periode verhindert
if ((fBatt_SOC-fLadeende3) > 0){
if ((fBatt_SOC-fLadeende3) < 0.6)
fLadeende = fBatt_SOC; else
// Es wird bis tLadezeitende3 auf fLadeende3 entladen
fLadeende = fLadeende3;
tLadezeitende = tLadezeitende3;}
}
else
if ((t >= tLadezeitende)&&(fBatt_SOC>=fLadeende)) {
tLadezeitende = tLadezeitende2;
if (fLadeende < fLadeende2)
fLadeende = fLadeende2;
}
if (t < tLadezeitende2)
// Berechnen der linearen Ladeleistung bis tLadezeitende2 = Sommerladeende
{iMinLade2 = ((fLadeende2 - fBatt_SOC)*e3dc_config.speichergroesse*10*3600)/(tLadezeitende2-t);
if (iMinLade2>e3dc_config.maximumLadeleistung)
iMinLade2=e3dc_config.maximumLadeleistung;
}
else
if (fLadeende2 <= fBatt_SOC) iMinLade2 = 0;
else iMinLade2 = e3dc_config.maximumLadeleistung;
if (t < tLadezeitende)
{
if ((fBatt_SOC!=fBatt_SOC_alt)||(t-tLadezeit_alt>300)||(tLadezeitende!=tLadezeitende_alt)||(iFc == 0)||bCheckConfig)
// Neuberechnung der Ladeleistung erfolgt, denn der SoC sich ändert oder
// tLadezeitende sich ändert oder nach Ablauf von höchstens 5 Minuten
{
fBatt_SOC_alt=fBatt_SOC; // bei Änderung SOC neu berechnen
bCheckConfig=false;
tLadezeitende_alt = tLadezeitende; // Auswertungsperiode
tLadezeit_alt=t; // alle 300sec Berechnen
// Berechnen der Ladeleistung bis zum nächstliegenden Zeitpunkt
iFc = (fLadeende - fBatt_SOC)*e3dc_config.speichergroesse*10*3600;
if ((tLadezeitende-t) > 300)
iFc = iFc / (tLadezeitende-t); else
iFc = iFc / (300);
if (iFc > e3dc_config.maximumLadeleistung)
iMinLade = e3dc_config.maximumLadeleistung;
else
iMinLade = iFc;
// iFc = (iFc-900)*5;
if (iFc >= e3dc_config.untererLadekorridor)
iFc = (iFc-e3dc_config.untererLadekorridor);
else
if (abs(iFc) >= e3dc_config.untererLadekorridor)
iFc = (iFc+e3dc_config.untererLadekorridor);
else
iFc = 0;
iFc = iFc*(float(e3dc_config.maximumLadeleistung)/(e3dc_config.obererLadekorridor-e3dc_config.untererLadekorridor));
if (iFc > e3dc_config.maximumLadeleistung) iFc = e3dc_config.maximumLadeleistung;
if (abs(iFc) > e3dc_config.maximumLadeleistung) iFc = e3dc_config.maximumLadeleistung*-1;
if (abs(iFc) < e3dc_config.minimumLadeleistung) iFc = 0;
}
}
else
{ iFc = e3dc_config.maximumLadeleistung;
if (fBatt_SOC < fLadeende)
iMinLade = iFc;
else
iMinLade = 0;
}
// Laden auf 100% nach 15:30
if (iMinLade == iMinLade2)
printf("ML1 %i RQ %i ",iMinLade,iFc);
else
printf("ML1 %i ML2 %i RQ %i ",iMinLade, iMinLade2,iFc);
printf("GMT %2ld:%2ld ZG %d ",tLadezeitende/3600,tLadezeitende%3600/60,tZeitgleichung);
printf("E3DC: %s", asctime(ts));
int iPower = 0;
if (iLMStatus == 0){
iLMStatus = 5;
tLadezeit_alt = 0;
// iBattLoad = e3dc_config.maximumLadeleistung;
// iBattLoad = 100;
// fAvBatterie = e3dc_config.untererLadekorridor;
// ControlLoadData2(frameBuffer,iBattLoad);
}
if (iAvBatt_Count < 120) iAvBatt_Count++;
fAvBatterie = fAvBatterie*(iAvBatt_Count-1)/iAvBatt_Count;
fAvBatterie = fAvBatterie + (float(iPower_Bat)/iAvBatt_Count);
if (iAvBatt_Count900 < 900) iAvBatt_Count900++;
fAvBatterie900 = fAvBatterie900*(iAvBatt_Count900-1)/iAvBatt_Count900;
fAvBatterie900 = fAvBatterie900 + (float(iPower_Bat)/iAvBatt_Count900);
// Überschussleistung=iPower ermitteln
iPower = (-iPower_Bat + int32_t(fPower_Grid) - e3dc_config.einspeiselimit*-1000)*-1;
// die PV-leistung kann die WR-Leistung überschreiten. Überschuss in den Speicher laden;
if ((iPower_PV_E3DC - e3dc_config.wrleistung) > iPower)
iPower = (iPower_PV_E3DC - e3dc_config.wrleistung);
// if (iPower < 50) iPower = 0;
// else
// if (iPower > e3dc_config.maximumLadeleistung) iPower = e3dc_config.maximumLadeleistung;
// else
// if (iPower <100) iPower = 100;
// Ermitteln Überschuss/gesicherte Leistungen
if (iPower > 0)
{if (iPower >iPower_Bat)
fSavedtoday = fSavedtoday + iPower_Bat;
else
fSavedtoday = fSavedtoday + iPower;}
if (iPower_PV > e3dc_config.einspeiselimit*1000)
{fSavedtotal = iPower_PV - e3dc_config.einspeiselimit*1000 + fSavedtotal;
if (fPower_WB>0)
if ((fPower_WB-fPower_Grid+iPower_Bat)>e3dc_config.einspeiselimit*1000)
fSavedWB = fSavedWB+fPower_WB-fPower_Grid+iPower_Bat-e3dc_config.einspeiselimit*1000;
}
if (((fBatt_SOC > e3dc_config.ladeschwelle)&&(t<tLadezeitende))||(fBatt_SOC > e3dc_config.ladeende))
{
if (iPower<iFc)
{ iPower = iFc;
if ((iPower>0)&&(iPower > fAvBatterie900)) iPower = iPower + pow((iPower-fAvBatterie900),2)/20;
// Nur wenn positive Werte angefordert werden, wird dynamisiert
if (iPower > e3dc_config.maximumLadeleistung) iPower = e3dc_config.maximumLadeleistung;
}
} else
// if (fBatt_SOC < cLadeende) iPower = 3000;
// else iPower = 0;
iPower = e3dc_config.maximumLadeleistung;
if (e3dc_config.wallbox&&(bWBStart||bWBConnect)&&bWBStopped&&(e3dc_config.wbmode>1)&&(e3dc_config.ladeende>fBatt_SOC)&&
((tE3DC-tWBtime)<7200)&&((tE3DC-tWBtime)>10))
// Wenn Wallbox vorhanden und das letzte Laden liegt nicht länger als 900sec zurück
// und wenn die Wallbox gestoppt wurde, dann wird für bis zu 2h weitergeladen
// oder bis der SoC ladeende2 erreicht hat
iPower = e3dc_config.maximumLadeleistung; // mit voller Leistung E3DC Speicher laden
// if (((abs( int(iPower - iPower_Bat)) > 30)||(t%3600==0))&&(iLMStatus == 1))
// if (((abs( int(iPower - iBattLoad)) > 30)||(abs(t-tE3DC_alt)>3600*3))&&(iLMStatus == 1))
if (iLMStatus == 1)
{
{
if (iBattLoad > (iPower_Bat-iDiffLadeleistung))
iDiffLadeleistung = iBattLoad-iPower_Bat+iDiffLadeleistung;
if ((iDiffLadeleistung < 0 )||(abs(iBattLoad)<=100)) iDiffLadeleistung = 0;
if (iDiffLadeleistung > 100 )iDiffLadeleistung = 100; //Maximal 100W vorhalten
if (abs(iPower+iDiffLadeleistung) > e3dc_config.maximumLadeleistung) iDiffLadeleistung = 0;
/* if (iLMStatus == 1) {
iBattLoad = iPower;
tE3DC_alt = t;
ControlLoadData2(frameBuffer,(iBattLoad+iDiffLadeleistung));
iLMStatus = 7;
}
*/
// Steuerung direkt über vorgabe der Batterieladeleistung
// -iPower_Bat + int32_t(fPower_Grid)
if (iLMStatus == 1) {
// Es wird nur Morgens bis zum Winterminimum auf ladeende entladen;
// Danach wird nur bis auf ladeende2 entladen.
if ((iPower < 0)&&((t>e3dc_config.winterminimum*3600)&&(fBatt_SOC<e3dc_config.ladeende2)))
iPower = 0;
// Wenn der SoC > >e3dc_config.ladeende2 wird mit der Speicher max verfügbaren Leistung entladen
// if ((iPower < 0)&&((t>tLadezeitende1)&&(fBatt_SOC>e3dc_config.ladeende2)))
// iPower = e3dc_config.maximumLadeleistung*-1;
iBattLoad = iPower;
tE3DC_alt = t;
{
if ((iPower<e3dc_config.maximumLadeleistung)&&(iPower > (iPower_Bat - int32_t(fPower_Grid))))
// die angeforderte Ladeleistung liegt über der verfügbaren Ladeleistung
{if ((fPower_Grid > 100)&&(iE3DC_Req_Load_alt<(e3dc_config.maximumLadeleistung-1)))
// es liegt Netzbezug vor und System war nicht im Freilauf
{iPower = iPower_Bat - int32_t(fPower_Grid);
// Einspeichern begrenzen oder Ausspeichern anfordern, begrenzt auf e3dc_config.maximumLadeleistung
if (iPower < e3dc_config.maximumLadeleistung*-1)
iPower = e3dc_config.maximumLadeleistung*-1;
}
else
iPower = e3dc_config.maximumLadeleistung;}
// Wenn die angeforderte Leistung großer ist als die vorhandene Leistung
// wird auf Automatik umgeschaltet, d.h. Anforderung Maximalleistung;
// if (iPower >0)
// ControlLoadData(frameBuffer,(iPower+iDiffLadeleistung),3);
// Es wird nur die Variable mit dem Sollwert gefüllt
// die Variable wird im Mainloop überprüft und im E3DC gesetzt
// wenn iLMStatus einen negativen Wert hat
if (iPower > e3dc_config.maximumLadeleistung)
iE3DC_Req_Load = e3dc_config.maximumLadeleistung-1; else
iE3DC_Req_Load = iPower+iDiffLadeleistung;
if (iE3DC_Req_Load >e3dc_config.maximumLadeleistung)
iE3DC_Req_Load = e3dc_config.maximumLadeleistung;
if (iPower_PV>0) // Nur wenn die Sonne scheint
{
static int iLastReq;
if (((iE3DC_Req_Load_alt) >= (e3dc_config.maximumLadeleistung-1))&&(iE3DC_Req_Load>=(e3dc_config.maximumLadeleistung-1)))
// Wenn der aktuelle Wert >= e3dc_config.maximumLadeleistung-1 ist
// und der zuletzt angeforderte Werte auch >= e3dc_config.maximumLadeleistung-1
// war, bleibt der Freilauf erhalten
{ iLMStatus = 3;
if (iLastReq>0)
{sprintf(Log,"CTL %s %0.02f %i %i %0.02f",strtok(asctime(ts),"\n"),fBatt_SOC, iE3DC_Req_Load, iPower_Bat, fPower_Grid);
WriteLog();
iLastReq--;}
}
else
{
// testweise kein Freilauf
if (iE3DC_Req_Load == e3dc_config.maximumLadeleistung)
{iLMStatus = 3;
iE3DC_Req_Load_alt = iE3DC_Req_Load;
}else
iLMStatus = -6;
iLastReq = 6;
sprintf(Log,"CTL %s %0.02f %i %i %0.02f",strtok(asctime(ts),"\n"),fBatt_SOC, iE3DC_Req_Load, iPower_Bat, fPower_Grid);
WriteLog();}
} else
iLMStatus = 11;
}
/* else if (fPower_Grid>50){
// Zurück in den Automatikmodus
ControlLoadData(frameBuffer,0,0);
iLMStatus = 7;}
*/
}
}
}
// peakshaving erforderlich?
if ((e3dc_config.peakshave != 0)&&(iLMStatus==2))
{
if ((fPower_Grid-iPower_Bat) != e3dc_config.peakshave)
{
iDiffLadeleistung2 = -iPower_Bat-iE3DC_Req_Load;
if (iDiffLadeleistung2 > 100) iDiffLadeleistung2 = 100;
if (iDiffLadeleistung2 < 0) iDiffLadeleistung2 = 0;
// iBattLoad = e3dc_config.peakshave-iPowerHome;
// iE3DC_Req_Load = e3dc_config.peakshave-iPowerHome+iDiffLadeleistung2;
// Es soll die Netzeinspeisung auf einen Mindestwert gesetzt werden
// iBattLoad = e3dc_config.peakshave-fPower_Grid+iPower_Bat;
// wenn iPower_Bat < 0 es wird ausgespeichert oder fPower_Grid > e3dc_config.peakshave
if ((iPower_Bat < 0)||(e3dc_config.peakshave<(fPower_Grid)*.9))
iE3DC_Req_Load = e3dc_config.peakshave-fPower_Grid+iPower_Bat+iDiffLadeleistung2;
else
iE3DC_Req_Load = 0;
// iE3DC_Req_Load = e3dc_config.peakshave-iPowerHome;
if ((iE3DC_Req_Load) > e3dc_config.maximumLadeleistung)
iE3DC_Req_Load = e3dc_config.maximumLadeleistung;
else if (abs(iE3DC_Req_Load) > e3dc_config.maximumLadeleistung)
iE3DC_Req_Load = e3dc_config.maximumLadeleistung*-1;
// Keine Laden aus dem Netz zulassen, nur von der PV
if (iE3DC_Req_Load > iPower_PV) iE3DC_Req_Load = iPower_PV;
// if (iE3DC_Req_Load > iPower_Bat)
if (abs(iE3DC_Req_Load) > 100)
iLMStatus = -7;
sprintf(Log,"CPS %s %0.02f %i %i% 0.02f 0.02f", strtok(asctime(ts),"\n"),fBatt_SOC, iE3DC_Req_Load, iPower_Bat, fPower_Grid, fAvPower_Grid600);
WriteLog();
}
};
if (iLMStatus>1) iLMStatus--;
printf("AVB %0.1f %0.1f ",fAvBatterie,fAvBatterie900);
printf("DisC %i ",iDischarge);
printf("BattL %i ",iBattLoad);
printf("iLMSt %i ",iLMStatus);
printf("Rsv %0.1f%%\n",fht);
printf("U %0.0004fkWh td %0.0004fkWh", (fSavedtotal/3600000),(fSavedtoday/3600000));
if (e3dc_config.wallbox)
printf(" WB %0.0004fkWh",(fSavedWB/3600000));
printf(" yd %0.0004fkWh\n",(fSavedyesderday/3600000));
char buffer [500];
// sprintf(buffer,"echo $PATH");
// system(buffer);
if (e3dc_config.openWB)
{
// sprintf(buffer,"mosquitto_pub -r -h raspberrypi -t openWB/set/evu/VPhase1 -m %0.1f",float(223.4));
// system(buffer);
sprintf(buffer,"openWB/set/evu/W -m %0i",int(fPower_Grid));
MQTTsend(buffer);
sprintf(buffer,"openWB/set/pv/W -m %0i",iPower_PV*-1);
MQTTsend(buffer);
sprintf(buffer,"echo %0.1f > /var/www/html/openWB/ramdisk/llaktuell",fPower_WB);
// system(buffer);
sprintf(buffer,"openWB/set/Housebattery/W -m %0i",iPower_Bat);
MQTTsend(buffer);
sprintf(buffer,"openWB/set/Housebattery/%%Soc -m %0i",int(fBatt_SOC));
MQTTsend(buffer);
sprintf(buffer,"echo %i > /var/www/html/openWB/ramdisk/hausleistung",iPowerHome);
// system(buffer);
}
return 0;
}
int WBProcess(SRscpFrameBuffer * frameBuffer) {
/* Steuerung der Wallbox
*/
const int cMinimumladestand = 15;
const int iMaxcurrent=31;
static float_t iDyLadeende;
static uint8_t WBChar_alt = 0;
static int32_t iWBMinimumPower,iAvalPower,iAvalPowerCount,idynPower; // MinimumPower bei 6A
static int iLadeleistung[27][4]; //27*4 Zellen
static bool bWBOn, bWBOff = false; // Wallbox eingeschaltet
static int32_t iMaxBattLade; // dynnamische maximale Ladeleistung der Batterie, abhängig vom SoC
/*
Die Ladeleistung der Wallbox wird nach verfügbaren PV-Überschussleistung gesteuert
Der WBModus gibt die Priorität der Wallbox gegenüber dem E3DC Speicher vor.
Der E3DC Speicher hat Priorität
Der angeforderte Ladeleistung des E3DC wird durch iBattLoad angezeigt.
der lineare Ladebedarf wird durch iMinLoad ermittelt
die berechnete dynamische Ladeleistung wird in iFc ermittelt.
ffAvBatterie und fAvBatterie900 zeigt die durchschnittliche Ladeleistung
der letzen 120 bzw. 900 Sekunden an.
WBModus = 0 KEINE STEUERUNG
WBModus = 1 NUR Überschuss > einspeiselimit
Der E3DC Speicher hat Priorität
Die Wallbox kann nur die Überschussleistung zur Verfügung gestellt werden
und speist sich aus der verfügbaren fPower_Grid > einspeiselimit-iWBMinimumPower.
WBModus = 2 NUR Überschuss
Der E3DC Speicher hat Priorität
Die Wallbox kann nur die Überschussleistung zur Verfügung gestellt werden
und speist sich aus der verfügbaren fPower_Grid > iWBMinimumPower.
Entspricht weitgehend dem jetzigen Verfahren.
der 1/4h Wert = fAvPower_Grid900 wird so geführt, dass er dem kleineren Wert von
MinLoad und iFC entspricht. MinLoad und iFC sollten im unteren Bereich
des Ladekorridors (obererLadekorridor) geführt werden. Mit dem Ziel von MinLoad = iFc.
Bei SoC >= ladeende2 wird fAvPower_Grid900 so geführt, dass diese um Null pendelt.
Bei gridüberschuss von 100/200 oder iPower_Bat > 700 die Ladeleistung angeboben,
Bei iPower_Bat < -700 oder fAvPower_Grid900 < 100 wird das Laden reduziert.
Das Laden wird beendet bei fAvPower_Grid900 < -200.
Das Laden wird neu gestartet bei fAvPower_Grid900 > 100 +
verfügbare PV-Leistung (iPower_Bat-fPower_Grid)
und verfügbare Speicherleistung (e3dc_config.maximumLadeleistung -700)
großer als die iWBMinimumPower ist.
WBModus = 3
Der E3DC Speicher hat immer noch Priorität, untersützt aber die Wallbox stärker
bei temporäre Ertragsschwankungen, der E3DC-Speicher wird so geführt,
das immer die maximale Ladeleistung aufgenommen werden kann.
Damit wird aber auch hingenommen, dass unter Umständen am Abend
der Speicher nicht voll wird.
der 1/4h Wert = fAvPower_Grid900 wird so geführt, dass er dem kleineren Wert von
MinLoad und iFC nahe kommt dabei sollte iBattload immer dem
e3dc_config.maximumLadeleistung entsprechen. MinLoad und iFC < WBminlade
Zielparameter: fAvPower_Grid900 = 2*Minload - WBminlade und
fAvPower_Grid = 2*iFc - e3dc_config.maximumLadeleistung
Dies wird wie folgt erreicht:
Die Ladeleistung wird angehoben, wenn iBattload unter e3dc_config.maximumLadeleistung
fällt oder fAvPower_Grid > 2*iFc - e3dc_config.maximumLadeleistung steigt
dabei wird auch in Kauf genommen, dass die Batterie zeitweise entladen wird.
WBModus = 4
Hier bekommt die Wallbox die Priorität, der Speicher wird bis auf Ladeschwelle entladen, aber der Bezug aus dem Netz wird vermieden.
Die Laden wird gestartet sobald verfügbare PV-Leistung (iPower_Bat-fPower_Grid)
und verfügbare Speicherleistung (e3dc_config.maximumLadeleistung -700)
großer als die iWBMinimumPower ist.
Das Laden wird beendet bei Gridbezug > 100/200 und bei der Unterschreitung der Ladeschwelle.
Unterstützung Teslatar
Teslatar ist ein eigenständiges Python Program, dass auf dem Raspberry Pi läuft.
Im Zusammenhang damit gibt es auch noch ein Problem mit der Wallbox, da Sie einfach
auf den Zustand "gestoppt" springt, was ein späteres gesteuertes Laden verhindert.
Deswegen wird zwischen 21:00 GMT und 5:00 GMT die Ladesperre der Wallbox überwacht
Die Einstellung der Ladestromstärke auf 30A löst die Überwachung erst aus.
*/
if (iWBStatus == 0) {
iMaxBattLade = e3dc_config.maximumLadeleistung*.9;
memcpy(WBchar6,"\x00\x06\x00\x00\x00\x00",6);
WBchar6[1]=WBchar[2];
if ((WBchar[2]==32)||(WBchar[2]==30))
bWBmaxLadestrom = true; else
bWBmaxLadestrom = false;
if (WBchar[2] > 4)
iWBStatus = 5;
else {