Compare commits

..

No commits in common. '91844e4f665df622c0ec873809941dbabe1f0650' and '33e0c1e26a115a725d722e4828e0ceaebe3fa892' have entirely different histories.

@ -22,12 +22,11 @@ DallasTemperature sensor(&oneWire);
//========== Init variables ========== //========== Init variables ==========
float avgTemperature; float temperature;
String metrics; String metrics;
bool heating; bool heating;
float reqTemp = 21.5; float reqTemp = 21.5;
float offset = 0.25; float offset = 0.25;
float correction[3] = {CORRECTION1, CORRECTION2, CORRECTION3};
//================================= //=================================
@ -129,7 +128,7 @@ void setup() {
String repply; String repply;
if(request->hasParam("temp")) { if(request->hasParam("temp")) {
repply = String(avgTemperature); repply = String(temperature);
}else if(request->hasParam("relay")){ }else if(request->hasParam("relay")){
repply = String(heating); repply = String(heating);
}else if(THERMOSTAT && request->hasParam("reqtemp")){ }else if(THERMOSTAT && request->hasParam("reqtemp")){
@ -166,53 +165,33 @@ void notFound(AsyncWebServerRequest *request) {
} }
void thermostatCheck(){ void thermostatCheck(){
if (avgTemperature <= (reqTemp - offset)) { if(temperature < (reqTemp - offset)){
heating = 1; heating = 1;
digitalWrite(RELAY_PIN, !heating); digitalWrite(RELAY_PIN, !heating);
} else if (avgTemperature >= (reqTemp + offset)) { }else if(temperature > (reqTemp + offset)){
heating = 0; heating = 0;
digitalWrite(RELAY_PIN, !heating); digitalWrite(RELAY_PIN, !heating);
} }
} }
void readSensor() { void readSensor() {
uint8_t ds18Count = sensor.getDS18Count(); float tempC = sensor.getTempCByIndex(0);
float tempC[ds18Count];
float temperature[ds18Count];
float avgTemperature;
int savedTemperatures = 0;
for (int i = 0; i < ds18Count; i++) { if(tempC != DEVICE_DISCONNECTED_C){
tempC[i] = sensor.getTempCByIndex(i); // read the actual temperature after it's been converted
if (tempC[i] != DEVICE_DISCONNECTED_C) { temperature = tempC + CORRECTION;
temperature[i] = tempC[i] + correction[i]; // do what you need with the temperature here
avgTemperature += temperature[i];
savedTemperatures++;
} }
} metrics = "temp ";
metrics += temperature;
avgTemperature = avgTemperature / savedTemperatures; metrics += "\nraw_temp ";
metrics += tempC;
for (int i = 0; i < ds18Count; i++) {
metrics += "\ntemp{device=\"";
metrics += i;
metrics += "\"} ";
metrics += temperature[i];
}
for (int i = 0; i < ds18Count; i++) {
metrics += "\nraw_temp{device=\"";
metrics += i;
metrics += "\"} ";
metrics += tempC[i];
}
if (THERMOSTAT) {
metrics += "\nheating "; metrics += "\nheating ";
metrics += heating; metrics += heating;
metrics += "\nreqTemp "; metrics += "\nreqTemp ";
metrics += reqTemp; metrics += reqTemp;
metrics += "\noffset "; metrics += "\noffset ";
metrics += offset; metrics += offset;
}
} }