|
@ -481,37 +481,10 @@ void _sensorInit() { |
|
|
|
|
|
|
|
|
for (unsigned char i=0; i<_sensors.size(); i++) { |
|
|
for (unsigned char i=0; i<_sensors.size(); i++) { |
|
|
|
|
|
|
|
|
// Do not process and already initialized sensor
|
|
|
|
|
|
|
|
|
// Do not process an already initialized sensor
|
|
|
if (_sensors[i]->ready()) continue; |
|
|
if (_sensors[i]->ready()) continue; |
|
|
DEBUG_MSG_P(PSTR("[SENSOR] Initializing %s\n"), _sensors[i]->description().c_str()); |
|
|
DEBUG_MSG_P(PSTR("[SENSOR] Initializing %s\n"), _sensors[i]->description().c_str()); |
|
|
|
|
|
|
|
|
#if EMON_ANALOG_SUPPORT
|
|
|
|
|
|
|
|
|
|
|
|
if (_sensors[i]->getID() == SENSOR_EMON_ANALOG_ID) { |
|
|
|
|
|
|
|
|
|
|
|
double value; |
|
|
|
|
|
EmonAnalogSensor * sensor = (EmonAnalogSensor *) _sensors[i]; |
|
|
|
|
|
|
|
|
|
|
|
if (value = (getSetting("pwrExpectedP", 0).toInt() == 0)) { |
|
|
|
|
|
value = getSetting("pwrRatioC", EMON_CURRENT_RATIO).toFloat(); |
|
|
|
|
|
if (value > 0) sensor->setCurrentRatio(0, value); |
|
|
|
|
|
} else { |
|
|
|
|
|
sensor->expectedPower(0, value); |
|
|
|
|
|
setSetting("pwrRatioC", sensor->getCurrentRatio(0)); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (getSetting("pwrResetCalibration", 0).toInt() == 1) { |
|
|
|
|
|
sensor->setCurrentRatio(0, EMON_CURRENT_RATIO); |
|
|
|
|
|
delSetting("pwrRatioC"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
sensor->setVoltage(getSetting("pwrVoltage", EMON_MAINS_VOLTAGE).toInt()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#endif // EMON_ANALOG_SUPPORT
|
|
|
|
|
|
|
|
|
|
|
|
// Force sensor to reload config
|
|
|
// Force sensor to reload config
|
|
|
_sensors[i]->begin(); |
|
|
_sensors[i]->begin(); |
|
|
if (!_sensors[i]->ready()) { |
|
|
if (!_sensors[i]->ready()) { |
|
@ -555,6 +528,81 @@ void _sensorInit() { |
|
|
_sensorCallback(i, type, payload); |
|
|
_sensorCallback(i, type, payload); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
// Custom initializations
|
|
|
|
|
|
|
|
|
|
|
|
#if EMON_ANALOG_SUPPORT
|
|
|
|
|
|
|
|
|
|
|
|
if (_sensors[i]->getID() == SENSOR_EMON_ANALOG_ID) { |
|
|
|
|
|
EmonAnalogSensor * sensor = (EmonAnalogSensor *) _sensors[i]; |
|
|
|
|
|
sensor->setCurrentRatio(0, getSetting("pwrRatioC", EMON_CURRENT_RATIO).toFloat()); |
|
|
|
|
|
sensor->setVoltage(getSetting("pwrVoltage", EMON_MAINS_VOLTAGE).toInt()); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#endif // EMON_ANALOG_SUPPORT
|
|
|
|
|
|
|
|
|
|
|
|
#if HLW8012_SUPPORT
|
|
|
|
|
|
|
|
|
|
|
|
if (_sensors[i]->getID() == SENSOR_HLW8012_ID) { |
|
|
|
|
|
|
|
|
|
|
|
HLW8012Sensor * sensor = (HLW8012Sensor *) _sensors[i]; |
|
|
|
|
|
|
|
|
|
|
|
double value; |
|
|
|
|
|
|
|
|
|
|
|
value = getSetting("pwrRatioC", 0).toFloat(); |
|
|
|
|
|
if (value > 0) sensor->setCurrentRatio(value); |
|
|
|
|
|
|
|
|
|
|
|
value = getSetting("pwrRatioV", 0).toFloat(); |
|
|
|
|
|
if (value > 0) sensor->setVoltageRatio(value); |
|
|
|
|
|
|
|
|
|
|
|
value = getSetting("pwrRatioP", 0).toFloat(); |
|
|
|
|
|
if (value > 0) sensor->setPowerRatio(value); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#endif // HLW8012_SUPPORT
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void _sensorConfigure() { |
|
|
|
|
|
|
|
|
|
|
|
// General sensor settings
|
|
|
|
|
|
_sensor_read_interval = 1000 * constrain(getSetting("snsRead", SENSOR_READ_INTERVAL).toInt(), SENSOR_READ_MIN_INTERVAL, SENSOR_READ_MAX_INTERVAL); |
|
|
|
|
|
_sensor_report_every = constrain(getSetting("snsReport", SENSOR_REPORT_EVERY).toInt(), SENSOR_REPORT_MIN_EVERY, SENSOR_REPORT_MAX_EVERY); |
|
|
|
|
|
_sensor_realtime = getSetting("apiRealTime", API_REAL_TIME_VALUES).toInt() == 1; |
|
|
|
|
|
_sensor_power_units = getSetting("powerUnits", SENSOR_POWER_UNITS).toInt(); |
|
|
|
|
|
_sensor_energy_units = getSetting("energyUnits", SENSOR_ENERGY_UNITS).toInt(); |
|
|
|
|
|
_sensor_temperature_units = getSetting("tmpUnits", SENSOR_TEMPERATURE_UNITS).toInt(); |
|
|
|
|
|
_sensor_temperature_correction = getSetting("tmpCorrection", SENSOR_TEMPERATURE_CORRECTION).toFloat(); |
|
|
|
|
|
_sensor_humidity_correction = getSetting("humCorrection", SENSOR_HUMIDITY_CORRECTION).toFloat(); |
|
|
|
|
|
|
|
|
|
|
|
// Specific sensor settings
|
|
|
|
|
|
for (unsigned char i=0; i<_sensors.size(); i++) { |
|
|
|
|
|
|
|
|
|
|
|
#if EMON_ANALOG_SUPPORT
|
|
|
|
|
|
|
|
|
|
|
|
if (_sensors[i]->getID() == SENSOR_EMON_ANALOG_ID) { |
|
|
|
|
|
|
|
|
|
|
|
double value; |
|
|
|
|
|
EmonAnalogSensor * sensor = (EmonAnalogSensor *) _sensors[i]; |
|
|
|
|
|
|
|
|
|
|
|
if (value = getSetting("pwrExpectedP", 0).toInt()) { |
|
|
|
|
|
sensor->expectedPower(0, value); |
|
|
|
|
|
setSetting("pwrRatioC", sensor->getCurrentRatio(0)); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (getSetting("pwrResetCalibration", 0).toInt() == 1) { |
|
|
|
|
|
sensor->setCurrentRatio(0, EMON_CURRENT_RATIO); |
|
|
|
|
|
delSetting("pwrRatioC"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
sensor->setVoltage(getSetting("pwrVoltage", EMON_MAINS_VOLTAGE).toInt()); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#endif // EMON_ANALOG_SUPPORT
|
|
|
|
|
|
|
|
|
#if HLW8012_SUPPORT
|
|
|
#if HLW8012_SUPPORT
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -566,25 +614,16 @@ void _sensorInit() { |
|
|
if (value = getSetting("pwrExpectedC", 0).toFloat()) { |
|
|
if (value = getSetting("pwrExpectedC", 0).toFloat()) { |
|
|
sensor->expectedCurrent(value); |
|
|
sensor->expectedCurrent(value); |
|
|
setSetting("pwrRatioC", sensor->getCurrentRatio()); |
|
|
setSetting("pwrRatioC", sensor->getCurrentRatio()); |
|
|
} else { |
|
|
|
|
|
value = getSetting("pwrRatioC", 0).toFloat(); |
|
|
|
|
|
if (value > 0) sensor->setCurrentRatio(value); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (value = getSetting("pwrExpectedV", 0).toInt()) { |
|
|
if (value = getSetting("pwrExpectedV", 0).toInt()) { |
|
|
sensor->expectedVoltage(value); |
|
|
sensor->expectedVoltage(value); |
|
|
setSetting("pwrRatioV", sensor->getVoltageRatio()); |
|
|
setSetting("pwrRatioV", sensor->getVoltageRatio()); |
|
|
} else { |
|
|
|
|
|
value = getSetting("pwrRatioV", 0).toFloat(); |
|
|
|
|
|
if (value > 0) sensor->setVoltageRatio(value); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (value = getSetting("pwrExpectedP", 0).toInt()) { |
|
|
if (value = getSetting("pwrExpectedP", 0).toInt()) { |
|
|
sensor->expectedPower(value); |
|
|
sensor->expectedPower(value); |
|
|
setSetting("pwrRatioP", sensor->getPowerRatio()); |
|
|
setSetting("pwrRatioP", sensor->getPowerRatio()); |
|
|
} else { |
|
|
|
|
|
value = getSetting("pwrRatioP", 0).toFloat(); |
|
|
|
|
|
if (value > 0) sensor->setPowerRatio(value); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (getSetting("pwrResetCalibration", 0).toInt() == 1) { |
|
|
if (getSetting("pwrResetCalibration", 0).toInt() == 1) { |
|
@ -600,20 +639,6 @@ void _sensorInit() { |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void _sensorConfigure() { |
|
|
|
|
|
|
|
|
|
|
|
// General sensor settings
|
|
|
|
|
|
_sensor_read_interval = 1000 * constrain(getSetting("snsRead", SENSOR_READ_INTERVAL).toInt(), SENSOR_READ_MIN_INTERVAL, SENSOR_READ_MAX_INTERVAL); |
|
|
|
|
|
_sensor_report_every = constrain(getSetting("snsReport", SENSOR_REPORT_EVERY).toInt(), SENSOR_REPORT_MIN_EVERY, SENSOR_REPORT_MAX_EVERY); |
|
|
|
|
|
_sensor_realtime = getSetting("apiRealTime", API_REAL_TIME_VALUES).toInt() == 1; |
|
|
|
|
|
_sensor_power_units = getSetting("powerUnits", SENSOR_POWER_UNITS).toInt(); |
|
|
|
|
|
_sensor_energy_units = getSetting("energyUnits", SENSOR_ENERGY_UNITS).toInt(); |
|
|
|
|
|
_sensor_temperature_units = getSetting("tmpUnits", SENSOR_TEMPERATURE_UNITS).toInt(); |
|
|
|
|
|
_sensor_temperature_correction = getSetting("tmpCorrection", SENSOR_TEMPERATURE_CORRECTION).toFloat(); |
|
|
|
|
|
_sensor_humidity_correction = getSetting("humCorrection", SENSOR_HUMIDITY_CORRECTION).toFloat(); |
|
|
|
|
|
|
|
|
|
|
|
// Update filter sizes
|
|
|
// Update filter sizes
|
|
|
for (unsigned char i=0; i<_magnitudes.size(); i++) { |
|
|
for (unsigned char i=0; i<_magnitudes.size(); i++) { |
|
|
_magnitudes[i].filter->resize(_sensor_report_every); |
|
|
_magnitudes[i].filter->resize(_sensor_report_every); |
|
@ -624,7 +649,7 @@ void _sensorConfigure() { |
|
|
delSetting("pwrExpectedC"); |
|
|
delSetting("pwrExpectedC"); |
|
|
delSetting("pwrExpectedV"); |
|
|
delSetting("pwrExpectedV"); |
|
|
delSetting("pwrResetCalibration"); |
|
|
delSetting("pwrResetCalibration"); |
|
|
//saveSettings();
|
|
|
|
|
|
|
|
|
saveSettings(); |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|