defines for sensors
This commit is contained in:
parent
9f95dfea15
commit
b5b9c1b221
3 changed files with 97 additions and 36 deletions
|
@ -31,16 +31,19 @@ uint16_t tempCmean_pos=0;
|
|||
//DeviceAddress thermometerAir={0x28,0xFF,0x6C,0x1C,0x72,0x16,0x05,0x8B};
|
||||
//DeviceAddress thermometerReservoirA={0x28,0xFF,0x6F,0x19,0x72,0x16,0x05,0x44}; //NFT
|
||||
//DeviceAddress thermometerReservoirB={0x28,0xFF,0x30,0xBA,0x85,0x16,0x03,0xB5}; //DB
|
||||
#ifdef THERMOMETER_ADDR_RESERVOIR
|
||||
DeviceAddress thermometerReservoir=THERMOMETER_ADDR_RESERVOIR;
|
||||
float tempC_reservoir; //last reading
|
||||
float tempCmean_reservoir_array[TEMPMEAN_SIZE];
|
||||
float tempCmean_reservoir=DEVICE_DISCONNECTED_C;
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef THERMOMETER_ADDR_CASE
|
||||
DeviceAddress thermometerCase=THERMOMETER_ADDR_CASE;
|
||||
float tempC_case; //last reading
|
||||
float tempCmean_case_array[TEMPMEAN_SIZE];
|
||||
float tempCmean_case=DEVICE_DISCONNECTED_C;
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
@ -50,17 +53,21 @@ void temperature_setup() {
|
|||
timing_temperature_reservoir.maxchange=0.5;
|
||||
timing_temperature_reservoir.mintime=2*1000;
|
||||
timing_temperature_reservoir.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
|
||||
for (uint16_t i=0;i<TEMPMEAN_SIZE;i++) {
|
||||
#ifdef THERMOMETER_ADDR_RESERVOIR
|
||||
tempCmean_reservoir_array[i]=-127;
|
||||
#endif
|
||||
#ifdef THERMOMETER_ADDR_CASE
|
||||
tempCmean_case_array[i]=-127;
|
||||
#endif
|
||||
}
|
||||
|
||||
sensors.begin();
|
||||
|
@ -99,8 +106,12 @@ void temperature_setup() {
|
|||
|
||||
}
|
||||
|
||||
#ifdef THERMOMETER_ADDR_RESERVOIR
|
||||
sensors.setResolution(thermometerReservoir, TEMPERATURE_PRECISION);
|
||||
#endif
|
||||
#ifdef THERMOMETER_ADDR_CASE
|
||||
sensors.setResolution(thermometerCase, TEMPERATURE_PRECISION);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
@ -127,6 +138,7 @@ void temperature_loop(unsigned long loopmillis) {
|
|||
flag_requestTemperatures=false;
|
||||
last_read_ds18b20=loopmillis;
|
||||
|
||||
#ifdef THERMOMETER_ADDR_RESERVOIR
|
||||
tempC_reservoir = sensors.getTempC(thermometerReservoir);
|
||||
if (tempC_reservoir == DEVICE_DISCONNECTED_C)
|
||||
{
|
||||
|
@ -140,8 +152,8 @@ void temperature_loop(unsigned long loopmillis) {
|
|||
tempCmean_reservoir=DEVICE_DISCONNECTED_C;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
#ifdef THERMOMETER_ADDR_CASE
|
||||
tempC_case = sensors.getTempC(thermometerCase);
|
||||
if (tempC_case == DEVICE_DISCONNECTED_C)
|
||||
{
|
||||
|
@ -155,6 +167,7 @@ void temperature_loop(unsigned long loopmillis) {
|
|||
tempCmean_case=DEVICE_DISCONNECTED_C;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
tempCmean_pos++;
|
||||
tempCmean_pos%=TEMPMEAN_SIZE;
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
; Please visit documentation for the other options and examples
|
||||
; https://docs.platformio.org/page/projectconf.html
|
||||
|
||||
[env:esp32doit-devkit-v1_NFT_2024]
|
||||
[env:esp32doit-devkit-v1_reservoir]
|
||||
platform = espressif32
|
||||
board = esp32doit-devkit-v1
|
||||
framework = arduino
|
||||
|
@ -17,35 +17,25 @@ monitor_speed = 115200
|
|||
monitor_port = /dev/ttyUSB0
|
||||
|
||||
build_flags=
|
||||
'-D CLIENT_ID="hydroponic-NFT"'
|
||||
'-D CLIENT_ID="waterreservoir"'
|
||||
-D PIN_BUTTON=12
|
||||
-D PIN_LED=13
|
||||
-D EC_PIN_RELAY_PROBE=27
|
||||
-D EC_PIN_FREQ=5
|
||||
-D EC_CALIBRATION_POLYNOM={18.785904241636743,-0.04069178351449846,3.528797358514823e-05,-4.214254847500995e-09,2.543662736303669e-13}
|
||||
-D EC_CALIBRATION_LINEARIZE_BELOW_ADC=2000
|
||||
-D EC_CALIBRATION_LINEAR_LOWADC=728
|
||||
-D EC_CALIBRATION_LINEAR_LOWEC=0
|
||||
-D EC_REFERENCE_ADC=6016.88
|
||||
|
||||
-D FLOW_PIN=16
|
||||
-D ONE_WIRE_BUS_PIN=18
|
||||
-D THERMOMETER_ADDR_RESERVOIR={0x28,0xFF,0x6F,0x19,0x72,0x16,0x05,0x44}
|
||||
-D THERMOMETER_ADDR_CASE={0x10,0x7E,0x22,0x99,0x01,0x08,0x00,0xA4}
|
||||
-D PIN_SDA=21
|
||||
-D PIN_SCL=22
|
||||
-D WATERLEVEL_OFFSET=500.0
|
||||
-D WATERLEVEL_FACTOR=-1.0
|
||||
-D RES_AREA=20*20*3.1416
|
||||
|
||||
-D WATERLEVELSENSOR_VL53L0X
|
||||
-D WATERLEVELSENSOR_VL53L1X
|
||||
|
||||
lib_deps =
|
||||
https://github.com/milesburton/Arduino-Temperature-Control-Library/
|
||||
https://github.com/emilv/ArduinoSort/
|
||||
robtillaart/ADS1X15@^0.3.9
|
||||
256dpi/MQTT@^2.5.1
|
||||
pololu/VL53L0X@^1.3.1
|
||||
pololu/VL53L1X@^1.3.1
|
||||
|
||||
|
||||
|
||||
|
|
92
src/main.cpp
92
src/main.cpp
|
@ -30,24 +30,30 @@ bool valuesStabilized=false; //gets set true when values are stable (avaeraging
|
|||
|
||||
|
||||
// ######## Temperature
|
||||
#ifdef ONE_WIRE_BUS_PIN
|
||||
#include "temperature.h"
|
||||
|
||||
#endif
|
||||
|
||||
// ######## Water Level
|
||||
#ifdef RES_AREA
|
||||
#include "waterlevel.h"
|
||||
|
||||
#endif
|
||||
|
||||
// ######## EC
|
||||
#ifdef EC_CALIBRATION_POLYNOM
|
||||
ADS1115 ADS(0x48);
|
||||
bool adsenabled=true;
|
||||
#include "ec.h"
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// ######## Flow Rate
|
||||
#ifdef FLOW_PIN
|
||||
#include "flow.h"
|
||||
#endif
|
||||
|
||||
// ######## Soilmoisture
|
||||
//#include "soilmoisture.h"
|
||||
|
@ -106,18 +112,21 @@ void setup() {
|
|||
}
|
||||
|
||||
|
||||
|
||||
#ifdef PIN_SDA
|
||||
Wire.begin(PIN_SDA,PIN_SCL);
|
||||
Serial.print("I2C Clock Speed=");
|
||||
Serial.println(Wire.getClock());
|
||||
|
||||
i2cscan();
|
||||
#endif
|
||||
|
||||
#ifdef RES_AREA
|
||||
Serial.println("Setup Waterlevel");
|
||||
waterlevel_setup();
|
||||
#endif
|
||||
|
||||
|
||||
//init ADS1115
|
||||
#ifdef EC_CALIBRATION_POLYNOM
|
||||
if (!ADS.begin()) {
|
||||
Serial.println("Error:"); delay(2000); Serial.println("ADS1115 Init Error!");
|
||||
if (mqtt){
|
||||
|
@ -128,17 +137,21 @@ void setup() {
|
|||
if (adsenabled){
|
||||
ADS.setGain(0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Serial.println("Setup EC");
|
||||
ec_setup();
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef ONE_WIRE_BUS_PIN
|
||||
Serial.println("Setup Temperature");
|
||||
temperature_setup();
|
||||
#endif
|
||||
|
||||
#ifdef FLOW_PIN
|
||||
Serial.println("Setup Flow");
|
||||
flow_setup();
|
||||
#endif
|
||||
|
||||
/*
|
||||
Serial.println("Setup Soilmoisture");
|
||||
|
@ -148,6 +161,7 @@ void setup() {
|
|||
Serial.println("Finished Setup");
|
||||
delay(200);
|
||||
|
||||
#ifdef EC_CALIBRATION_POLYNOM
|
||||
//Test adc to ec function output
|
||||
if (eccalibrationoutput) {
|
||||
Serial.println();
|
||||
|
@ -161,6 +175,7 @@ void setup() {
|
|||
Serial.println("Waiting 10 seconds because eccalibrationoutput is enabled");
|
||||
delay(10000);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
@ -173,22 +188,32 @@ void loop() {
|
|||
unsigned long loopmillis=millis();
|
||||
enableTiming=true; //reactivate
|
||||
|
||||
|
||||
#ifdef EC_CALIBRATION_POLYNOM
|
||||
ec_loop(loopmillis);
|
||||
#endif
|
||||
|
||||
#ifdef ONE_WIRE_BUS_PIN
|
||||
temperature_loop(loopmillis);
|
||||
|
||||
#endif
|
||||
|
||||
#if defined(EC_CALIBRATION_POLYNOM) && defined(RES_AREA)
|
||||
if (!ec_measurementRunning()){ //skip tof read when ec measurement running, because vlxx sensor reading takes quite long per cycle
|
||||
waterlevel_loop(loopmillis);
|
||||
}
|
||||
#elif defined(RES_AREA)
|
||||
waterlevel_loop(loopmillis);
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef FLOW_PIN
|
||||
flow_loop(loopmillis);
|
||||
|
||||
#endif
|
||||
//sm_loop(loopmillis);
|
||||
|
||||
|
||||
static bool getReading=false;
|
||||
|
||||
|
||||
if (!eccalibrationoutput) { //Is in normal operation mode
|
||||
if (!digitalRead(PIN_BUTTON)) { //button pressed
|
||||
valueError=false;
|
||||
|
@ -228,7 +253,7 @@ void loop() {
|
|||
|
||||
|
||||
|
||||
|
||||
#ifdef EC_CALIBRATION_POLYNOM
|
||||
if (eccalibrationoutput && !digitalRead(PIN_BUTTON) && !getReading) { //Calibration UI . Button Pressed
|
||||
if (!isValueArrayOK(ec_calib_array,EC_CALIB_ARRAY_SIZE,EC_ADC_UNAVAILABLE)) { //Calibration Array filled?
|
||||
for (uint8_t blink=0;blink<5;blink++) { //Error Blink
|
||||
|
@ -281,6 +306,7 @@ void loop() {
|
|||
Serial.print(ec_adc_adjusted);
|
||||
Serial.println();
|
||||
}
|
||||
#endif
|
||||
|
||||
if (loopmillis>last_check+2000) { //check values
|
||||
|
||||
|
@ -289,31 +315,46 @@ void loop() {
|
|||
|
||||
bool _noErrorsDuringLoop=true;
|
||||
|
||||
if (tempCmean_reservoir==DEVICE_DISCONNECTED_C || tempCmean_case==DEVICE_DISCONNECTED_C) {
|
||||
#ifdef ONE_WIRE_BUS_PIN
|
||||
bool tempdevdisconnected=false;
|
||||
#ifdef THERMOMETER_ADDR_RESERVOIR
|
||||
tempdevdisconnected|= (tempCmean_reservoir==DEVICE_DISCONNECTED_C);
|
||||
#endif
|
||||
#ifdef THERMOMETER_ADDR_RESERVOIR
|
||||
tempdevdisconnected|= (tempCmean_case==DEVICE_DISCONNECTED_C);
|
||||
#endif
|
||||
|
||||
if (tempdevdisconnected) {
|
||||
if (!valueError && valuesStabilized) { //error just appeared
|
||||
#ifdef THERMOMETER_ADDR_RESERVOIR
|
||||
if (tempCmean_reservoir==DEVICE_DISCONNECTED_C) {
|
||||
Serial.println("valueError tempCmean_reservoir");
|
||||
if (mqtt){
|
||||
publishInfo("error/temperature","valueError tempCmean_reservoir");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#ifdef THERMOMETER_ADDR_CASE
|
||||
if (tempCmean_case==DEVICE_DISCONNECTED_C) {
|
||||
Serial.println("valueError tempCmean_case");
|
||||
if (mqtt){
|
||||
publishInfo("error/temperature","valueError tempCmean_case");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
}
|
||||
valueError=true;
|
||||
_noErrorsDuringLoop=false;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
if (sm_mean1==SM_DISCONNECTED || sm_mean2==SM_DISCONNECTED) {
|
||||
valueError=true;
|
||||
}*/
|
||||
#ifdef EC_CALIBRATION_POLYNOM
|
||||
if (ec==EC_UNAVAILABLE){
|
||||
if (!valueError && valuesStabilized) { //error just appeared
|
||||
if (ec==EC_UNAVAILABLE){
|
||||
|
@ -326,10 +367,11 @@ void loop() {
|
|||
valueError=true;
|
||||
_noErrorsDuringLoop=false;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
#ifdef RES_AREA
|
||||
if (distance_unsuccessful_count>20) {
|
||||
if (!valueError && valuesStabilized) { //error just appeared
|
||||
Serial.println("valueError distance");
|
||||
|
@ -340,6 +382,7 @@ void loop() {
|
|||
valueError=true;
|
||||
_noErrorsDuringLoop=false;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
@ -354,12 +397,16 @@ void loop() {
|
|||
Serial.println("_______________________");
|
||||
Serial.print(millis()/1000.0,2); Serial.println(":");
|
||||
|
||||
#ifdef THERMOMETER_ADDR_RESERVOIR
|
||||
Serial.print("temperature reservoir = ");
|
||||
Serial.print(tempCmean_reservoir);
|
||||
Serial.println();
|
||||
#endif
|
||||
#ifdef THERMOMETER_ADDR_CASE
|
||||
Serial.print("temperature case = ");
|
||||
Serial.print(tempCmean_case);
|
||||
Serial.println();
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
@ -390,9 +437,12 @@ void loop() {
|
|||
//Serial.print(getMax(sm_mean3array,SM_SIZE)); Serial.println();
|
||||
*/
|
||||
|
||||
#ifdef FLOW_PIN
|
||||
Serial.print("Flow = "); Serial.print(flow);
|
||||
Serial.println();
|
||||
#endif
|
||||
|
||||
#ifdef EC_CALIBRATION_POLYNOM
|
||||
Serial.print("EC ec_calib_adc,ec_adc,ec_adc_adjusted = ");
|
||||
Serial.print(ec_calib_adc); Serial.print(",");
|
||||
Serial.print(ec_adc); Serial.print(",");
|
||||
|
@ -402,15 +452,18 @@ void loop() {
|
|||
Serial.print(ec); Serial.print(",");
|
||||
Serial.print(ec25);
|
||||
Serial.println();
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#ifdef RES_AREA
|
||||
Serial.print("distance,Waterlevel,Volume = ");
|
||||
Serial.print(distance); Serial.print(",");
|
||||
Serial.print(waterlevel); Serial.print(",");
|
||||
Serial.print(watervolume); Serial.println();
|
||||
|
||||
Serial.println();
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
@ -423,12 +476,16 @@ void loop() {
|
|||
enableTiming=false;
|
||||
}
|
||||
|
||||
#ifdef THERMOMETER_ADDR_RESERVOIR
|
||||
if (tempCmean_reservoir!=DEVICE_DISCONNECTED_C) {
|
||||
publishValueTimed("temperature/reservoir",tempCmean_reservoir,2,timing_temperature_reservoir,loopmillis);
|
||||
}
|
||||
#endif
|
||||
#ifdef THERMOMETER_ADDR_CASE
|
||||
if (tempCmean_case!=DEVICE_DISCONNECTED_C) {
|
||||
publishValueTimed("case/temperature",tempCmean_case,2,timing_temperature_case,loopmillis);
|
||||
}
|
||||
#endif
|
||||
/*
|
||||
if (sm_mean1!=SM_DISCONNECTED) {
|
||||
publishValueTimed("soilmoisture/sm1",sm_mean1,3,timing_soilmoisture_sm1,loopmillis);
|
||||
|
@ -442,7 +499,7 @@ void loop() {
|
|||
*/
|
||||
|
||||
|
||||
|
||||
#ifdef FLOW_PIN
|
||||
static float last_flow=0;
|
||||
if (valuesStabilized){
|
||||
if (flow==0.0 && last_flow!=flow) {
|
||||
|
@ -452,18 +509,20 @@ void loop() {
|
|||
}
|
||||
last_flow=flow;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#ifdef RES_AREA
|
||||
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);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#ifdef EC_CALIBRATION_POLYNOM
|
||||
if (ec_flag_measurement_available){
|
||||
ec_flag_measurement_available=false;
|
||||
|
||||
|
@ -483,9 +542,8 @@ void loop() {
|
|||
publishValue("ec/ec",ec,0);
|
||||
publishValue("ec/sc",ec25,0);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
if (ec_adc!=0) {
|
||||
|
|
Loading…
Add table
Reference in a new issue