Last active
March 17, 2023 18:47
-
-
Save seansplayin/d4633d5a01039012867b7f5bd6785e44 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <OneWire.h> | |
#include <DallasTemperature.h> | |
#include <WiFi.h> | |
#include <WiFiClient.h> | |
#include <WiFiAP.h> | |
#include <WebServer.h> | |
#include "htmlreporting.h" | |
String htmlreporting = html; | |
#define ROLLING_ARRAY_SIZE 5 | |
#define DS_SAMPLES 5 | |
// WiFi credentials | |
const char *ssid = ""; | |
const char *password = ""; | |
// Create an instance of the web server | |
WebServer server(80); | |
// Data wire is plugged into port 2 on the ESP32 | |
#define ONE_WIRE_BUS 2 | |
// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs) | |
OneWire oneWire(ONE_WIRE_BUS); | |
// Pass oneWire reference to DallasTemperature library | |
DallasTemperature sensors(&oneWire); | |
// Temperature sensor addresses | |
DeviceAddress DSensor1 = {0x28, 0xFF, 0x56, 0xC6, 0x83, 0x16, 0x2, 0x6C}; | |
DeviceAddress DSensor2 = {0x28, 0xFF, 0x18, 0xE1, 0x8C, 0x16, 0x3, 0x56}; | |
DeviceAddress DSensor3 = {0x28, 0xFF, 0x87, 0x18, 0x8E, 0x16, 0x4, 0x6E}; | |
DeviceAddress DSensor4 = {0x28, 0xFF, 0x77, 0xA1, 0x8E, 0x16, 0x3, 0x8F}; | |
DeviceAddress DSensor5 = {0x28, 0xFF, 0x19, 0xA9, 0x8D, 0x16, 0x4, 0x8B}; | |
DeviceAddress DSensor6 = {0x28, 0xFF, 0x89, 0x7C, 0x8E, 0x16, 0x4, 0x85}; | |
DeviceAddress DSensor7 = {0x28, 0xFF, 0xF5, 0x22, 0x8C, 0x16, 0x3, 0x9A}; | |
DeviceAddress DSensor8 = {0x28, 0xFF, 0xE7, 0x26, 0x8E, 0x16, 0x4, 0x62}; | |
DeviceAddress DSensor9 = {0x28, 0xFF, 0x8, 0x45, 0x8D, 0x16, 0x4, 0x2F}; | |
DeviceAddress DSensor10 = {0x28, 0xFF, 0x10, 0x62, 0x8C, 0x16, 0x3, 0x2B}; | |
DeviceAddress DSensor11 = {0x28, 0x7C, 0xC9, 0x81, 0xE3, 0x6F, 0x3C, 0x00}; | |
//DeviceAddress DSensor11 = {0x28, 0xFF, 0x9E, 0x24, 0x8C, 0x16, 0x3, 0x20}; | |
//Pump Relay Pins | |
int lagPumpPin = 25; | |
int leadPumpPin = 32; | |
int domesticHeatingPumpPin = 33; | |
int domesticHotWaterPumpPin = 34; | |
int circulationLoopPumpPin = 35; | |
int leadPumpMode = 0; | |
int lagPumpMode = 0; | |
int domesticHotWaterPumpMode = 0; | |
int domesticHeatingPumpMode = 0; | |
int circulationLoopPumpMode = 0; | |
float PT1000 = 0.0; | |
#define PT1000Pin 4 | |
float readPT1000() { | |
// implementation code here | |
} | |
float temperature = ((analogRead(PT1000Pin) * 0.00322265625) - 1.25) / 0.005; | |
float pt1000_temps[ROLLING_ARRAY_SIZE]; | |
int pt1000_index = 0; | |
// Rolling average arrays | |
float PT1000Array[5]; | |
float DSensor1Array[5]; | |
float DSensor2Array[5]; | |
float DSensor3Array[5]; | |
float DSensor4Array[5]; | |
float DSensor5Array[5]; | |
float DSensor6Array[5]; | |
float DSensor7Array[5]; | |
float DSensor8Array[5]; | |
float DSensor9Array[5]; | |
float DSensor10Array[5]; | |
float DSensor11Array[5]; | |
float PT1000Average = 0.0; | |
float DSensor1Average = 0.0; | |
float DSensor2Average = 0.0; | |
float DSensor3Average = 0.0; | |
float DSensor4Average = 0.0; | |
float DSensor5Average = 0.0; | |
float DSensor6Average = 0.0; | |
float DSensor7Average = 0.0; | |
float DSensor8Average = 0.0; | |
float DSensor9Average = 0.0; | |
float DSensor10Average = 0.0; | |
float DSensor11Average = 0.0; | |
//float pt1000_temps[ROLLING_ARRAY_SIZE]; | |
float ds1_temps[DS_SAMPLES]; | |
float ds2_temps[DS_SAMPLES]; | |
float ds3_temps[DS_SAMPLES]; | |
float ds4_temps[DS_SAMPLES]; | |
float ds5_temps[DS_SAMPLES]; | |
float ds6_temps[DS_SAMPLES]; | |
float ds7_temps[DS_SAMPLES]; | |
float ds8_temps[DS_SAMPLES]; | |
float ds9_temps[DS_SAMPLES]; | |
float ds10_temps[DS_SAMPLES]; | |
float ds11_temps[DS_SAMPLES]; | |
// Pump control variables | |
bool leadPumpStatus = false; | |
bool lagPumpStatus = false; | |
bool domesticHotWaterPumpStatus = false; | |
bool domesticHeatingPumpStatus = false; | |
bool circulationLoopPumpStatus = false; | |
bool circulation = false; // declare the variable outside of any function | |
// Declare the functions readDSensor1() through readDSensor11() before calling them in loop() | |
// Function declaration for readDSensor1() | |
float readDSensor1(); | |
// Function declaration for readDSensor2() | |
float readDSensor2(); | |
// Function declaration for readDSensor3() | |
float readDSensor3(); | |
// Function declaration for readDSensor4() | |
float readDSensor4(); | |
// Function declaration for readDSensor5() | |
float readDSensor5(); | |
// Function declaration for readDSensor6() | |
float readDSensor6(); | |
// Function declaration for readDSensor7() | |
float readDSensor7(); | |
// Function declaration for readDSensor8() | |
float readDSensor8(); | |
// Function declaration for readDSensor9() | |
float readDSensor9(); | |
// Function declaration for readDSensor10() | |
float readDSensor10(); | |
// Function declaration for readDSensor11() | |
float readDSensor11(); | |
// Define the functions to read temperature from each DS18B20 sensor | |
float readDSensor1() { | |
// Code to read temperature from DS18B20 sensor 1 | |
sensors.requestTemperaturesByAddress(DSensor1); | |
float temperature = sensors.getTempC(DSensor1); | |
} | |
float readDSensor2() { | |
// Code to read temperature from DS18B20 sensor 2 | |
sensors.requestTemperaturesByAddress(DSensor2); | |
float temperature = sensors.getTempC(DSensor2); | |
} | |
float readDSensor3() { | |
// Code to read temperature from DS18B20 sensor 3 | |
sensors.requestTemperaturesByAddress(DSensor3); | |
float temperature = sensors.getTempC(DSensor3); | |
} | |
float readDSensor4() { | |
// Code to read temperature from DS18B20 sensor 4 | |
sensors.requestTemperaturesByAddress(DSensor4); | |
float temperature = sensors.getTempC(DSensor4); | |
} | |
float readDSensor5() { | |
// Code to read temperature from DS18B20 sensor 5 | |
sensors.requestTemperaturesByAddress(DSensor5); | |
float temperature = sensors.getTempC(DSensor5); | |
} | |
float readDSensor6() { | |
// Code to read temperature from DS18B20 sensor 6 | |
sensors.requestTemperaturesByAddress(DSensor6); | |
float temperature = sensors.getTempC(DSensor6); | |
} | |
float readDSensor7() { | |
// Code to read temperature from DS18B20 sensor 7 | |
sensors.requestTemperaturesByAddress(DSensor7); | |
float temperature = sensors.getTempC(DSensor7); | |
} | |
float readDSensor8() { | |
// Code to read temperature from DS18B20 sensor 8 | |
sensors.requestTemperaturesByAddress(DSensor8); | |
float temperature = sensors.getTempC(DSensor8); | |
} | |
float readDSensor9() { | |
// Code to read temperature from DS18B20 sensor 9 | |
sensors.requestTemperaturesByAddress(DSensor9); | |
float temperature = sensors.getTempC(DSensor9); | |
} | |
float readDSensor10() { | |
// Code to read temperature from DS18B20 sensor 10 | |
sensors.requestTemperaturesByAddress(DSensor10); | |
float temperature = sensors.getTempC(DSensor10); | |
} | |
float readDSensor11() { | |
// Code to read temperature from DS18B20 sensor 11 | |
sensors.requestTemperaturesByAddress(DSensor11); | |
float temperature = sensors.getTempC(DSensor11); | |
} | |
// Functions to set pump control variables | |
void setLeadPumpStatus(bool newStatus) { | |
leadPumpStatus = newStatus; | |
} | |
void setLagPumpStatus(bool newStatus) { | |
lagPumpStatus = newStatus; | |
} | |
void setDomesticHotWaterPumpStatus(bool newStatus) { | |
domesticHotWaterPumpStatus = newStatus; | |
} | |
void setDomesticHeatingPumpStatus(bool newStatus) { | |
domesticHeatingPumpStatus = newStatus; | |
} | |
void setCirculationLoopPumpStatus(bool newStatus) { | |
circulationLoopPumpStatus = newStatus; | |
} | |
// Functions to get pump control variables as strings for display | |
String getLeadPumpStatus() { | |
return leadPumpStatus ? "On" : "Off"; | |
} | |
String getLagPumpStatus() { | |
return lagPumpStatus ? "On" : "Off"; | |
} | |
String getDomesticHotWaterPumpStatus() { | |
return domesticHotWaterPumpStatus ? "On" : "Off"; | |
} | |
String getDomesticHeatingPumpStatus() { | |
return domesticHeatingPumpStatus ? "On" : "Off"; | |
} | |
String getCirculationLoopPumpStatus() { | |
return circulationLoopPumpStatus ? "On" : "Off"; | |
} | |
// Functions to get pump control variables as strings for radio buttons | |
String getLeadPumpOn() { | |
return leadPumpStatus ? "checked" : ""; | |
} | |
String getLeadPumpOff() { | |
return !leadPumpStatus ? "checked" : ""; | |
} | |
String getLeadPumpAuto() { | |
circulation = digitalRead(circulationLoopPumpPin); // assign a value to the global variable | |
return !leadPumpStatus && !circulation ? "checked" : ""; | |
} | |
String getLagPumpOn() { | |
return lagPumpStatus ? "checked" : ""; | |
} | |
String getLagPumpOff() { | |
return !lagPumpStatus ? "checked" : ""; | |
} | |
String getLagPumpAuto() { | |
circulation = digitalRead(circulationLoopPumpPin); | |
return !lagPumpStatus && !circulation ? "checked" : ""; | |
} | |
String getDomesticHotWaterPumpOn() { | |
return domesticHotWaterPumpStatus ? "checked" : ""; | |
} | |
String getDomesticHotWaterPumpOff() { | |
return !domesticHotWaterPumpStatus ? "checked" : ""; | |
} | |
String getDomesticHotWaterPumpAuto() { | |
circulation = digitalRead(circulationLoopPumpPin); | |
return !domesticHotWaterPumpStatus && !circulation ? "checked" : ""; | |
} | |
String getDomesticHeatingPumpOn() { | |
return domesticHeatingPumpStatus ? "checked" : ""; | |
} | |
String getDomesticHeatingPumpOff() { | |
return !domesticHeatingPumpStatus ? "checked" : ""; | |
} | |
String getDomesticHeatingPumpAuto() { | |
circulation = digitalRead(circulationLoopPumpPin); | |
return !domesticHeatingPumpStatus && !circulation ? "checked" : ""; | |
} | |
String getCirculationLoopPumpOn() { | |
return circulationLoopPumpStatus ? "checked" : ""; | |
} | |
String getCirculationLoopPumpOff() { | |
return !circulationLoopPumpStatus ? "checked" : ""; | |
} | |
String getCirculationLoopPumpAuto() { | |
circulation = digitalRead(circulationLoopPumpPin); | |
return circulation ? "checked" : ""; | |
} | |
// Functions to handle pump control requests | |
void handleLeadPumpOn() { | |
leadPumpStatus = true; | |
server.send(200, "text/plain", "Lead pump turned on"); | |
} | |
void handleLeadPumpOff() { | |
leadPumpStatus = false; | |
server.send(200, "text/plain", "Lead pump turned off"); | |
} | |
void handleLeadPumpAuto() { | |
leadPumpStatus = !circulation; | |
server.send(200, "text/plain", "Lead pump set to auto"); | |
} | |
void handleLagPumpOn() { | |
lagPumpStatus = true; | |
server.send(200, "text/plain", "Lag pump turned on"); | |
} | |
void handleLagPumpOff() { | |
lagPumpStatus = false; | |
server.send(200, "text/plain", "Lag pump turned off"); | |
} | |
void handleLagPumpAuto() { | |
lagPumpStatus = !circulation; | |
server.send(200, "text/plain", "Lag pump set to auto"); | |
} | |
void handleDomesticHotWaterPumpOn() { | |
domesticHotWaterPumpStatus = true; | |
server.send(200, "text/plain", "Domestic hot water pump turned on"); | |
} | |
void handleDomesticHotWaterPumpOff() { | |
domesticHotWaterPumpStatus = false; | |
server.send(200, "text/plain", "Domestic hot water pump turned off"); | |
} | |
void handleDomesticHotWaterPumpAuto() { | |
domesticHotWaterPumpStatus = !circulation; | |
server.send(200, "text/plain", "Domestic hot water pump set to auto"); | |
} | |
void handleDomesticHeatingPumpOn() { | |
domesticHeatingPumpStatus = true; | |
server.send(200, "text/plain", "Domestic heating pump turned on"); | |
} | |
void handleDomesticHeatingPumpOff() { | |
domesticHeatingPumpStatus = false; | |
server.send(200, "text/plain", "Domestic heating pump turned off"); | |
} | |
void handleDomesticHeatingPumpAuto() { | |
domesticHeatingPumpStatus = !circulation; | |
server.send(200, "text/plain", "Domestic heating pump set to auto"); | |
} | |
void handleCirculationLoopPumpOn() { | |
circulationLoopPumpStatus = true; | |
server.send(200, "text/plain", "Circulation loop pump turned on"); | |
} | |
void handleCirculationLoopPumpOff() { | |
circulationLoopPumpStatus = false; | |
server.send(200, "text/plain", "Circulation loop pump turned off"); | |
} | |
void handleCirculationLoopPumpAuto() { | |
circulationLoopPumpStatus = circulation; | |
server.send(200, "text/plain", "Circulation loop pump set to auto"); | |
} | |
void handleRoot() { | |
String html = "<html><body><h1>Sean's ESP32 Web Server</h1>"; | |
html += "<p>Lead Pump: " + String(leadPumpMode) + "</p>"; | |
html += "<p>Lag Pump: " + String(lagPumpMode) + "</p>"; | |
html += "<p>Domestic Hot Water Pump: " + String(domesticHotWaterPumpMode) + "</p>"; | |
html += "<p>Domestic Heating Pump: " + String(domesticHeatingPumpMode) + "</p>"; | |
html += "<p>Circulation Loop Pump: " + String(circulationLoopPumpMode) + "</p>"; | |
html += "<p>PT1000: " + String(PT1000) + "</p>"; | |
html += "<form action='/form'>"; | |
html += "<p>Lead Pump Mode: <input type='text' name='leadPumpMode' value='" + String(leadPumpMode) + "'></p>"; | |
html += "<p>Lag Pump Mode: <input type='text' name='lagPumpMode' value='" + String(lagPumpMode) + "'></p>"; | |
html += "<p>Domestic Hot Water Pump Mode: <input type='text' name='domesticHotWaterPumpMode' value='" + String(domesticHotWaterPumpMode) + "'></p>"; | |
html += "<p>Domestic Heating Pump Mode: <input type='text' name='domesticHeatingPumpMode' value='" + String(domesticHeatingPumpMode) + "'></p>"; | |
html += "<p>Circulation Loop Pump Mode: <input type='text' name='circulationLoopPumpMode' value='" + String(circulationLoopPumpMode) + "'></p>"; | |
html += "<p>PT1000 Value: <input type='text' name='PT1000' value='" + String(PT1000) + "'></p>"; | |
html += "<p>DSensor1 Value: <input type='text' name='DSensor1' value='" + String((int)DSensor1[0]) + "'></p>"; | |
html += "<p><input type='submit' value='Submit'></p>"; | |
html += "</form>"; | |
html += "</body></html>"; | |
server.send(200, "text/html", html); | |
} | |
//Now that we have defined all the functions for handling the web server requests, we can initialize the server and start the main loop. | |
// Initialize the web server | |
// Setup function | |
void setup() { | |
// Initialize serial communication | |
Serial.begin(115200); | |
pinMode(leadPumpPin, OUTPUT); | |
pinMode(lagPumpPin, OUTPUT); | |
pinMode(domesticHotWaterPumpPin, OUTPUT); | |
pinMode(domesticHeatingPumpPin, OUTPUT); | |
pinMode(circulationLoopPumpPin, OUTPUT); | |
digitalWrite(leadPumpPin, LOW); | |
digitalWrite(lagPumpPin, LOW); | |
digitalWrite(domesticHotWaterPumpPin, LOW); | |
digitalWrite(domesticHeatingPumpPin, LOW); | |
digitalWrite(circulationLoopPumpPin, LOW); | |
WiFi.mode(WIFI_STA); | |
WiFi.begin(ssid, password); | |
Serial.print("Connecting to "); | |
Serial.print(ssid); | |
while (WiFi.status() != WL_CONNECTED) { | |
delay(1000); | |
Serial.print("."); | |
} | |
Serial.println(); | |
Serial.print("Connected to WiFi network with IP Address: "); | |
Serial.println(WiFi.localIP()); | |
// Initialize the web server | |
server.begin(); | |
// server.on("/", [](){ | |
// server.send_P(200, "text/html", html_page); | |
// server.send(200, "text/plain", "Hello World"); | |
// server.send_P(200, "text/html", htmlreporting.h); | |
//}); | |
server.on("/", [](){ | |
server.send_P(200, "text/html", htmlreporting.c_str()); | |
}); | |
Serial.println("Web server started"); | |
// Initialize PT1000 analog input | |
pinMode(PT1000Pin, INPUT); | |
// Initialize DS18b20 digital temperature sensors | |
sensors.begin(); | |
// Locate sensors on the bus | |
if (!sensors.getAddress(DSensor1, 0)) { | |
Serial.println("Error: Unable to locate DSensor1."); | |
} | |
if (!sensors.getAddress(DSensor2, 1)) { | |
Serial.println("Error: Unable to locate DSensor2."); | |
} | |
if (!sensors.getAddress(DSensor3, 2)) { | |
Serial.println("Error: Unable to locate DSensor3."); | |
} | |
if (!sensors.getAddress(DSensor4, 3)) { | |
Serial.println("Error: Unable to locate DSensor4."); | |
} | |
if (!sensors.getAddress(DSensor5, 4)) { | |
Serial.println("Error: Unable to locate DSensor5."); | |
} | |
if (!sensors.getAddress(DSensor6, 5)) { | |
Serial.println("Error: Unable to locate DSensor6."); | |
} | |
if (!sensors.getAddress(DSensor7, 6)) { | |
Serial.println("Error: Unable to locate DSensor7."); | |
} | |
if (!sensors.getAddress(DSensor8, 7)) { | |
Serial.println("Error: Unable to locate DSensor8."); | |
} | |
if (!sensors.getAddress(DSensor9, 8)) { | |
Serial.println("Error: Unable to locate DSensor9."); | |
} | |
if (!sensors.getAddress(DSensor10, 9)) { | |
Serial.println("Error: Unable to locate DSensor10."); | |
} | |
if (!sensors.getAddress(DSensor11, 10)) { | |
Serial.println("Error: Unable to locate DSensor11."); | |
} | |
} | |
// Loop function | |
void loop() { | |
int ds1_index = 0; | |
int ds2_index = 0; | |
int ds3_index = 0; | |
int ds4_index = 0; | |
int ds5_index = 0; | |
int ds6_index = 0; | |
int ds7_index = 0; | |
int ds8_index = 0; | |
int ds9_index = 0; | |
int ds10_index = 0; | |
int ds11_index = 0; | |
// Read PT1000 temperature | |
float pt1000_temp = readPT1000(); | |
// Add PT1000 temperature to rolling average array | |
pt1000_temps[pt1000_index] = pt1000_temp; | |
pt1000_index = (pt1000_index + 1) % ROLLING_ARRAY_SIZE; | |
// Calculate PT1000 rolling average | |
float pt1000_sum = 0; | |
for (int i = 0; i < ROLLING_ARRAY_SIZE; i++) { | |
pt1000_sum += pt1000_temps[i]; | |
} | |
PT1000Average = pt1000_sum / ROLLING_ARRAY_SIZE; | |
// Read DSensor1 temperature | |
float ds1_temp = readDSensor1(); | |
// Add DSensor1 temperature to rolling average array | |
ds1_temps[ds1_index] = ds1_temp; | |
ds1_index = (ds1_index + 1) % ROLLING_ARRAY_SIZE; | |
// Calculate DSensor1 rolling average | |
float ds1_sum = 0; | |
for (int i = 0; i < ROLLING_ARRAY_SIZE; i++) { | |
ds1_sum += ds1_temps[i]; | |
} | |
DSensor1Average = ds1_sum / ROLLING_ARRAY_SIZE; | |
// Read DSensor2 temperature | |
float ds2_temp = readDSensor2(); | |
// Add DSensor2 temperature to rolling average array | |
ds2_temps[ds2_index] = ds2_temp; | |
ds2_index = (ds2_index + 1) % ROLLING_ARRAY_SIZE; | |
// Calculate DSensor2 rolling average | |
float ds2_sum = 0; | |
for (int i = 0; i < ROLLING_ARRAY_SIZE; i++) { | |
ds2_sum += ds2_temps[i]; | |
} | |
DSensor2Average = ds2_sum / ROLLING_ARRAY_SIZE; | |
// Read DSensor3 temperature | |
float ds3_temp = readDSensor3(); | |
// Add DSensor3 temperature to rolling average array | |
ds3_temps[ds3_index] = ds3_temp; | |
ds3_index = (ds3_index + 1) % ROLLING_ARRAY_SIZE; | |
// Calculate DSensor3 rolling average | |
float ds3_sum = 0; | |
for (int i = 0; i < ROLLING_ARRAY_SIZE; i++) { | |
ds3_sum += ds3_temps[i]; | |
} | |
DSensor3Average = ds3_sum / ROLLING_ARRAY_SIZE; | |
// Read DSensor4 temperature | |
float ds4_temp = readDSensor4(); | |
// Add DSensor4 temperature to rolling average array | |
ds4_temps[ds4_index] = ds4_temp; | |
ds4_index = (ds4_index + 1) % ROLLING_ARRAY_SIZE; | |
// Calculate DSensor4 rolling average | |
float ds4_sum = 0; | |
for (int i = 0; i < ROLLING_ARRAY_SIZE; i++) { | |
ds4_sum += ds4_temps[i]; | |
} | |
DSensor4Average = ds4_sum / ROLLING_ARRAY_SIZE; | |
// Read DSensor5 temperature | |
float ds5_temp = readDSensor5(); | |
// Add DSensor5 temperature to rolling average array | |
ds5_temps[ds5_index] = ds5_temp; | |
ds5_index = (ds5_index + 1) % ROLLING_ARRAY_SIZE; | |
// Calculate DSensor5 rolling average | |
float ds5_sum = 0; | |
for (int i = 0; i < ROLLING_ARRAY_SIZE; i++) { | |
ds5_sum += ds5_temps[i]; | |
} | |
DSensor5Average = ds5_sum / ROLLING_ARRAY_SIZE; | |
// Read DSensor6 temperature | |
float ds6_temp = readDSensor6(); | |
// Add DSensor6 temperature to rolling average array | |
ds6_temps[ds6_index] = ds6_temp; | |
ds6_index = (ds6_index + 1) % ROLLING_ARRAY_SIZE; | |
// Calculate DSensor6 rolling average | |
float ds6_sum = 0; | |
for (int i = 0; i < ROLLING_ARRAY_SIZE; i++) { | |
ds6_sum += ds6_temps[i]; | |
} | |
DSensor6Average = ds6_sum / ROLLING_ARRAY_SIZE; | |
// Read DSensor7 temperature | |
float ds7_temp = readDSensor7(); | |
// Add DSensor7 temperature to rolling average array | |
ds7_temps[ds7_index] = ds7_temp; | |
ds7_index = (ds7_index + 1) % ROLLING_ARRAY_SIZE; | |
// Calculate DSensor7 rolling average | |
float ds7_sum = 0; | |
for (int i = 0; i < ROLLING_ARRAY_SIZE; i++) { | |
ds7_sum += ds7_temps[i]; | |
} | |
DSensor7Average = ds7_sum / ROLLING_ARRAY_SIZE; | |
// Read DSensor8 temperature | |
float ds8_temp = readDSensor8(); | |
// Add DSensor8 temperature to rolling average array | |
ds8_temps[ds8_index] = ds8_temp; | |
ds8_index = (ds8_index + 1) % ROLLING_ARRAY_SIZE; | |
// Calculate DSensor8 rolling average | |
float ds8_sum = 0; | |
for (int i = 0; i < ROLLING_ARRAY_SIZE; i++) { | |
ds8_sum += ds8_temps[i]; | |
} | |
DSensor8Average = ds8_sum / ROLLING_ARRAY_SIZE; | |
// Read DSensor9 temperature | |
float ds9_temp = readDSensor9(); | |
// Add DSensor9 temperature to rolling average array | |
ds9_temps[ds9_index] = ds9_temp; | |
ds9_index = (ds9_index + 1) % ROLLING_ARRAY_SIZE; | |
// Calculate DSensor9 rolling average | |
float ds9_sum = 0; | |
for (int i = 0; i < ROLLING_ARRAY_SIZE; i++) { | |
ds9_sum += ds9_temps[i]; | |
} | |
DSensor9Average = ds9_sum / ROLLING_ARRAY_SIZE; | |
// Read DSensor10 temperature | |
float ds10_temp = readDSensor10(); | |
// Add DSensor10 temperature to rolling average array | |
ds10_temps[ds10_index] = ds10_temp; | |
ds10_index = (ds10_index + 1) % ROLLING_ARRAY_SIZE; | |
// Calculate DSensor10 rolling average | |
float ds10_sum = 0; | |
for (int i = 0; i < ROLLING_ARRAY_SIZE; i++) { | |
ds10_sum += ds10_temps[i]; | |
} | |
DSensor10Average = ds10_sum / ROLLING_ARRAY_SIZE; | |
// Read DSensor11 temperature | |
float ds11_temp = readDSensor11(); | |
// Add DSensor11 temperature to rolling average array | |
ds11_temps[ds11_index] = ds11_temp; | |
ds11_index = (ds11_index + 1) % ROLLING_ARRAY_SIZE; | |
// Calculate DSensor11 rolling average | |
float ds11_sum = 0; | |
for (int i = 0; i < ROLLING_ARRAY_SIZE; i++) { | |
ds11_sum += ds11_temps[i]; | |
} | |
DSensor11Average = ds11_sum / ROLLING_ARRAY_SIZE; | |
// Add the new temperature reading to the rolling average array for each sensor | |
PT1000Array[4] = temperature; | |
DSensor1Array[4] = sensors.getTempC(DSensor1); | |
DSensor2Array[4] = sensors.getTempC(DSensor2); | |
DSensor3Array[4] = sensors.getTempC(DSensor3); | |
DSensor4Array[4] = sensors.getTempC(DSensor4); | |
DSensor5Array[4] = sensors.getTempC(DSensor5); | |
DSensor6Array[4] = sensors.getTempC(DSensor6); | |
DSensor7Array[4] = sensors.getTempC(DSensor7); | |
DSensor8Array[4] = sensors.getTempC(DSensor8); | |
DSensor9Array[4] = sensors.getTempC(DSensor9); | |
DSensor10Array[4] = sensors.getTempC(DSensor10); | |
DSensor11Array[4] = sensors.getTempC(DSensor11); | |
// Shift the rolling average array for each sensor | |
for (int i = 0; i < 4; i++) { | |
PT1000Array[i] = PT1000Array[i + 1]; | |
DSensor1Array[i] = DSensor1Array[i + 1]; | |
DSensor2Array[i] = DSensor2Array[i + 1]; | |
DSensor3Array[i] = DSensor3Array[i + 1]; | |
DSensor4Array[i] = DSensor4Array[i + 1]; | |
DSensor5Array[i] = DSensor5Array[i + 1]; | |
DSensor6Array[i] = DSensor6Array[i + 1]; | |
DSensor7Array[i] = DSensor7Array[i + 1]; | |
DSensor8Array[i] = DSensor8Array[i + 1]; | |
DSensor9Array[i] = DSensor9Array[i + 1]; | |
DSensor10Array[i] = DSensor10Array[i + 1]; | |
DSensor11Array[i] = DSensor11Array[i + 1]; | |
} | |
// Calculate the rolling average for each sensor | |
PT1000Average = (PT1000Array[0] + PT1000Array[1] + PT1000Array[2] + PT1000Array[3] + PT1000Array[4]) / 5.0; | |
DSensor1Average = (DSensor1Array[0] + DSensor1Array[1] + DSensor1Array[2] + DSensor1Array[3] + DSensor1Array[4]) / 5.0; | |
DSensor2Average = (DSensor2Array[0] + DSensor2Array[1] + DSensor2Array[2] + DSensor2Array[3] + DSensor2Array[4]) / 5.0; | |
DSensor3Average = (DSensor3Array[0] + DSensor3Array[1] + DSensor3Array[2] + DSensor3Array[3] + DSensor3Array[4]) / 5.0; | |
DSensor4Average = (DSensor4Array[0] + DSensor4Array[1] + DSensor4Array[2] + DSensor4Array[3] + DSensor4Array[4]) / 5.0; | |
DSensor5Average = (DSensor5Array[0] + DSensor5Array[1] + DSensor5Array[2] + DSensor5Array[3] + DSensor5Array[4]) / 5.0; | |
DSensor6Average = (DSensor6Array[0] + DSensor6Array[1] + DSensor6Array[2] + DSensor6Array[3] + DSensor6Array[4]) / 5.0; | |
DSensor7Average = (DSensor7Array[0] + DSensor7Array[1] + DSensor7Array[2] + DSensor7Array[3] + DSensor7Array[4]) / 5.0; | |
DSensor8Average = (DSensor8Array[0] + DSensor8Array[1] + DSensor8Array[2] + DSensor8Array[3] + DSensor8Array[4]) / 5.0; | |
DSensor9Average = (DSensor9Array[0] + DSensor9Array[1] + DSensor9Array[2] + DSensor9Array[3] + DSensor9Array[4]) / 5.0; | |
DSensor10Average = (DSensor10Array[0] + DSensor10Array[1] + DSensor10Array[2] + DSensor10Array[3] + DSensor10Array[4]) / 5.0; | |
DSensor11Average = (DSensor11Array[0] + DSensor11Array[1] + DSensor11Array[2] + DSensor11Array[3] + DSensor11Array[4]) / 5.0; | |
// Print the temperatures to the serial monitor | |
Serial.print("PT1000: "); | |
Serial.println(PT1000); | |
Serial.print("DSensor1: "); | |
Serial.println(readDSensor1()); | |
Serial.print("DSensor2: "); | |
Serial.println(readDSensor2()); | |
Serial.print("DSensor3: "); | |
Serial.println(readDSensor3()); | |
Serial.print("DSensor4: "); | |
Serial.println(readDSensor4()); | |
Serial.print("DSensor5: "); | |
Serial.println(readDSensor5()); | |
Serial.print("DSensor6: "); | |
Serial.println(readDSensor6()); | |
Serial.print("DSensor7: "); | |
Serial.println(readDSensor7()); | |
Serial.print("DSensor8: "); | |
Serial.println(readDSensor8()); | |
Serial.print("DSensor9: "); | |
Serial.println(readDSensor9()); | |
Serial.print("DSensor10: "); | |
Serial.println(readDSensor10()); | |
Serial.print("DSensor11: "); | |
Serial.println(readDSensor11()); | |
// Print the rolling averages to the serial monitor | |
Serial.print("PT1000 Average: "); | |
Serial.println(PT1000Average); | |
Serial.print("DSensor1 Average: "); | |
Serial.println(DSensor1Average); | |
Serial.print("DSensor2 Average: "); | |
Serial.println(DSensor2Average); | |
Serial.print("DSensor3 Average: "); | |
Serial.println(DSensor3Average); | |
Serial.print("DSensor4 Average: "); | |
Serial.println(DSensor4Average); | |
Serial.print("DSensor5 Average: "); | |
Serial.println(DSensor5Average); | |
Serial.print("DSensor6 Average: "); | |
Serial.println(DSensor6Average); | |
Serial.print("DSensor7 Average: "); | |
Serial.println(DSensor7Average); | |
Serial.print("DSensor8 Average: "); | |
Serial.println(DSensor8Average); | |
Serial.print("DSensor9 Average: "); | |
Serial.println(DSensor9Average); | |
Serial.print("DSensor10 Average: "); | |
Serial.println(DSensor10Average); | |
Serial.print("DSensor11 Average: "); | |
Serial.println(DSensor11Average); | |
server.handleClient(); | |
// Wait for 1 second before taking the next reading | |
delay(5000); | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const char html[] PROGMEM = R"====( | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>ESP32 ESP32 Server</title> | |
<style> | |
table { | |
border-collapse: collapse; | |
width: 100%; | |
margin-bottom: 1em; | |
} | |
table th, table td { | |
border: 1px solid #ddd; | |
padding: 8px; | |
text-align: left; | |
} | |
table th { | |
background-color: #4CAF50; | |
color: white; | |
} | |
table tr:nth-child(even) { | |
background-color: #f2f2f2; | |
} | |
table tr:hover { | |
background-color: #ddd; | |
} | |
</style> | |
</head> | |
<body> | |
<h1>ESP32-WROOM-32 Solar Controller</h1> | |
<table> | |
<thead> | |
<tr> | |
<th>System Temperatures</th> | |
<th>Pump Status</th> | |
<th>Energy</th> | |
</tr> | |
</thead> | |
<tbody> | |
<tr> | |
<td>PT1000 <br>PT1000Average</td> | |
<td>Data 2</td> | |
<td>Data 3</td> | |
</tr> | |
<tr> | |
<td>Data 4</td> | |
<td>Data 5</td> | |
<td>Data 6</td> | |
</tr> | |
</tbody> | |
</table> | |
</body> | |
</html> | |
)===="; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment