change flow timing

This commit is contained in:
interfisch 2023-05-15 18:00:51 +02:00
parent 84c1f23389
commit f0398e49c0
3 changed files with 56 additions and 6 deletions

View File

@ -7,7 +7,7 @@ mqttValueTiming timing_flow;
uint16_t flow_counter=0; //maximum counts/s measured with Eden 128 Pump was 171 uint16_t flow_counter=0; //maximum counts/s measured with Eden 128 Pump was 171
void IRAM_ATTR isr_flow(); void IRAM_ATTR isr_flow();
unsigned long last_read_flow=0; unsigned long last_read_flow=0;
#define READINTERVAL_FLOW 2000 #define READINTERVAL_FLOW 10000
float flow_factor=7.5; //F=7.5*flowrate[L/min] float flow_factor=7.5; //F=7.5*flowrate[L/min]
float flow; float flow;
@ -18,8 +18,8 @@ uint32_t flow_counter_sum=0;
void flow_setup() { void flow_setup() {
timing_flow.minchange=0.0; timing_flow.minchange=0.0;
timing_flow.maxchange=0.5; timing_flow.maxchange=0.3;
timing_flow.mintime=1*000; timing_flow.mintime=10*000;
timing_flow.maxtime=30*60*1000; timing_flow.maxtime=30*60*1000;
pinMode(FLOW_PIN, INPUT_PULLUP); pinMode(FLOW_PIN, INPUT_PULLUP);

View File

@ -4,6 +4,7 @@
mqttValueTiming timing_temperature_reservoir; mqttValueTiming timing_temperature_reservoir;
mqttValueTiming timing_temperature_air; mqttValueTiming timing_temperature_air;
mqttValueTiming timing_temperature_case;
#include <OneWire.h> #include <OneWire.h>
#include <DallasTemperature.h> #include <DallasTemperature.h>
@ -39,6 +40,13 @@ float tempC_air; //last reading
float tempCmean_air_array[TEMPMEAN_SIZE]; float tempCmean_air_array[TEMPMEAN_SIZE];
float tempCmean_air=DEVICE_DISCONNECTED_C; float tempCmean_air=DEVICE_DISCONNECTED_C;
DeviceAddress thermometerCase={0x10,0x7E,0x22,0x99,0x01,0x08,0x00,0xA4};
float tempC_case; //last reading
float tempCmean_case_array[TEMPMEAN_SIZE];
float tempCmean_case=DEVICE_DISCONNECTED_C;
void temperature_setup() { void temperature_setup() {
timing_temperature_reservoir.minchange=0.0; timing_temperature_reservoir.minchange=0.0;
@ -51,10 +59,16 @@ void temperature_setup() {
timing_temperature_air.mintime=2*1000; timing_temperature_air.mintime=2*1000;
timing_temperature_air.maxtime=60*60*1000; timing_temperature_air.maxtime=60*60*1000;
timing_temperature_case.minchange=0.0;
timing_temperature_case.maxchange=0.5;
timing_temperature_case.mintime=2*1000;
timing_temperature_case.maxtime=60*60*1000;
//initialize mean array //initialize mean array
for (uint16_t i=0;i<TEMPMEAN_SIZE;i++) { for (uint16_t i=0;i<TEMPMEAN_SIZE;i++) {
tempCmean_reservoir_array[i]=-127; tempCmean_reservoir_array[i]=-127;
tempCmean_air_array[i]=-127; tempCmean_air_array[i]=-127;
tempCmean_case_array[i]=-127;
} }
sensors.begin(); sensors.begin();
@ -92,6 +106,7 @@ void temperature_setup() {
sensors.setResolution(thermometerReservoir, TEMPERATURE_PRECISION); sensors.setResolution(thermometerReservoir, TEMPERATURE_PRECISION);
sensors.setResolution(thermometerAir, TEMPERATURE_PRECISION); sensors.setResolution(thermometerAir, TEMPERATURE_PRECISION);
sensors.setResolution(thermometerCase, TEMPERATURE_PRECISION);
} }
@ -128,7 +143,7 @@ void temperature_loop(unsigned long loopmillis) {
tempC_air = sensors.getTempC(thermometerAir); tempC_air = sensors.getTempC(thermometerAir);
if (tempC_air == DEVICE_DISCONNECTED_C) if (tempC_air == DEVICE_DISCONNECTED_C)
{ {
Serial.print(" Error reading: "); printAddress(thermometerReservoir); Serial.print(" Error reading: "); printAddress(thermometerAir);
}else{ }else{
tempCmean_air_array[tempCmean_pos]=tempC_air; tempCmean_air_array[tempCmean_pos]=tempC_air;
if (isValueArrayOKf(tempCmean_air_array,TEMPMEAN_SIZE,DEVICE_DISCONNECTED_C)) { if (isValueArrayOKf(tempCmean_air_array,TEMPMEAN_SIZE,DEVICE_DISCONNECTED_C)) {
@ -138,6 +153,19 @@ void temperature_loop(unsigned long loopmillis) {
} }
} }
tempC_case = sensors.getTempC(thermometerCase);
if (tempC_case == DEVICE_DISCONNECTED_C)
{
Serial.print(" Error reading: "); printAddress(thermometerCase);
}else{
tempCmean_case_array[tempCmean_pos]=tempC_case;
if (isValueArrayOKf(tempCmean_case_array,TEMPMEAN_SIZE,DEVICE_DISCONNECTED_C)) {
tempCmean_case=getMeanf(tempCmean_case_array,TEMPMEAN_SIZE);
}else{
tempCmean_case=DEVICE_DISCONNECTED_C;
}
}
tempCmean_pos++; tempCmean_pos++;
tempCmean_pos%=TEMPMEAN_SIZE; tempCmean_pos%=TEMPMEAN_SIZE;
} }

View File

@ -149,7 +149,7 @@ void loop() {
if (tempCmean_air==DEVICE_DISCONNECTED_C || tempCmean_reservoir==DEVICE_DISCONNECTED_C) { if (tempCmean_air==DEVICE_DISCONNECTED_C || tempCmean_reservoir==DEVICE_DISCONNECTED_C || tempCmean_case==DEVICE_DISCONNECTED_C) {
valueError=true; valueError=true;
} }
//if (waterlevel==WATERLEVEL_UNAVAILABLE) { //if (waterlevel==WATERLEVEL_UNAVAILABLE) {
@ -241,6 +241,9 @@ void loop() {
if (tempCmean_air!=DEVICE_DISCONNECTED_C) { if (tempCmean_air!=DEVICE_DISCONNECTED_C) {
publishValueTimed("temperature/air",tempCmean_air,2,timing_temperature_air,loopmillis); publishValueTimed("temperature/air",tempCmean_air,2,timing_temperature_air,loopmillis);
} }
if (tempCmean_case!=DEVICE_DISCONNECTED_C) {
publishValueTimed("temperature/case",tempCmean_case,2,timing_temperature_case,loopmillis);
}
if (sm_mean1!=SM_DISCONNECTED) { if (sm_mean1!=SM_DISCONNECTED) {
publishValueTimed("soilmoisture/sm1",sm_mean1,3,timing_soilmoisture_sm1,loopmillis); publishValueTimed("soilmoisture/sm1",sm_mean1,3,timing_soilmoisture_sm1,loopmillis);
} }
@ -254,6 +257,25 @@ void loop() {
publishValueTimed("flow/flow",flow,2,timing_flow,loopmillis); publishValueTimed("flow/flow",flow,2,timing_flow,loopmillis);
if (ec_flag_measurement_available){
ec_flag_measurement_available=false;
if (ec_adc!=0) {
publishValue("ec/adc",ec_adc,0);
}
if (ec_calib_adc!=0) {
publishValue("ec/eccalibadc",ec_calib_adc,0);
}
if (ec_adc_adjusted!=0) {
publishValue("ec/adcadjusted",ec_adc_adjusted,0);
}
if (ec!=EC_UNAVAILABLE){
publishValue("ec/ec",ec,0);
publishValue("ec/sc",ec25,0);
}
}
/*
if (ec_adc!=0) { if (ec_adc!=0) {
publishValueTimed("ec/adc",ec_adc,0,timing_ec_adc,loopmillis); publishValueTimed("ec/adc",ec_adc,0,timing_ec_adc,loopmillis);
} }
@ -266,7 +288,7 @@ void loop() {
if (ec!=EC_UNAVAILABLE){ if (ec!=EC_UNAVAILABLE){
publishValueTimed("ec/ec",ec,0,timing_ec_ec,loopmillis); publishValueTimed("ec/ec",ec,0,timing_ec_ec,loopmillis);
publishValueTimed("ec/sc",ec25,0,timing_ec_sc,loopmillis); publishValueTimed("ec/sc",ec25,0,timing_ec_sc,loopmillis);
} }*/
} }