Compare commits

...

2 Commits

Author SHA1 Message Date
interfisch fe93d9eff6 make temperature request async 2024-06-27 20:39:12 +02:00
interfisch b11e3dc9b2 enable waterlevel again 2024-06-27 20:38:59 +02:00
3 changed files with 80 additions and 14 deletions

View File

@ -113,9 +113,12 @@ void temperature_loop(unsigned long loopmillis) {
Serial.println("Warn: Request Temperatures Timeout!");
publishInfo("error/temperature","Warn: Request Temperatures Timeout!");
flag_requestTemperatures=false;
last_read_ds18b20=loopmillis;
}
if (!flag_requestTemperatures) {
sensors.requestTemperatures(); //this takes ~600ms
sensors.setWaitForConversion(false); //make async
sensors.requestTemperatures(); //this takes ~600ms in non async mode. about 2ms in async mode
sensors.setWaitForConversion(true);
flag_requestTemperatures=true;
}
if (sensors.isConversionComplete()) {

View File

@ -52,28 +52,29 @@ monitor_speed = 115200
build_flags=
'-D CLIENT_ID="hydroponic-DB"'
-D PIN_BUTTON
'-D CLIENT_ID="hydroponic-Test"'
-D PIN_BUTTON=12
-D EC_PIN_RELAY_PROBE
-D EC_PIN_FREQ
-D EC_PIN_RELAY_PROBE=6
-D EC_PIN_FREQ=5
-D EC_CALIBRATION_POLYNOM={8.718380956513695,-0.026463423062356713,3.425216464107108e-05,-4.069826379094172e-09,2.478900495960682e-13}
-D EC_CALIBRATION_LINEARIZE_BELOW_ADC=2000
-D EC_CALIBRATION_LINEAR_LOWADC=728
-D EC_CALIBRATION_LINEAR_LOWEC=0
-D FLOW_PIN
-D ONE_WIRE_BUS_PIN
-D FLOW_PIN=16
-D ONE_WIRE_BUS_PIN=18
-D THERMOMETER_ADDR_RESERVOIR={0x28,0xFF,0x30,0xBA,0x85,0x16,0x03,0xB5}
-D THERMOMETER_ADDR_CASE
-D THERMOMETER_ADDR_CASE={0x28,0xFF,0x30,0xBA,0x85,0x16,0x03,0xB6}
-D PIN_SDA
-D PIN_SCL
-D PIN_SDA=1
-D PIN_SCL=2
lib_deps =
https://github.com/milesburton/Arduino-Temperature-Control-Library/
https://github.com/emilv/ArduinoSort/
robtillaart/ADS1X15@^0.3.9
256dpi/MQTT@^2.5.2
pololu/VL53L0X@^1.3.1
pololu/VL53L0X@^1.3.1
adafruit/Adafruit NeoPixel

View File

@ -48,14 +48,36 @@ ADS1115 ADS(0x48);
//#include "soilmoisture.h"
#ifdef PIN_NEOPIXEL
#include <Adafruit_NeoPixel.h>
Adafruit_NeoPixel pixels(1, PIN_NEOPIXEL, NEO_GRB + NEO_KHZ800);
#endif
void setup() {
pinMode(PIN_BUTTON,INPUT_PULLUP);
#ifdef PIN_LED
pinMode(PIN_LED,OUTPUT);
digitalWrite(PIN_LED,LOW);
#endif
#if defined(NEOPIXEL_POWER)
// If this board has a power control pin, we must set it to output and high
// in order to enable the NeoPixels. We put this in an #if defined so it can
// be reused for other boards without compilation errors
pinMode(NEOPIXEL_POWER, OUTPUT);
digitalWrite(NEOPIXEL_POWER, HIGH);
#endif
#ifdef PIN_NEOPIXEL
pixels.begin();
pixels.setBrightness(100); // not so bright
pixels.clear();
#endif
Serial.begin(115200);
if (mqtt) {
WiFi.begin(ssid, pass);
@ -66,7 +88,7 @@ void setup() {
Serial.println("Setup Waterlevel");
//waterlevel_setup(); //Temporarily disabled
waterlevel_setup();
//init ADS1115
@ -127,7 +149,7 @@ void loop() {
temperature_loop(loopmillis);
if (!ec_measurementRunning()){ //skip tof read when ec measurement running, because vlxx sensor reading takes quite long per cycle
//Temporarily disabled waterlevel_loop(loopmillis);
waterlevel_loop(loopmillis);
}
flow_loop(loopmillis);
@ -141,17 +163,35 @@ void loop() {
if (!digitalRead(PIN_BUTTON)) { //button pressed
valueError=false;
Serial.println("Reset ValueError flag by user");
#ifdef PIN_LED
digitalWrite(PIN_LED,valueError); //set led before delay to blink if error persists
#endif
#ifdef PIN_NEOPIXEL
pixels.setPixelColor(0, pixels.Color(255*valueError, 0,0));
pixels.show();
#endif
delay(100);
}
static bool last_valueError=true;
if (!valuesStabilized) { //if values are not okay since boot
#ifdef PIN_LED
digitalWrite(PIN_LED,(loopmillis/250)%2==0); //blink led
#endif
#ifdef PIN_NEOPIXEL
pixels.setPixelColor(0, pixels.Color((loopmillis/250)%2==0,(loopmillis/250)%2==0,0));
pixels.show();
#endif
}else{ //LED shows valueError flag status when values were okay once
if (last_valueError!=valueError) { //update led if valueerror flag changed
last_valueError=valueError;
#ifdef PIN_LED
digitalWrite(PIN_LED,valueError);
#endif
#ifdef PIN_NEOPIXEL
pixels.setPixelColor(0, pixels.Color((loopmillis/250)%2==0,(loopmillis/250)%2==0,0));
pixels.show();
#endif
}
}
}
@ -162,16 +202,32 @@ void loop() {
if (eccalibrationoutput && !digitalRead(PIN_BUTTON) && !getReading) { //Calibration UI
if (!isValueArrayOK(ec_calib_array,EC_CALIB_ARRAY_SIZE,EC_ADC_UNAVAILABLE)) {
for (uint8_t blink=0;blink<5;blink++) {
#ifdef PIN_LED
digitalWrite(PIN_LED,HIGH);
delay(100);
digitalWrite(PIN_LED,LOW);
delay(100);
#endif
#ifdef PIN_NEOPIXEL
pixels.setPixelColor(0, pixels.Color(0,0,255));
pixels.show();
delay(100);
pixels.setPixelColor(0, pixels.Color(0,0,0));
pixels.show();
delay(100);
#endif
}
}else{
getReading=true;
force_ec_measurement=true;
ec_flag_measurement_available=false;
#ifdef PIN_LED
digitalWrite(PIN_LED,HIGH);
#endif
#ifdef PIN_NEOPIXEL
pixels.setPixelColor(0, pixels.Color(0,255,0));
pixels.show();
#endif
}
}
@ -180,7 +236,13 @@ void loop() {
ec_flag_measurement_available=false;
getReading=false;
#ifdef PIN_LED
digitalWrite(PIN_LED,LOW);
#endif
#ifdef PIN_NEOPIXEL
pixels.setPixelColor(0, pixels.Color(0,0,0));
pixels.show();
#endif
Serial.print(loopmillis); Serial.print(",");
Serial.print(tempCmean_reservoir); Serial.print(",");
Serial.print(ec_calib_adc); Serial.print(",");