fix waterlevel calculation and calibrate
This commit is contained in:
parent
92ec32304c
commit
5571267f6c
|
@ -23,8 +23,9 @@ float watervolume=WATERLEVEL_UNAVAILABLE; //calculated Volume in Reservoir
|
||||||
|
|
||||||
|
|
||||||
//Calibration
|
//Calibration
|
||||||
float waterlevel_calib_offset_measured=0; //Sollwert
|
float waterlevel_calib_offset_measured=86; //Sollwert
|
||||||
float waterlevel_calib_offset_sensor=0; //Istwert
|
float waterlevel_calib_offset_sensor=78; //Istwert
|
||||||
|
//raw reading is 78mm, ruler reads 86mm. VL8160 sensor is 169mm above bottom of reservoir.
|
||||||
|
|
||||||
float waterlevel_calib_reservoirArea=27*36.5; //area in cm^2
|
float waterlevel_calib_reservoirArea=27*36.5; //area in cm^2
|
||||||
|
|
||||||
|
@ -32,8 +33,15 @@ float waterlevel_calib_reservoirArea=27*36.5; //area in cm^2
|
||||||
float waterlevel_heightToVolume(float distance);
|
float waterlevel_heightToVolume(float distance);
|
||||||
|
|
||||||
|
|
||||||
|
mqttValueTiming timing_waterlevel;
|
||||||
|
|
||||||
void waterlevel_setup() {
|
void waterlevel_setup() {
|
||||||
|
|
||||||
|
timing_waterlevel.minchange=0.0;
|
||||||
|
timing_waterlevel.maxchange=3.0;
|
||||||
|
timing_waterlevel.mintime=30*000;
|
||||||
|
timing_waterlevel.maxtime=60*60*1000;
|
||||||
|
|
||||||
Wire.begin();
|
Wire.begin();
|
||||||
|
|
||||||
sensor.init();
|
sensor.init();
|
||||||
|
@ -65,12 +73,12 @@ void waterlevel_loop(unsigned long loopmillis) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isValueArrayOKf(waterlevelMean_array,WATERLEVELMEAN_SIZE,WATERLEVEL_UNAVAILABLE)){
|
if (isValueArrayOKf(waterlevelMean_array,WATERLEVELMEAN_SIZE,WATERLEVEL_UNAVAILABLE)){
|
||||||
//float _distance=getFilteredf(waterlevelMean_array,WATERLEVELMEAN_SIZE,WATERLEVELMEAN_FILTER_CUTOFF);
|
float _filteredDistance=getFilteredf(waterlevelMean_array,WATERLEVELMEAN_SIZE,WATERLEVELMEAN_FILTER_CUTOFF);
|
||||||
float _distance=getMaxf(waterlevelMean_array,WATERLEVELMEAN_SIZE);
|
|
||||||
|
|
||||||
//Invert distance and offset
|
//Invert distance and offset
|
||||||
waterlevel=distance-(waterlevel_calib_offset_sensor+waterlevel_calib_offset_measured);
|
waterlevel=(waterlevel_calib_offset_sensor+waterlevel_calib_offset_measured)-_filteredDistance;
|
||||||
watervolume=waterlevel_heightToVolume(_distance);
|
watervolume=waterlevel_heightToVolume(waterlevel);
|
||||||
|
|
||||||
//float _meanWaterlevel=getMeanf(waterlevelMean,WATERLEVELMEAN_SIZE);
|
//float _meanWaterlevel=getMeanf(waterlevelMean,WATERLEVELMEAN_SIZE);
|
||||||
//Serial.print("\t Dist="); Serial.print(_filteredWaterlevel); Serial.print("mm"); Serial.print("(+- "); Serial.print((getMaxf(waterlevelMean,WATERLEVELMEAN_SIZE)-getMinf(waterlevelMean,WATERLEVELMEAN_SIZE))/2.0); Serial.print(")"); Serial.print(" [mean="); Serial.print(_meanWaterlevel); Serial.print("]");
|
//Serial.print("\t Dist="); Serial.print(_filteredWaterlevel); Serial.print("mm"); Serial.print("(+- "); Serial.print((getMaxf(waterlevelMean,WATERLEVELMEAN_SIZE)-getMinf(waterlevelMean,WATERLEVELMEAN_SIZE))/2.0); Serial.print(")"); Serial.print(" [mean="); Serial.print(_meanWaterlevel); Serial.print("]");
|
||||||
|
|
|
@ -29,7 +29,7 @@ bool enableTiming=true;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void publishValueTimed(String topic,float value,uint8_t decimals,mqttValueTiming &mqttvt,unsigned long loopmillis);
|
bool publishValueTimed(String topic,float value,uint8_t decimals,mqttValueTiming &mqttvt,unsigned long loopmillis);
|
||||||
void publishValue(String topic,float value,uint8_t decimals);
|
void publishValue(String topic,float value,uint8_t decimals);
|
||||||
|
|
||||||
void connect() {
|
void connect() {
|
||||||
|
@ -97,7 +97,7 @@ bool mqtt_loop(unsigned long loopmillis) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void publishValueTimed(String topic,float value,uint8_t decimals,mqttValueTiming &mqttvt,unsigned long loopmillis) {
|
bool publishValueTimed(String topic,float value,uint8_t decimals,mqttValueTiming &mqttvt,unsigned long loopmillis) {
|
||||||
unsigned long timediff=loopmillis-mqttvt.lasttime;
|
unsigned long timediff=loopmillis-mqttvt.lasttime;
|
||||||
float valuediff=abs(value-mqttvt.lastvalue);
|
float valuediff=abs(value-mqttvt.lastvalue);
|
||||||
valuediff=constrain(valuediff,mqttvt.minchange,mqttvt.maxchange);
|
valuediff=constrain(valuediff,mqttvt.minchange,mqttvt.maxchange);
|
||||||
|
@ -110,7 +110,9 @@ void publishValueTimed(String topic,float value,uint8_t decimals,mqttValueTiming
|
||||||
mqttvt.lasttime=loopmillis;
|
mqttvt.lasttime=loopmillis;
|
||||||
mqttvt.lastvalue=value;
|
mqttvt.lastvalue=value;
|
||||||
publishValue(topic,value,decimals);
|
publishValue(topic,value,decimals);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void publishValue(String topic,float value,uint8_t decimals) {
|
void publishValue(String topic,float value,uint8_t decimals) {
|
||||||
|
|
|
@ -8,7 +8,7 @@ import matplotlib.pyplot as plt
|
||||||
from pandas import *
|
from pandas import *
|
||||||
|
|
||||||
# reading CSV file
|
# reading CSV file
|
||||||
data = read_csv("20230509_NaCl_raw.csv")
|
data = read_csv("20230620_NaCl_raw.csv")
|
||||||
|
|
||||||
# converting column data to list
|
# converting column data to list
|
||||||
#solutionAdded = data['solutionAdded'].tolist() #in ml
|
#solutionAdded = data['solutionAdded'].tolist() #in ml
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
#include "wifi_functions.h"
|
#include "wifi_functions.h"
|
||||||
|
|
||||||
bool debug=true; //print Serial information
|
bool debug=true; //print Serial information
|
||||||
bool mqtt=false;
|
bool mqtt=true;
|
||||||
bool eccalibrationoutput=false; //serial output for ec calibration
|
bool eccalibrationoutput=false; //serial output for ec calibration
|
||||||
|
|
||||||
|
|
||||||
|
@ -263,6 +263,13 @@ void loop() {
|
||||||
|
|
||||||
publishValueTimed("flow/flow",flow,2,timing_flow,loopmillis);
|
publishValueTimed("flow/flow",flow,2,timing_flow,loopmillis);
|
||||||
|
|
||||||
|
if (waterlevel!=WATERLEVEL_UNAVAILABLE) {
|
||||||
|
bool _published=publishValueTimed("waterlevel/height",waterlevel,2,timing_waterlevel,loopmillis);
|
||||||
|
if (_published) { //use height for timing. send calculated volume with it
|
||||||
|
publishValue("waterlevel/volume",watervolume,2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if (ec_flag_measurement_available){
|
if (ec_flag_measurement_available){
|
||||||
ec_flag_measurement_available=false;
|
ec_flag_measurement_available=false;
|
||||||
|
|
Loading…
Reference in New Issue