@ -38,6 +38,7 @@ typedef struct {
bool running ;
bool running ;
uint8_t lastIvId ;
uint8_t lastIvId ;
uint8_t sub ;
uint8_t sub ;
uint8_t foundIvCnt ;
} discovery_t ;
} discovery_t ;
template < class HMSYSTEM >
template < class HMSYSTEM >
@ -224,6 +225,7 @@ class PubMqtt {
mDiscovery . running = true ;
mDiscovery . running = true ;
mDiscovery . lastIvId = 0 ;
mDiscovery . lastIvId = 0 ;
mDiscovery . sub = 0 ;
mDiscovery . sub = 0 ;
mDiscovery . foundIvCnt = 0 ;
}
}
void setPowerLimitAck ( Inverter < > * iv ) {
void setPowerLimitAck ( Inverter < > * iv ) {
@ -350,14 +352,16 @@ class PubMqtt {
uint8_t fldTotal [ 4 ] = { FLD_PAC , FLD_YT , FLD_YD , FLD_PDC } ;
uint8_t fldTotal [ 4 ] = { FLD_PAC , FLD_YT , FLD_YD , FLD_PDC } ;
const char * unitTotal [ 4 ] = { " W " , " kWh " , " Wh " , " W " } ;
const char * unitTotal [ 4 ] = { " W " , " kWh " , " Wh " , " W " } ;
String node_mac = WiFi . macAddress ( ) . substring ( 12 , 14 ) + WiFi . macAddress ( ) . substring ( 15 , 17 ) ;
String node_id = String ( mDevName ) + " _TOTAL " ;
String node_id = " AHOY_DTU_ " + node_mac ;
bool total = ( mDiscovery . lastIvId = = MAX_NUM_INVERTERS ) ;
bool total = ( mDiscovery . lastIvId = = MAX_NUM_INVERTERS ) ;
Inverter < > * iv = mSys - > getInverterByPos ( mDiscovery . lastIvId ) ;
Inverter < > * iv = mSys - > getInverterByPos ( mDiscovery . lastIvId ) ;
record_t < > * rec ;
record_t < > * rec ;
if ( NULL ! = iv )
if ( NULL ! = iv ) {
rec = iv - > getRecordStruct ( RealTimeRunData_Debug ) ;
rec = iv - > getRecordStruct ( RealTimeRunData_Debug ) ;
if ( 0 = = mDiscovery . sub )
mDiscovery . foundIvCnt + + ;
}
if ( ( NULL ! = iv ) | | total ) {
if ( ( NULL ! = iv ) | | total ) {
if ( ! total ) {
if ( ! total ) {
@ -420,18 +424,26 @@ class PubMqtt {
if ( + + mDiscovery . sub = = ( ( ! total ) ? ( rec - > length ) : 4 ) ) {
if ( + + mDiscovery . sub = = ( ( ! total ) ? ( rec - > length ) : 4 ) ) {
mDiscovery . sub = 0 ;
mDiscovery . sub = 0 ;
if ( + + mDiscovery . lastIvId = = ( MAX_NUM_INVERTERS + 1 ) )
checkDiscoveryEnd ( ) ;
mDiscovery . running = false ;
}
}
} else {
} else {
mDiscovery . sub = 0 ;
mDiscovery . sub = 0 ;
if ( + + mDiscovery . lastIvId = = ( MAX_NUM_INVERTERS + 1 ) )
checkDiscoveryEnd ( ) ;
mDiscovery . running = false ;
}
}
yield ( ) ;
yield ( ) ;
}
}
void checkDiscoveryEnd ( void ) {
if ( + + mDiscovery . lastIvId = = MAX_NUM_INVERTERS ) {
// check if only one inverter was found, then don't create 'total' sensor
DPRINTLN ( DBG_INFO , " found: " + String ( mDiscovery . foundIvCnt ) ) ;
if ( mDiscovery . foundIvCnt = = 1 )
mDiscovery . running = false ;
} else if ( mDiscovery . lastIvId = = ( MAX_NUM_INVERTERS + 1 ) )
mDiscovery . running = false ;
}
const char * getFieldDeviceClass ( uint8_t fieldId ) {
const char * getFieldDeviceClass ( uint8_t fieldId ) {
uint8_t pos = 0 ;
uint8_t pos = 0 ;
for ( ; pos < DEVICE_CLS_ASSIGN_LIST_LEN ; pos + + ) {
for ( ; pos < DEVICE_CLS_ASSIGN_LIST_LEN ; pos + + ) {