2121#include < regex>
2222#include < mutex>
2323
24- #define RSCP2MQTT_VERSION " 3.29 "
24+ #define RSCP2MQTT_VERSION " 3.30 "
2525
2626#define AES_KEY_SIZE 32
2727#define AES_BLOCK_SIZE 32
4040#ifdef INFLUXDB
4141 #define RSCP2MQTT RSCP2MQTT_VERSION" .influxdb"
4242 #define INFLUXDB_PORT_DEFAULT 8086
43- #define CURL_BUFFER_SIZE 1024
43+ #define CURL_BUFFER_SIZE 65536
4444#else
4545 #define RSCP2MQTT RSCP2MQTT_VERSION
4646#endif
@@ -2607,7 +2607,6 @@ static void receiveLoop(bool & bStopExecution) {
26072607 // multiple frames can only occur in this example if one or more frames are received with a big time delay
26082608 // this should usually not occur but handling this is shown in this example
26092609 int iReceivedRscpFrames = 0 ;
2610-
26112610 int iResult;
26122611
26132612 while (!bStopExecution && ((iReceivedBytes > 0 ) || iReceivedRscpFrames == 0 )) {
@@ -2628,23 +2627,30 @@ static void receiveLoop(bool & bStopExecution) {
26282627 // receive data
26292628 // Issues #55, #61 and #67
26302629 while (1 ) {
2630+ errno = 0 ; // Issue #87
26312631 iResult = SocketRecvData (iSocket, &vecDynamicBuffer[0 ] + iReceivedBytes, vecDynamicBuffer.size () - iReceivedBytes);
26322632 if (iResult < 0 ) {
26332633 if ((errno == EAGAIN) || (errno == EWOULDBLOCK) || (errno == EINTR)) continue ;
26342634 logMessage (cfg.logfile , (char *)__FILE__, __LINE__, (char *)" Error: Socket receive error. errno %i\n " , errno);
26352635 bStopExecution = true ;
2636+ vecDynamicBuffer.resize (0 ); // Issue #87
2637+ iReceivedBytes = 0 ; // Issue #87
2638+ break ;
26362639 } else if (iResult == 0 ) {
26372640 // connection was closed regularly by peer
26382641 // if this happens on startup each time the possible reason is
26392642 // wrong AES password or wrong network subnet (adapt hosts.allow file required)
26402643 logMessage (cfg.logfile , (char *)__FILE__, __LINE__, (char *)" Error: Connection closed by peer. Perhaps E3DC_AES_PASSWORD is not configured correctly.\n " );
26412644 bStopExecution = true ;
2645+ vecDynamicBuffer.resize (0 ); // Issue #87
2646+ iReceivedBytes = 0 ; // Issue #87
2647+ break ;
26422648 }
26432649 break ;
26442650 }
26452651
26462652 // increment amount of received bytes
2647- iReceivedBytes += iResult;
2653+ if (!bStopExecution) iReceivedBytes += iResult; // Issue #87
26482654
26492655 // process all received frames
26502656 while (!bStopExecution) {
@@ -2668,6 +2674,8 @@ static void receiveLoop(bool & bStopExecution) {
26682674 logMessage (cfg.logfile , (char *)__FILE__, __LINE__, (char *)" Error: parsing RSCP frame: %i\n " , iProcessedBytes);
26692675 // stop execution as the data received is not RSCP data
26702676 bStopExecution = true ;
2677+ vecDynamicBuffer.resize (0 ); // Issue #87
2678+ iReceivedBytes = 0 ; // Issue #87
26712679 break ;
26722680 } else if (iProcessedBytes > 0 ) {
26732681 // round up the processed bytes as iProcessedBytes does not include the zero padding bytes
@@ -2735,6 +2743,8 @@ static void mainLoop(void) {
27352743 // free frame buffer memory
27362744 protocol.destroyFrameData (&frameBuffer);
27372745
2746+ if (bStopExecution) return ; // Issue #87
2747+
27382748 if (countdown <= 0 ) {
27392749 classifyValues (RSCP_MQTT::RscpMqttCache);
27402750 if (cfg.pm_requests ) pmSummation (RSCP_MQTT::RscpMqttCache, cfg.pm_number );
@@ -2846,6 +2856,7 @@ static void mainLoop(void) {
28462856int main (int argc, char *argv[]) {
28472857 char key[128 ], value[128 ], line[256 ];
28482858 char *cfile = NULL ;
2859+ char *env = NULL ;
28492860 int i = 0 ;
28502861
28512862 cfg.daemon = false ;
@@ -3180,6 +3191,32 @@ int main(int argc, char *argv[]) {
31803191 }
31813192 fclose (fp);
31823193
3194+ // Overwrite with environment parameters
3195+ env = getenv (" E3DC_IP" );
3196+ if (env) strcpy (cfg.e3dc_ip , env);
3197+ env = getenv (" E3DC_PORT" );
3198+ if (env) cfg.e3dc_port = atoi (env);
3199+ env = getenv (" E3DC_USER" );
3200+ if (env) strcpy (cfg.e3dc_user , env);
3201+ env = getenv (" E3DC_PASSWORD" );
3202+ if (env) strcpy (cfg.e3dc_password , env);
3203+ env = getenv (" E3DC_AES_PASSWORD" );
3204+ if (env) strcpy (cfg.aes_password , env);
3205+ env = getenv (" PREFIX" );
3206+ if (env) strncpy (cfg.prefix , env, 24 );
3207+ env = getenv (" HISTORY_START_YEAR" );
3208+ if (env) cfg.history_start_year = atoi (env);
3209+ env = getenv (" INTERVAL" );
3210+ if (env) cfg.interval = atoi (env);
3211+ env = getenv (" RAW_MODE" );
3212+ if (env && (strcasecmp (env, " true" ) == 0 )) cfg.raw_mode = true ;
3213+ env = getenv (" WALLBOX" );
3214+ if (env && (strcasecmp (env, " true" ) == 0 )) cfg.wallbox = true ;
3215+ env = getenv (" PVI_TRACKER" );
3216+ if (env) cfg.pvi_tracker = atoi (env);
3217+ env = getenv (" BATTERY_STRINGS" );
3218+ if (env) cfg.battery_strings = atoi (env);
3219+
31833220#ifdef INFLUXDB
31843221 if (!influx_reduced) {
31853222 store.type = INFLUXDB_TOPIC;
0 commit comments