-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathRscpExampleMain.cpp
executable file
·6970 lines (6216 loc) · 299 KB
/
RscpExampleMain.cpp
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 <array>
#include <cctype>
#include "RscpProtocol.h"
#include "RscpTags.h"
#include "SocketConnection.h"
#include "AES.h"
#include <time.h>
#include "E3DC_CONF.h"
#include "SunriseCalc.hpp"
#include "awattar.hpp"
#include "avl_array.h"
//#include "MQTTClient.h"
#include "cJSON.h"
#include <string>
#include <iostream>
#include <fcntl.h>
// for convenience test4
// 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 WBToggel;
static uint8_t WBchar[8];
static uint8_t WBchar6[6]; // Steuerstring zur Wallbox
static uint8_t WBcharALG[8]; // Steuerstring zur Wallbox
static uint8_t WBcharPara2[8]; // 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,fVoltage,fCurrent;
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 float fMaxPower_WB; // höchste Ladeleistung seit das Fahrzeug verbunden ist
static float fPVtoday=0; // Erzeugung heute
static float fPVnextday=0; // Erzeugung heute
static float fPVcharge=0; // Zum Speicherladen verfügbarer Ertrag
static float fPVdirect=0; // Direktverbrauch
static float fPVSoll=0; // Mindestertrag zur Abdeckung Tagesverbrauch und Speicherladung bis ladeende2
static float fDCDC = 0; // Strommenge mit rechnen
static int32_t iPower_PV, iPower_PV_E3DC;
static int32_t iAvalPower = 0;
static int32_t iMaxBattLade; // dynnamische maximale Ladeleistung der Batterie, abhängig vom SoC
static int32_t iPower_Bat;
static int32_t iPower_WP = 0; // Leistungsaufnahme WP
static int64_t itotal_WP = -1; // Zählestand WP
static float fPower_Bat;
static float fPower_Ext[7];
static int ireq_Heistab; // verfügbare Leistung
static uint8_t iPhases_WB;
static uint8_t iCyc_WB;
static int32_t iBattLoad;
static int iPowerBalance = 0;
static int iPowerHome = 0;
static uint8_t iNotstrom = 0;
static float fNotstromreserve = 0; // aus dem System übernommene Notstromreserve für AWReserve berücksichtigen
static time_t tE3DC, tWBtime;
static int hh,mm,ss;
static int32_t iFc, iMinLade,iMinLade2; // Mindestladeladeleistung des E3DC Speichers
static float_t fL1V=230,fL2V=230,fL3V=230;
static int iDischarge = -1;
static bool bDischarge = true,bDischargeDone; // Wenn false, wird das Entladen blockiert, unabhängig von dem vom Portal gesetzen wert
char cWBALG;
static bool bWBLademodus; // Lademodus der Wallbox; z.B. Sonnenmodus
static bool bWBChanged; // Lademodus der Wallbox; wurde extern geändertz.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,bWBmaxLadestromSave; // Ladestrom der Wallbox per App eingestellt.; 32=ON 31 = OFF
static int iWBSoll,iWBIst; // Soll = angeforderter Ladestrom, Ist = aktueller Ladestrom
static int32_t iE3DC_Req_Load,iE3DC_Req_Load_alt,iE3DC_Req_LoadMode=0; // Leistung, mit der der E3DC-Seicher geladen oder entladen werden soll
float_t WWTemp; // Warmwassertemperatur
static float fht; // Reserve aus ht berechnet
// in der Simulation wird der höchste Peakwert hochgerechnet
//
int forecastpeaktime; //
float forecastpeak; //
float fpeakshaveminsoc; // Wenn peakshave dann wird hier der MindestSoc im Tagesverlauf berechnet
// am Morgen, d.h. sonnenaufgang + zeitversatz aus unload mit ziel 50% bei Sonnenuntergang - Zeitversatz unload. Wird der wert unterschritten, wird das entladen gestoppt, ist er um 10% unterschritten wird aus dem Netz geladen, soweit der Netzbezug unter peakshave liegt.
float fpeakshaveendsoc;
// Ziel-Soc bis zu dieser Grenze darf entladen werden
// Bei gerigem Ertrag wird dieser verdoppelt = n x Peakshavesoc
// hohen Ertrag wird dieser bis auf 5% herabgesetzt d.h. halbiert
static u_int8_t btasmota_ch1 = 8; // Anforderung LWWP 0 = aus(EVU), 1 = ein; 2 = Preis
// 4 = PVon 8 = standby 16 = dynamischer Wärmepreis berechnet
static u_int8_t btasmota_ch2 = 0; // Anforderung LWWP/PV-Anhebung 1=ww, 2=preis, 4=überschuss
#define sizeweekhour 24*7*4
int weekhour = sizeweekhour+1;
int dayhour = weekhour+1;
static u_int32_t iWeekhour[sizeweekhour+10]; // Wochenstatistik
static u_int32_t iWeekhourWP[sizeweekhour+10]; // Wochenstatistik Wärmepumpe
static u_int32_t iDayStat[25*4*2+1]; // Tagesertragstatisik SOLL/IST Vergleich
// in den ersten 96 15min Intervallen steht der prog. Ertrag Durchschnittswerte
// in den zweiten 96 15min Intervallen steht der tatsächliche Ertrag Durchschnittswerte
// index 200 heutiger Ertrag 15min
// index 199 heutige Prognose kumuliert
// Index 198 heutiger Ertrag kumuliert
static int DayStat = sizeof(iDayStat)/sizeof(u_int32_t)-1;
static int32_t iGridStat[31*24*4]; //15min Gridbezug Monat
static char fnameGrid[100];
static int Gridstat;
SunriseCalc * location;
std::vector<ch_s> ch; //charge hour
// std::vector<watt_s> w1;
avl_array<uint16_t, uint16_t, std::uint16_t, 10, true> oek; // array mit 10 Einträgen
e3dc_config_t e3dc_config;
float fLadeende = e3dc_config.ladeende;
float fLadeende2 = e3dc_config.ladeende2;
float fLadeende3 = e3dc_config.unload;
FILE * pFile;
char Log[3000];
int WriteLog()
{
static time_t t,t_alt = 0;
int day,hour;
char fname[256];
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);
snprintf(fname,sizeof(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 WriteSoC()
{
char fname[256];
sprintf(fname,"soc.txt");
FILE *fp;
fp = fopen(fname,"a"); // altes logfile löschen
if(!fp)
fp = fopen(fname, "w");
if(fp)
{
fprintf(fp,"%s\n",Log);
fclose(fp);
}
return(0);
}
int MQTTsend(char host[20],char buffer[127])
{
char cbuf[128];
if (strcmp(host,"0.0.0.0")!=0) //gültige hostadresse
{
sprintf(cbuf, "mosquitto_pub -r -h %s -t %s", host,buffer);
int ret = system(cbuf);
return ret;
} else
return(-1);
}
/*
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;
if (iWBStatus<12)
iWBStatus=12;
// 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,(uint8_t)e3dc_config.wallbox);
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);
iWBSoll = WBchar6[1]; // angeforderte Ladestromstärke;
WBToggel = WBchar6[4];
printf(" RQ %02X %02i %02X ",WBchar6[0],WBchar6[1],WBchar6[4]);
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;
}
int createRequestWBData2(SRscpFrameBuffer * frameBuffer) {
RscpProtocol protocol;
SRscpValue rootValue;
if (iWBStatus<12)
iWBStatus=12;
// 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,(uint8_t)e3dc_config.wallbox);
protocol.createContainerValue(&WB2Container, TAG_WB_REQ_SET_PARAM_1);
protocol.appendValue(&WB2Container, TAG_WB_EXTERN_DATA_LEN,8);
protocol.appendValue(&WB2Container, TAG_WB_EXTERN_DATA,WBchar,8);
iWBSoll = WBchar[2]; // angeforderte Ladestromstärke;
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 = -1;
static float fBatt_SOC_alt;
static float fSavedtoday, fSavedyesderday,fSavedtotal,fSavedWB; // Überschussleistung
static int32_t iDiffLadeleistung, iDiffLadeleistung2;
static time_t tLadezeit_alt,tLadezeitende_alt,tE3DC_alt;
static time_t t,t_alt;
static time_t tm_CONF_dt;
static bool bCheckConfig;
struct tm * ptm;
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) {
FILE *sfp;
char fbuf[255];
bool bf;
sprintf(fbuf,"%s.check",e3dc_config.conffile);
sfp = fopen(fbuf, "w");
stat(e3dc_config.conffile,&stats);
tm_CONF_dt = *(&stats.st_mtime);
char var[128], value[128], line[256];
strcpy(e3dc_config.server_ip, "0.0.0.0");
strcpy(e3dc_config.heizstab_ip, "0.0.0.0");
e3dc_config.heizstab_port = 502;
strcpy(e3dc_config.heizung_ip, "0.0.0.0");
strcpy(e3dc_config.mqtt_ip, "0.0.0.0");
strcpy(e3dc_config.mqtt2_ip, "0.0.0.0");
strcpy(e3dc_config.mqtt3_ip, "0.0.0.0");
strcpy(e3dc_config.mqtt4_ip, "0.0.0.0");
strcpy(e3dc_config.WB_ip, "0.0.0.0");
strcpy(e3dc_config.openWB_ip, "0.0.0.0");
strcpy(e3dc_config.shelly0V10V_ip, "0.0.0.0");
strcpy(e3dc_config.shellyEM_ip, "0.0.0.0");
memset(e3dc_config.openweathermap,0,sizeof(e3dc_config.openweathermap));
memset(e3dc_config.analyse,0,sizeof(e3dc_config.analyse));
e3dc_config.wrsteuerung = 1; // 0 = aus, 1= aktiv, 2=debug ausgaben
e3dc_config.stop = 0; // 1 = Programm beenden
e3dc_config.test = 0; // 1 = Programm beenden
e3dc_config.wallbox = -1;
e3dc_config.openWB = false;
e3dc_config.openmeteo = false;
e3dc_config.shelly0V10V = false;
e3dc_config.shelly0V10Vmin = 12;
e3dc_config.shelly0V10Vmax = 47;
e3dc_config.tasmota = false;
e3dc_config.statistik = true;
e3dc_config.WP = false;
e3dc_config.WPWolf = false;
e3dc_config.WPSperre = false;
e3dc_config.ext1 = false;
e3dc_config.ext2 = false;
e3dc_config.ext3 = false;
e3dc_config.ext4 = false;
e3dc_config.ext7 = false;
sprintf(e3dc_config.logfile,"logfile");
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.powerfaktor = POWERFAKTOR;
e3dc_config.wrleistung = WRLEISTUNG;
e3dc_config.speichergroesse = SPEICHERGROESSE;
e3dc_config.winterminimum = WINTERMINIMUM;
e3dc_config.RB = -1;
e3dc_config.sommermaximum = SOMMERMAXIMUM;
e3dc_config.RE = -1;
e3dc_config.sommerladeende = SOMMERLADEENDE;
e3dc_config.LE = -1;
e3dc_config.einspeiselimit = EINSPEISELIMIT;
e3dc_config.ladeschwelle = LADESCHWELLE;
e3dc_config.ladeende = LADEENDE;
e3dc_config.ladeende2 = LADEENDE2;
e3dc_config.ladeende2rampe = 1;
e3dc_config.wbmaxladestrom = WBMAXLADESTROM;
e3dc_config.wbminladestrom = 6;
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.peakshavesoc = 0;
e3dc_config.peakshaveuppersoc = 50;
e3dc_config.peakshavepvcharge = -1;
e3dc_config.wbtest = 0; // debugausgaben für die WB einschalten
e3dc_config.wbmode = 4;
e3dc_config.wbminlade = 1000;
e3dc_config.wbminSoC = 10;
e3dc_config.wbhour = -1;
e3dc_config.wbvon = -1;
e3dc_config.wbbis = -1;
// strcpy(e3dc_config.e3dcwallboxtxt,"/var/www/html/e3dc.wallbox.txt");
strcpy(e3dc_config.e3dcwallboxtxt,"e3dc.wallbox.txt");
e3dc_config.hoehe = 50;
e3dc_config.laenge = 10;
e3dc_config.aWATTar = 0;
e3dc_config.AWLand = 1; // 1 = DE 2 = AT
e3dc_config.AWMWSt = -1; // 19 = DE 20 = AT
e3dc_config.AWNebenkosten = -1;
e3dc_config.Avhourly = 10; // geschätzter stündlicher Verbrauch in %
e3dc_config.AWDiff = -1; // Differenzsockel in €/MWh
e3dc_config.AWAufschlag = 1.2;
e3dc_config.AWSimulation = 0;
e3dc_config.AWtest = 0;
e3dc_config.AWReserve = 0;
e3dc_config.BWWP_Power = 0;
e3dc_config.BWWP_port = 6722;
e3dc_config.BWWPein = 0;
e3dc_config.BWWPaus = 0;
e3dc_config.BWWPon = -1;
e3dc_config.BWWPoff = -1;
e3dc_config.BWWPSupport = -1;
e3dc_config.BWWPTasmotaDauer = 0;
memset(e3dc_config.BWWPTasmota,0,sizeof(e3dc_config.BWWPTasmota));
e3dc_config.soc = -1;
e3dc_config.ForcecastSoc = 2; // Faktor zur Berechnung des Ladebedarf
e3dc_config.ForcecastConsumption = 1; // Faktor zur Berechnung des Verbrauchsbedarf
e3dc_config.ForcecastReserve = 1; // Hinzurechnung Reserve in % zum Strombedarf
memset(e3dc_config.Forecast[0], 0, sizeof(e3dc_config.Forecast[0]));
memset(e3dc_config.Forecast[1], 0, sizeof(e3dc_config.Forecast[1]));
memset(e3dc_config.Forecast[2], 0, sizeof(e3dc_config.Forecast[2]));
memset(e3dc_config.Forecast[3], 0, sizeof(e3dc_config.Forecast[3]));
e3dc_config.WPHeizlast = -1;
e3dc_config.WPLeistung = -1;
e3dc_config.WPHeizgrenze = -1;
e3dc_config.WPmin = -1;
e3dc_config.WPmax = -1;
e3dc_config.WPPVon = -1;
e3dc_config.WPPVoff = -100;
e3dc_config.WPHK1 = 25;
e3dc_config.WPHK1max = 29;
e3dc_config.WPHK2on = -1;
e3dc_config.WPHK2off = -1;
e3dc_config.WPEHZ = 0;
e3dc_config.WPZWE = -99;
e3dc_config.WPZWEPVon = -1;
e3dc_config.WPOffset = 2;
e3dc_config.MQTTavl = -1;
e3dc_config.DCDC = true;
bf = true;
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(sscanf(line, "%[^ \t=]%*[\t ]=%*[\t ]%[^ \n]", var, value) == 2) {
for (int i = 0; i < strlen(var); i++)
var[i] = tolower(var[i]);
if(strcmp(var, "server_ip") == 0)
strcpy(e3dc_config.server_ip, value);
else if(strcmp(var, "bwwp_ip") == 0)
strcpy(e3dc_config.BWWP_ip, value);
else if(strcmp(var, "shelly0v10v_ip") == 0)
strcpy(e3dc_config.shelly0V10V_ip, value);
else if(strcmp(var, "shellyem_ip") == 0)
strcpy(e3dc_config.shellyEM_ip, value);
else if(strcmp(var, "heizung_ip") == 0)
strcpy(e3dc_config.heizung_ip, value);
else if(strcmp(var, "heizstab_ip") == 0)
strcpy(e3dc_config.heizstab_ip, value);
else if(strcmp(var, "heizstab_port") == 0)
e3dc_config.heizstab_port = atoi(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, "e3dcwallboxtxt") == 0)
{
strcpy(e3dc_config.e3dcwallboxtxt, value);
strcat(e3dc_config.e3dcwallboxtxt,"e3dc.wallbox.txt");
}
else if(strcmp(var, "openwb_ip") == 0)
strcpy(e3dc_config.openWB_ip, value);
else if(strcmp(var, "mqtt_ip") == 0)
strcpy(e3dc_config.mqtt_ip, value);
else if(strcmp(var, "mqtt2_ip") == 0)
strcpy(e3dc_config.mqtt2_ip, value);
else if(strcmp(var, "mqtt3_ip") == 0)
strcpy(e3dc_config.mqtt3_ip, value);
else if(strcmp(var, "mqtt4_ip") == 0)
strcpy(e3dc_config.mqtt4_ip, value);
else if(strcmp(var, "mqtt4_topic") == 0)
strcpy(e3dc_config.mqtt4_topic, value);
else if(strcmp(var, "wb_ip") == 0)
strcpy(e3dc_config.WB_ip, value);
else if(strcmp(var, "wb_topic") == 0)
strcpy(e3dc_config.WB_topic, value);
else if(strcmp(var, "analyse") == 0)
strcpy(e3dc_config.analyse, value);
else if(strcmp(var, "forecast1") == 0)
strcpy(e3dc_config.Forecast[0], value);
else if(strcmp(var, "forecast2") == 0)
strcpy(e3dc_config.Forecast[1], value);
else if(strcmp(var, "forecast3") == 0)
strcpy(e3dc_config.Forecast[2], value);
else if(strcmp(var, "forecast4") == 0)
strcpy(e3dc_config.Forecast[3], value);
else if(strcmp(var, "forecastsoc") == 0)
e3dc_config.ForcecastSoc = atof(value);
else if(strcmp(var, "forecastconsumption") == 0)
e3dc_config.ForcecastConsumption = atof(value);
else if(strcmp(var, "forecastreserve") == 0)
e3dc_config.ForcecastReserve = atof(value);
else if(strcmp(var, "openweathermap") == 0)
strcpy(e3dc_config.openweathermap, value);
else if(strcmp(var, "bwwptasmota") == 0)
strcpy(e3dc_config.BWWPTasmota, value);
else if(strcmp(var, "bwwptasmotadauer") == 0)
e3dc_config.BWWPTasmotaDauer = atoi(value);
else if(strcmp(var, "wurzelzaehler") == 0)
e3dc_config.wurzelzaehler = atoi(value);
else if(strcmp(var, "wrsteuerung") == 0)
e3dc_config.wrsteuerung = atoi(value);
else if(strcmp(var, "stop") == 0)
e3dc_config.stop = atoi(value);
else if(strcmp(var, "test") == 0)
e3dc_config.test = atoi(value);
else if((strcmp(var, "wallbox") == 0)){
if
(strcmp(value, "true") == 0)
e3dc_config.wallbox = 0;
else
if
(strcmp(value, "false") == 0)
e3dc_config.wallbox = -1;
else
e3dc_config.wallbox = atoi(value);}
else if((strcmp(var, "openwb") == 0)&&
(strcmp(value, "true") == 0))
e3dc_config.openWB = true;
else if((strcmp(var, "openmeteo") == 0)&&
(strcmp(value, "true") == 0))
e3dc_config.openmeteo = true;
else if((strcmp(var, "dcdc") == 0)&&
(strcmp(value, "false") == 0))
e3dc_config.DCDC = false;
else if((strcmp(var, "dcdc") == 0)&&
(strcmp(value, "true") == 0))
e3dc_config.DCDC = true;
else if((strcmp(var, "shelly0v10v") == 0))
{
if (strcmp(value, "false") == 0)
e3dc_config.shelly0V10V = false;
else
if (strcmp(value, "true") == 0)
e3dc_config.shelly0V10V = true;
}
else if((strcmp(var, "tasmota") == 0))
{
if (strcmp(value, "false") == 0)
e3dc_config.tasmota = false;
else
if (strcmp(value, "true") == 0)
e3dc_config.tasmota = true;
}
else if((strcmp(var, "wp") == 0)&&
(strcmp(value, "true") == 0))
e3dc_config.WP = true;
else if((strcmp(var, "wpwolf") == 0)&&
(strcmp(value, "true") == 0))
e3dc_config.WPWolf = true;
else if((strcmp(var, "wpsperre") == 0)&&
(strcmp(value, "true") == 0))
e3dc_config.WPSperre = true;
else if((strcmp(var, "statistik") == 0)&&
(strcmp(value, "true") == 0))
e3dc_config.statistik = 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, "ext4") == 0)&&
(strcmp(value, "true") == 0))
e3dc_config.ext4 = 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, "shelly0v10vmin") == 0)
e3dc_config.shelly0V10Vmin = atoi(value);
else if(strcmp(var, "shelly0v10vmax") == 0)
e3dc_config.shelly0V10Vmax = atoi(value);
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, "powerfaktor") == 0)
e3dc_config.powerfaktor = atof(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, "wpheizlast") == 0)
e3dc_config.WPHeizlast = atof(value);
else if(strcmp(var, "wpheizgrenze") == 0)
e3dc_config.WPHeizgrenze = atof(value);
else if(strcmp(var, "wpleistung") == 0)
e3dc_config.WPLeistung = atof(value);
else if(strcmp(var, "wpmin") == 0)
e3dc_config.WPmin = atof(value);
else if(strcmp(var, "wpmax") == 0)
e3dc_config.WPmax = atof(value);
else if(strcmp(var, "wppvon") == 0)
e3dc_config.WPPVon = atof(value);
else if(strcmp(var, "wppvoff") == 0)
e3dc_config.WPPVoff = atof(value);
else if(strcmp(var, "wphk1") == 0)
e3dc_config.WPHK1 = atof(value);
else if(strcmp(var, "wphk1max") == 0)
e3dc_config.WPHK1max = atof(value);
else if(strcmp(var, "wphk2on") == 0)
e3dc_config.WPHK2on = atof(value);
else if(strcmp(var, "wphk2off") == 0)
e3dc_config.WPHK2off = atof(value);
else if(strcmp(var, "wpehz") == 0)
e3dc_config.WPEHZ = atof(value);
else if(strcmp(var, "wpzwe") == 0)
e3dc_config.WPZWE = atof(value);
else if(strcmp(var, "wpzwepvon") == 0)
e3dc_config.WPZWEPVon = atof(value);
else if(strcmp(var, "wpoffset") == 0)
e3dc_config.WPOffset = atof(value);
else if(strcmp(var, "bwwpein") == 0)
e3dc_config.BWWPein = atof(value);
else if(strcmp(var, "bwwpaus") == 0)
e3dc_config.BWWPaus = atof(value);
else if(strcmp(var, "bwwpon") == 0)
e3dc_config.BWWPon = atof(value);
else if(strcmp(var, "bwwpoff") == 0)
e3dc_config.BWWPoff = atof(value);
else if(strcmp(var, "bwwpsupport") == 0)
e3dc_config.BWWPSupport = atof(value);
else if(strcmp(var, "rb") == 0)
e3dc_config.RB = atof(value);
else if(strcmp(var, "sommermaximum") == 0)
e3dc_config.sommermaximum = atof(value);
else if(strcmp(var, "re") == 0)
e3dc_config.RE = atof(value);
else if(strcmp(var, "sommerladeende") == 0)
e3dc_config.sommerladeende = atof(value);
else if(strcmp(var, "le") == 0)
e3dc_config.LE = 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, "ladeende2rampe") == 0)
e3dc_config.ladeende2rampe = atof(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, "wbtest") == 0)
e3dc_config.wbtest = 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, "wbmaxladestrom") == 0)
e3dc_config.wbmaxladestrom = atoi(value);
else if(strcmp(var, "wbminladestrom") == 0)
e3dc_config.wbminladestrom = atoi(value);
else if(strcmp(var, "wbhour") == 0)
e3dc_config.wbhour = atoi(value);
else if(strcmp(var, "wbvon") == 0)
e3dc_config.wbvon = atoi(value);
else if(strcmp(var, "wbbis") == 0)
e3dc_config.wbbis = atoi(value);
else if(strcmp(var, "wbminsoc") == 0)
e3dc_config.wbminSoC = atof(value);
else if(strcmp(var, "hoehe") == 0)
e3dc_config.hoehe = atof(value);
else if(strcmp(var, "laenge") == 0)
e3dc_config.laenge = atof(value);
else if(strcmp(var, "awsimulation") == 0)
e3dc_config.AWSimulation = atoi(value); // max länge eines Wintertages
else if(strcmp(var, "peakshave") == 0)
e3dc_config.peakshave = atoi(value); // in Watt
else if(strcmp(var, "peakshavesoc") == 0)
e3dc_config.peakshavesoc = atof(value); // in Watt
else if(strcmp(var, "peakshaveuppersoc") == 0)
e3dc_config.peakshaveuppersoc = atoi(value); // in Watt
else if(strcmp(var, "peakshavepvcharge") == 0)
e3dc_config.peakshavepvcharge = atoi(value); // in Watt
else if(strcmp(var, "soc") == 0)
e3dc_config.soc = 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;
else if(strcmp(var, "awattar") == 0)
{if (strcmp(value, "true") == 0)
e3dc_config.aWATTar = 1;
else
e3dc_config.aWATTar = atoi(value);}
else if((strcmp(var, "awland") == 0)&&
(strcmp(value, "at") == 0)) // AT = 2
e3dc_config.AWLand = 2;
else if((strcmp(var, "awland") == 0)&&
(strcmp(value, "AT") == 0)) // AT = 2
e3dc_config.AWLand = 2;
else if((strcmp(var, "awland") == 0)&&
(strcmp(value, "de") == 0)) // DE = 1
e3dc_config.AWLand = 1;
else if(strcmp(var, "avhourly") == 0)
e3dc_config.Avhourly = atof(value); // % der SoC
else if(strcmp(var, "awdiff") == 0)
e3dc_config.AWDiff = atof(value)*10; // % der SoC
else if(strcmp(var, "awaufschlag") == 0)
e3dc_config.AWAufschlag = 1 + atof(value)/100;
else if(strcmp(var, "awnebenkosten") == 0)
e3dc_config.AWNebenkosten = atof(value);
else if(strcmp(var, "awmwst") == 0)
e3dc_config.AWMWSt = atof(value);
else if(strcmp(var, "awreserve") == 0)
e3dc_config.AWReserve = atof(value);
else if(strcmp(var, "mqtt/aval") == 0)
e3dc_config.MQTTavl = atoi(value);
else if(strcmp(var, "awtest") == 0)
e3dc_config.AWtest = atoi(value); // Testmodus 0 = Idel, 1 = Entlade, 2 = Netzladen mit Begrenzung 3 = Netzladen ohne Begrenzung
else
bf = false;
if (bf)
fprintf(sfp,"%s = %s\n",var,value);
else
bf = 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);
fclose(sfp);
/* if (e3dc_config.RB < 0)
e3dc_config.RB = (e3dc_config.winterminimum-(e3dc_config.sommermaximum-e3dc_config.winterminimum)/2);
if (e3dc_config.RE < 0)
(e3dc_config.winterminimum+(e3dc_config.sommermaximum-e3dc_config.winterminimum)/2);
if (e3dc_config.LE < 0)
(e3dc_config.LE = e3dc_config.sommerladeende);
*/
if (e3dc_config.AWMWSt<0)
{
if (e3dc_config.AWLand <= 1)
e3dc_config.AWMWSt = 19;
else
e3dc_config.AWMWSt = 20;
}
if ((e3dc_config.AWNebenkosten > 0)&&(e3dc_config.AWDiff<0))
e3dc_config.AWDiff = (e3dc_config.AWNebenkosten/(e3dc_config.AWMWSt+100) * (e3dc_config.AWAufschlag-1)*1000);
if (e3dc_config.powerfaktor < 0)
e3dc_config.powerfaktor = (float(e3dc_config.maximumLadeleistung)/(e3dc_config.obererLadekorridor-e3dc_config.untererLadekorridor));
if (e3dc_config.aWATTar) {
// wenn awattar dann hton/htoff deaktivieren
e3dc_config.htoff = e3dc_config.hton+1;
e3dc_config.htsat = false;
e3dc_config.htsun = false; }
}
ptm = gmtime(&t);
// Berechne Sonnenaufgang-/untergang
location = new SunriseCalc(e3dc_config.hoehe, e3dc_config.laenge, 0);
location->date(1900+ptm->tm_year, 12,21, 0); // Wintersonnewende
sunriseWSW = location->sunrise();
location->date(1900+ptm->tm_year, ptm->tm_mon+1,ptm->tm_mday, 0);
sunriseAt = location->sunrise();
sunsetAt = location->sunset();
if ((!fp)||not (fpread)) printf("Configurationsdatei %s nicht gefunden",CONF_FILE);
return fpread;
}
int wpvl,wphl,wppw,wpswk,wpkst,wpkt,wpkt2,wpzl,wpalv,wpal,wpeevk,wpbhg; //heizleistung und stromaufnahme wärmepumpe
time_t tLadezeitende,tLadezeitende1,tLadezeitende2,tLadezeitende3; // dynamische Ladezeitberechnung aus dem Cosinus des lfd Tages. 23 Dez = Minimum, 23 Juni = Maximum
static int isocket;
long iLength,myiLength;
int iRegister;
const char * relay_ip;
//const char * cmd;
static std::vector<uint8_t> send;
static std::vector<uint8_t> receive;
int iPort = e3dc_config.BWWP_port;
typedef struct {
uint16_t Tid; //transaktion_ID
uint16_t Pid; //Protokoll_ID
uint16_t Mlen; //Msglength
uint8_t Dev; //Geräte_ID
uint8_t Fcd; //Function Code
uint16_t Reg; //Register
uint16_t Count; //Number Register
uint16_t Value; //Wert
char data[195];
}Modbus_send;
typedef struct {
uint16_t Tid; //transaktion_ID
uint16_t Pid; //Protokoll_ID
uint16_t Mlen; //Msglength
uint8_t Dev; //Geräte_ID
uint8_t Fcd; //Function Code
uint16_t Reg; // Content Register
uint16_t Count; //anzahl Register
char data[197];
}Modbus_receive;
std::array<int, 20> oekofen{2,11,12,13,21,22,23,31,32,33,41,42,43,60,61,73,78,101,102,105};
static int x1 = 0;
static int16_t temp[oekofen.size()];
static uint8_t tn = 1;
char server_ip[16];
static bool brequest = false;
long iModbusTCP_Set(int reg,int val,int tac)
{
send.resize(12);
receive.resize(125);
Modbus_send Msend;
Msend.Tid = (tn*256+reg);
tn++;
Msend.Pid = 0;
Msend.Mlen = 6*256;
Msend.Dev = 1; // Devadr. 1 oder 255
Msend.Fcd = 6; // Funktioncode
// Msend.Fcd = 6; // Funktioncode
Msend.Reg = reg*256; // Adresse Register // Aussentemperatur
Msend.Count = (val%256)*256; // Inhalt int size = send.size();
Msend.Count = Msend.Count + val/256; // Inhalt int size = send.size();
memcpy(&send[0],&Msend,send.size());
if (e3dc_config.debug)