add second hydroponic system

This commit is contained in:
interfisch 2024-05-04 13:04:05 +02:00
parent 95ceac3e80
commit feeec8ffd4
5 changed files with 125 additions and 90 deletions

View File

@ -170,10 +170,12 @@ void ec_loop(unsigned long loopmillis) {
ec_adc_adjusted=mapf(ec_adc,0,ec_calib_adc,0,ec_reference_adc); ec_adc_adjusted=mapf(ec_adc,0,ec_calib_adc,0,ec_reference_adc);
if (probeselect==0) { if (probeselect==0) {
ec=ec_getECfromADC(ec_adc_adjusted, ec_calibration_polynom_A, sizeof(ec_calibration_polynom_A), ec_calibration_linearize_below_adc_A, ec_calibration_linear_lowADC_A, ec_calibration_linear_lowEC_A); ec=ec_getECfromADC(ec_adc_adjusted, ec_calibration_polynom_A, sizeof(ec_calibration_polynom_A), ec_calibration_linearize_below_adc_A, ec_calibration_linear_lowADC_A, ec_calibration_linear_lowEC_A);
ec25=ec_calculateEC25(ec,tempC_reservoir_a);
}else if (probeselect==1) { }else if (probeselect==1) {
ec=ec_getECfromADC(ec_adc_adjusted, ec_calibration_polynom_B, sizeof(ec_calibration_polynom_B), ec_calibration_linearize_below_adc_B, ec_calibration_linear_lowADC_B, ec_calibration_linear_lowEC_B); ec=ec_getECfromADC(ec_adc_adjusted, ec_calibration_polynom_B, sizeof(ec_calibration_polynom_B), ec_calibration_linearize_below_adc_B, ec_calibration_linear_lowADC_B, ec_calibration_linear_lowEC_B);
ec25=ec_calculateEC25(ec,tempC_reservoir_b);
} }
ec25=ec_calculateEC25(ec,tempC_reservoir);
//Serial.println("DEBUG: EC OK"); //Serial.println("DEBUG: EC OK");
}else{ }else{
ec_calib_adc=EC_ADC_UNAVAILABLE; ec_calib_adc=EC_ADC_UNAVAILABLE;

View File

@ -1,44 +1,72 @@
#ifndef _FLOW_H_ #ifndef _FLOW_H_
#define _FLOW_H_ #define _FLOW_H_
mqttValueTiming timing_flow; mqttValueTiming timing_flow_a;
mqttValueTiming timing_flow_b;
#define FLOW_PIN 19 #define FLOW_A_PIN 16
uint16_t flow_counter=0; //maximum counts/s measured with Eden 128 Pump was 171 #define FLOW_B_PIN 17
void IRAM_ATTR isr_flow(); uint16_t flow_a_counter=0; //maximum counts/s measured with Eden 128 Pump was 171
unsigned long last_read_flow=0; uint16_t flow_b_counter=0; //maximum counts/s measured with Eden 128 Pump was 171
void IRAM_ATTR isr_flow_a();
void IRAM_ATTR isr_flow_b();
unsigned long last_read_flow_a=0;
unsigned long last_read_flow_b=0;
#define READINTERVAL_FLOW 10000 #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_a;
float flow_b;
uint32_t flow_counter_sum=0; uint32_t flow_a_counter_sum=0;
uint32_t flow_b_counter_sum=0;
void flow_setup() { void flow_setup() {
timing_flow.minchange=0.0; timing_flow_a.minchange=0.0;
timing_flow.maxchange=0.3; timing_flow_a.maxchange=0.3;
timing_flow.mintime=10*000; timing_flow_a.mintime=10*000;
timing_flow.maxtime=30*60*1000; timing_flow_a.maxtime=30*60*1000;
pinMode(FLOW_PIN, INPUT_PULLUP); timing_flow_b.minchange=0.0;
attachInterrupt(FLOW_PIN, isr_flow, CHANGE); timing_flow_b.maxchange=0.3;
timing_flow_b.mintime=10*000;
timing_flow_b.maxtime=30*60*1000;
pinMode(FLOW_A_PIN, INPUT_PULLUP);
pinMode(FLOW_B_PIN, INPUT_PULLUP);
attachInterrupt(FLOW_A_PIN, isr_flow_a, CHANGE);
attachInterrupt(FLOW_B_PIN, isr_flow_b, CHANGE);
} }
void flow_loop(unsigned long loopmillis) { void flow_loop(unsigned long loopmillis) {
if (loopmillis>=last_read_flow+READINTERVAL_FLOW) { if (loopmillis>=last_read_flow_a+READINTERVAL_FLOW) {
flow=flow_counter*1000.0/(loopmillis-last_read_flow)/2.0; //Frequency [Hz] flow_a=flow_a_counter*1000.0/(loopmillis-last_read_flow_a)/2.0; //Frequency [Hz]
flow/=flow_factor; //[L/min] flow_a/=flow_factor; //[L/min]
flow_counter=0; flow_a_counter=0;
last_read_flow=loopmillis; last_read_flow_a=loopmillis;
}
if (loopmillis>=last_read_flow_b+READINTERVAL_FLOW) {
flow_b=flow_b_counter*1000.0/(loopmillis-last_read_flow_b)/2.0; //Frequency [Hz]
flow_b/=flow_factor; //[L/min]
flow_b_counter=0;
last_read_flow_b=loopmillis;
} }
} }
void IRAM_ATTR isr_flow() { void IRAM_ATTR isr_flow_a() {
flow_counter++; flow_a_counter++;
flow_counter_sum++; flow_a_counter_sum++;
}
void IRAM_ATTR isr_flow_b() {
flow_b_counter++;
flow_b_counter_sum++;
} }

View File

@ -2,8 +2,8 @@
#define _TEMPERATURE_H_ #define _TEMPERATURE_H_
mqttValueTiming timing_temperature_reservoir; mqttValueTiming timing_temperature_reservoir_a;
mqttValueTiming timing_temperature_air; mqttValueTiming timing_temperature_reservoir_b;
mqttValueTiming timing_temperature_case; mqttValueTiming timing_temperature_case;
#include <OneWire.h> #include <OneWire.h>
@ -28,17 +28,19 @@ DallasTemperature sensors(&oneWire);
#define TEMPMEAN_SIZE 16 #define TEMPMEAN_SIZE 16
uint16_t tempCmean_pos=0; uint16_t tempCmean_pos=0;
// arrays to hold device addresses // arrays to hold device addresses
DeviceAddress thermometerReservoir={0x28,0xFF,0x30,0xBA,0x85,0x16,0x03,0xB5}; DeviceAddress thermometerReservoirA={0x28,0xFF,0x6F,0x19,0x72,0x16,0x05,0x44};
float tempC_reservoir; //last reading float tempC_reservoir_a; //last reading
float tempCmean_reservoir_array[TEMPMEAN_SIZE]; float tempCmean_reservoir_a_array[TEMPMEAN_SIZE];
float tempCmean_reservoir=DEVICE_DISCONNECTED_C; float tempCmean_reservoir_a=DEVICE_DISCONNECTED_C;
DeviceAddress thermometerAir={0x28,0xFF,0x6C,0x1C,0x72,0x16,0x05,0x8B}; //DeviceAddress thermometerAir={0x28,0xFF,0x6C,0x1C,0x72,0x16,0x05,0x8B};
float tempC_air; //last reading
float tempCmean_air_array[TEMPMEAN_SIZE]; DeviceAddress thermometerReservoirB={0x28,0xFF,0x30,0xBA,0x85,0x16,0x03,0xB5};
float tempCmean_air=DEVICE_DISCONNECTED_C; float tempC_reservoir_b; //last reading
float tempCmean_reservoir_b_array[TEMPMEAN_SIZE];
float tempCmean_reservoir_b=DEVICE_DISCONNECTED_C;
DeviceAddress thermometerCase={0x10,0x7E,0x22,0x99,0x01,0x08,0x00,0xA4}; DeviceAddress thermometerCase={0x10,0x7E,0x22,0x99,0x01,0x08,0x00,0xA4};
float tempC_case; //last reading float tempC_case; //last reading
@ -49,15 +51,16 @@ float tempCmean_case=DEVICE_DISCONNECTED_C;
void temperature_setup() { void temperature_setup() {
timing_temperature_reservoir.minchange=0.0; timing_temperature_reservoir_a.minchange=0.0;
timing_temperature_reservoir.maxchange=0.5; timing_temperature_reservoir_a.maxchange=0.5;
timing_temperature_reservoir.mintime=2*1000; timing_temperature_reservoir_a.mintime=2*1000;
timing_temperature_reservoir.maxtime=60*60*1000; timing_temperature_reservoir_a.maxtime=60*60*1000;
timing_temperature_reservoir_b.minchange=0.0;
timing_temperature_reservoir_b.maxchange=0.5;
timing_temperature_reservoir_b.mintime=2*1000;
timing_temperature_reservoir_b.maxtime=60*60*1000;
timing_temperature_air.minchange=0.0;
timing_temperature_air.maxchange=0.5;
timing_temperature_air.mintime=2*1000;
timing_temperature_air.maxtime=60*60*1000;
timing_temperature_case.minchange=0.0; timing_temperature_case.minchange=0.0;
timing_temperature_case.maxchange=0.5; timing_temperature_case.maxchange=0.5;
@ -66,8 +69,8 @@ void temperature_setup() {
//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_a_array[i]=-127;
tempCmean_air_array[i]=-127; tempCmean_reservoir_b_array[i]=-127;
tempCmean_case_array[i]=-127; tempCmean_case_array[i]=-127;
} }
@ -104,8 +107,8 @@ void temperature_setup() {
} }
sensors.setResolution(thermometerReservoir, TEMPERATURE_PRECISION); sensors.setResolution(thermometerReservoirA, TEMPERATURE_PRECISION);
sensors.setResolution(thermometerAir, TEMPERATURE_PRECISION); sensors.setResolution(thermometerReservoirB, TEMPERATURE_PRECISION);
sensors.setResolution(thermometerCase, TEMPERATURE_PRECISION); sensors.setResolution(thermometerCase, TEMPERATURE_PRECISION);
} }
@ -127,33 +130,32 @@ void temperature_loop(unsigned long loopmillis) {
flag_requestTemperatures=false; flag_requestTemperatures=false;
last_read_ds18b20=loopmillis; last_read_ds18b20=loopmillis;
tempC_reservoir = sensors.getTempC(thermometerReservoir); tempC_reservoir_a = sensors.getTempC(thermometerReservoirA);
if (tempC_reservoir == DEVICE_DISCONNECTED_C) if (tempC_reservoir_a == DEVICE_DISCONNECTED_C)
{ {
Serial.print(" Error reading: "); printAddress(thermometerReservoir); Serial.print(" Error reading: "); printAddress(thermometerReservoirA);
}else{ }else{
tempCmean_reservoir_array[tempCmean_pos]=tempC_reservoir; tempCmean_reservoir_a_array[tempCmean_pos]=tempC_reservoir_a;
if (isValueArrayOKf(tempCmean_reservoir_array,TEMPMEAN_SIZE,DEVICE_DISCONNECTED_C)) { if (isValueArrayOKf(tempCmean_reservoir_a_array,TEMPMEAN_SIZE,DEVICE_DISCONNECTED_C)) {
tempCmean_reservoir=getMeanf(tempCmean_reservoir_array,TEMPMEAN_SIZE); tempCmean_reservoir_a=getMeanf(tempCmean_reservoir_a_array,TEMPMEAN_SIZE);
}else{ }else{
tempCmean_reservoir=DEVICE_DISCONNECTED_C; tempCmean_reservoir_a=DEVICE_DISCONNECTED_C;
} }
} }
/* temporarily disabled
tempC_air = sensors.getTempC(thermometerAir); tempC_reservoir_b = sensors.getTempC(thermometerReservoirB);
if (tempC_air == DEVICE_DISCONNECTED_C) if (tempC_reservoir_b == DEVICE_DISCONNECTED_C)
{ {
Serial.print(" Error reading: "); printAddress(thermometerAir); Serial.print(" Error reading: "); printAddress(thermometerReservoirB);
}else{ }else{
tempCmean_air_array[tempCmean_pos]=tempC_air; tempCmean_reservoir_b_array[tempCmean_pos]=tempC_reservoir_b;
if (isValueArrayOKf(tempCmean_air_array,TEMPMEAN_SIZE,DEVICE_DISCONNECTED_C)) { if (isValueArrayOKf(tempCmean_reservoir_b_array,TEMPMEAN_SIZE,DEVICE_DISCONNECTED_C)) {
tempCmean_air=getMeanf(tempCmean_air_array,TEMPMEAN_SIZE); tempCmean_reservoir_b=getMeanf(tempCmean_reservoir_b_array,TEMPMEAN_SIZE);
}else{ }else{
tempCmean_air=DEVICE_DISCONNECTED_C; tempCmean_reservoir_b=DEVICE_DISCONNECTED_C;
} }
} }
*/
tempC_case = sensors.getTempC(thermometerCase); tempC_case = sensors.getTempC(thermometerCase);
if (tempC_case == DEVICE_DISCONNECTED_C) if (tempC_case == DEVICE_DISCONNECTED_C)

View File

@ -64,7 +64,7 @@ void waterlevel_loop(unsigned long loopmillis) {
uint16_t distance=sensor.readRangeSingleMillimeters(); uint16_t distance=sensor.readRangeSingleMillimeters();
//Serial.print("Distance reading:"); Serial.println(distance); Serial.print("Distance reading:"); Serial.println(distance);
if (distance!=WATERLEVEL_UNAVAILABLE) { //successful if (distance!=WATERLEVEL_UNAVAILABLE) { //successful
waterlevelMean_array[waterlevelMean_array_pos]=distance; waterlevelMean_array[waterlevelMean_array_pos]=distance;

View File

@ -40,7 +40,7 @@ ADS1115 ADS(0x48);
#include "flow.h" #include "flow.h"
// ######## Soilmoisture // ######## Soilmoisture
#include "soilmoisture.h" //#include "soilmoisture.h"
@ -88,8 +88,10 @@ void setup() {
Serial.println("Setup Flow"); Serial.println("Setup Flow");
flow_setup(); flow_setup();
/*
Serial.println("Setup Soilmoisture"); Serial.println("Setup Soilmoisture");
sm_setup(); sm_setup();
*/
Serial.println("Finished Setup"); Serial.println("Finished Setup");
delay(200); delay(200);
@ -127,7 +129,7 @@ void loop() {
flow_loop(loopmillis); flow_loop(loopmillis);
sm_loop(loopmillis); //sm_loop(loopmillis);
static bool getReading=false; static bool getReading=false;
@ -165,7 +167,8 @@ void loop() {
getReading=false; getReading=false;
digitalWrite(PIN_LED,LOW); digitalWrite(PIN_LED,LOW);
Serial.print(loopmillis); Serial.print(","); Serial.print(loopmillis); Serial.print(",");
Serial.print(tempCmean_reservoir); Serial.print(","); Serial.print(tempCmean_reservoir_a); Serial.print(",");
Serial.print(tempCmean_reservoir_b); Serial.print(",");
Serial.print(ec_calib_adc); Serial.print(","); Serial.print(ec_calib_adc); Serial.print(",");
Serial.print(ec_adc_A); Serial.print(","); Serial.print(ec_adc_A); Serial.print(",");
Serial.print(ec_adc_adjusted_A); Serial.print(","); Serial.print(ec_adc_adjusted_A); Serial.print(",");
@ -178,13 +181,14 @@ void loop() {
last_check=loopmillis; last_check=loopmillis;
if (tempCmean_air==DEVICE_DISCONNECTED_C || tempCmean_reservoir==DEVICE_DISCONNECTED_C || tempCmean_case==DEVICE_DISCONNECTED_C) { if (tempCmean_reservoir_a==DEVICE_DISCONNECTED_C || tempCmean_reservoir_b==DEVICE_DISCONNECTED_C || tempCmean_case==DEVICE_DISCONNECTED_C) {
valueError=true; valueError=true;
} }
/*
if (sm_mean1==SM_DISCONNECTED || sm_mean2==SM_DISCONNECTED) { if (sm_mean1==SM_DISCONNECTED || sm_mean2==SM_DISCONNECTED) {
valueError=true; valueError=true;
} }*/
if (ec_A==EC_UNAVAILABLE || ec_B==EC_UNAVAILABLE){ if (ec_A==EC_UNAVAILABLE || ec_B==EC_UNAVAILABLE){
valueError=true; valueError=true;
} }
@ -200,17 +204,19 @@ void loop() {
Serial.println("_______________________"); Serial.println("_______________________");
Serial.print(millis()/1000.0,2); Serial.println(":"); Serial.print(millis()/1000.0,2); Serial.println(":");
Serial.print("temperature reservoir,air = "); Serial.print("temperature reservoir_a,reservoir_b = ");
Serial.print(tempCmean_reservoir); Serial.print(","); Serial.print(tempCmean_air); Serial.print(tempCmean_reservoir_a); Serial.print(","); Serial.print(tempCmean_reservoir_b);
Serial.println(); Serial.println();
/*
Serial.print("sm_mean 1,2,3 = "); Serial.print("sm_mean 1,2,3 = ");
Serial.print(sm_mean1); Serial.print(","); Serial.print(sm_mean1); Serial.print(",");
Serial.print(sm_mean2); Serial.print(","); Serial.print(sm_mean2); Serial.print(",");
Serial.print(sm_mean3); Serial.print(sm_mean3);
Serial.println(); Serial.println();
*/
/* /*
Serial.print("sm_mean 1,2,3 = "); Serial.print("sm_mean 1,2,3 = ");
@ -231,7 +237,8 @@ void loop() {
//Serial.print(getMax(sm_mean3array,SM_SIZE)); Serial.println(); //Serial.print(getMax(sm_mean3array,SM_SIZE)); Serial.println();
*/ */
Serial.print("Flow = "); Serial.print(flow); Serial.print("Flow a= "); Serial.print(flow_a);
Serial.print(", b= "); Serial.print(flow_b);
Serial.println(); Serial.println();
Serial.print("EC ec_calib_adc,ec_adc_A,ec_adc_adjusted_A = "); Serial.print("EC ec_calib_adc,ec_adc_A,ec_adc_adjusted_A = ");
@ -274,15 +281,16 @@ void loop() {
enableTiming=false; enableTiming=false;
} }
if (tempCmean_reservoir!=DEVICE_DISCONNECTED_C) { if (tempCmean_reservoir_a!=DEVICE_DISCONNECTED_C) {
publishValueTimed("temperature/reservoir",tempCmean_reservoir,2,timing_temperature_reservoir,loopmillis); publishValueTimed("nft/temperature/reservoir",tempCmean_reservoir_a,2,timing_temperature_reservoir_a,loopmillis);
} }
if (tempCmean_air!=DEVICE_DISCONNECTED_C) { if (tempCmean_reservoir_b!=DEVICE_DISCONNECTED_C) {
publishValueTimed("temperature/air",tempCmean_air,2,timing_temperature_air,loopmillis); publishValueTimed("db/temperature/reservoir",tempCmean_reservoir_b,2,timing_temperature_reservoir_b,loopmillis);
} }
if (tempCmean_case!=DEVICE_DISCONNECTED_C) { if (tempCmean_case!=DEVICE_DISCONNECTED_C) {
publishValueTimed("temperature/case",tempCmean_case,2,timing_temperature_case,loopmillis); publishValueTimed("case/temperature",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);
} }
@ -292,8 +300,10 @@ void loop() {
if (sm_mean3!=SM_DISCONNECTED) { if (sm_mean3!=SM_DISCONNECTED) {
publishValueTimed("soilmoisture/sm3",sm_mean3,3,timing_soilmoisture_sm3,loopmillis); publishValueTimed("soilmoisture/sm3",sm_mean3,3,timing_soilmoisture_sm3,loopmillis);
} }
*/
publishValueTimed("flow/flow",flow,2,timing_flow,loopmillis); publishValueTimed("nft/flow/flow",flow_a,2,timing_flow_a,loopmillis);
publishValueTimed("db/flow/flow",flow_b,2,timing_flow_b,loopmillis);
if (waterlevel!=WATERLEVEL_UNAVAILABLE) { if (waterlevel!=WATERLEVEL_UNAVAILABLE) {
bool _published=publishValueTimed("waterlevel/height",waterlevel,2,timing_waterlevel,loopmillis); bool _published=publishValueTimed("waterlevel/height",waterlevel,2,timing_waterlevel,loopmillis);
@ -312,28 +322,28 @@ void loop() {
//Probe A //Probe A
if (ec_adc_A!=0) { if (ec_adc_A!=0) {
publishValue("ecA/adc",ec_adc_A,0); publishValue("nft/ec/adc",ec_adc_A,0);
} }
if (ec_adc_adjusted_A!=0) { if (ec_adc_adjusted_A!=0) {
publishValue("ecA/adcadjusted",ec_adc_adjusted_A,0); publishValue("nft/ec/adcadjusted",ec_adc_adjusted_A,0);
} }
if (ec_A!=EC_UNAVAILABLE){ if (ec_A!=EC_UNAVAILABLE){
publishValue("ecA/ec",ec_A,0); publishValue("nft/ec/ec",ec_A,0);
publishValue("ecA/sc",ec25_A,0); publishValue("nft/ec/sc",ec25_A,0);
} }
//Probe B //Probe B
if (ec_adc_B!=0) { if (ec_adc_B!=0) {
publishValue("ecB/adc",ec_adc_B,0); publishValue("nft/ec/adc",ec_adc_B,0);
} }
if (ec_adc_adjusted_B!=0) { if (ec_adc_adjusted_B!=0) {
publishValue("ecB/adcadjusted",ec_adc_adjusted_B,0); publishValue("db/ec/adcadjusted",ec_adc_adjusted_B,0);
} }
if (ec_B!=EC_UNAVAILABLE){ if (ec_B!=EC_UNAVAILABLE){
publishValue("ecB/ec",ec_B,0); publishValue("db/ec/ec",ec_B,0);
publishValue("ecB/sc",ec25_B,0); publishValue("db/ec/sc",ec25_B,0);
} }
} }
@ -354,13 +364,6 @@ void loop() {
}*/ }*/
} }
} }
} }