|
|
|
@ -25,14 +25,16 @@ |
|
|
|
|
#define MEDIAN_SAMPLES 60 |
|
|
|
|
#define ONBOARD_LED 2 |
|
|
|
|
#define NTP_TIMEOUT 15000 |
|
|
|
|
void check_mode(void); |
|
|
|
|
|
|
|
|
|
LiquidCrystal_I2C lcd(LCD_I2C_ADDR, LCD_COL, LCD_ROW); |
|
|
|
|
looper sched; |
|
|
|
|
RunningMedian samples = RunningMedian(MEDIAN_SAMPLES); |
|
|
|
|
float temp_min = (analogRead(TEMP_SENS_PIN) / 2048.0) * 330.0; |
|
|
|
|
float temp_max = temp_min; |
|
|
|
|
float temp = (analogRead(TEMP_SENS_PIN) / 2048.0) * 330.0; |
|
|
|
|
bool led_state; |
|
|
|
|
String header; |
|
|
|
|
WiFiServer server(80); |
|
|
|
|
|
|
|
|
|
void setup() |
|
|
|
|
{ |
|
|
|
@ -123,6 +125,8 @@ void setup() |
|
|
|
|
DateTime.forceUpdate(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
server.begin(); |
|
|
|
|
|
|
|
|
|
sched.addJob(show_temperature, KRATE_TEMP); |
|
|
|
|
sched.addJob(show_time, KRATE_TIME); |
|
|
|
|
|
|
|
|
@ -134,6 +138,74 @@ void setup() |
|
|
|
|
void loop() |
|
|
|
|
{ |
|
|
|
|
sched.scheduler(); |
|
|
|
|
|
|
|
|
|
WiFiClient client = server.available(); // Listen for incoming clients
|
|
|
|
|
|
|
|
|
|
if (client) { // If a new client connects,
|
|
|
|
|
Serial.println("New Client."); // print a message out in the serial port
|
|
|
|
|
String currentLine = ""; // make a String to hold incoming data from the client
|
|
|
|
|
while (client.connected()) |
|
|
|
|
{ // loop while the client's connected
|
|
|
|
|
if (client.available()) { // if there's bytes to read from the client,
|
|
|
|
|
char c = client.read(); // read a byte, then
|
|
|
|
|
Serial.write(c); // print it out the serial monitor
|
|
|
|
|
header += c; |
|
|
|
|
if (c == '\n') { // if the byte is a newline character
|
|
|
|
|
// if the current line is blank, you got two newline characters in a row.
|
|
|
|
|
// that's the end of the client HTTP request, so send a response:
|
|
|
|
|
if (currentLine.length() == 0) { |
|
|
|
|
// checking if header is valid
|
|
|
|
|
// YWRtaW46c3RhYWdhcg== (user:pass) admin:staagar
|
|
|
|
|
if (header.indexOf("YWRtaW46c3RhYWdhcg==") >= 0) { |
|
|
|
|
client.println("HTTP/1.1 200 OK"); |
|
|
|
|
client.println("Content-type:text/html"); |
|
|
|
|
client.println("Connection: close"); |
|
|
|
|
client.println(); |
|
|
|
|
client.println("<!DOCTYPE html>\n"); |
|
|
|
|
client.println("<html>\n"); |
|
|
|
|
client.println("<meta http-equiv=\"refresh\" content=\"5\">\n"); |
|
|
|
|
client.println("<body>\n"); |
|
|
|
|
client.println("<center>\n"); |
|
|
|
|
client.println("<h1 style=\"color:blue;\">Temperatur Kirche</h1>\n"); |
|
|
|
|
client.print("<h2 style=\"color:green;\">Aktuell: "); |
|
|
|
|
client.print(temp); |
|
|
|
|
client.println(" °C</h2>\n"); |
|
|
|
|
client.print("<h2 style=\"color:green;\">Minimum: "); |
|
|
|
|
client.print(temp_min); |
|
|
|
|
client.println(" °C</h2>\n"); |
|
|
|
|
client.print("<h2 style=\"color:green;\">Maximum: "); |
|
|
|
|
client.print(temp_max); |
|
|
|
|
client.println(" °C</h2>\n"); |
|
|
|
|
client.println("</center>\n"); |
|
|
|
|
client.println("</body>\n"); |
|
|
|
|
client.println("</html>"); |
|
|
|
|
|
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
// Wrong user or password, so HTTP request fails...
|
|
|
|
|
else { |
|
|
|
|
client.println("HTTP/1.1 401 Unauthorized"); |
|
|
|
|
client.println("WWW-Authenticate: Basic realm=\"Secure\""); |
|
|
|
|
client.println("Content-Type: text/html"); |
|
|
|
|
client.println(); |
|
|
|
|
client.println("<html>Authentication failed</html>"); |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
} else { // if you got a newline, then clear currentLine
|
|
|
|
|
currentLine = ""; |
|
|
|
|
} |
|
|
|
|
} else if (c != '\r') { // if you got anything else but a carriage return character,
|
|
|
|
|
currentLine += c; // add it to the end of the currentLine
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
// Clear the header variable
|
|
|
|
|
header = ""; |
|
|
|
|
// Close the connection
|
|
|
|
|
client.stop(); |
|
|
|
|
Serial.println("Client disconnected."); |
|
|
|
|
Serial.println(""); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void show_time(void) |
|
|
|
@ -154,10 +226,25 @@ void show_time(void) |
|
|
|
|
|
|
|
|
|
void show_temperature(void) |
|
|
|
|
{ |
|
|
|
|
float temp = (analogRead(TEMP_SENS_PIN) / 2048.0) * 330.0; |
|
|
|
|
float new_temp = (analogRead(TEMP_SENS_PIN) / 2048.0) * 330.0; |
|
|
|
|
|
|
|
|
|
Serial.println(temp, 1); |
|
|
|
|
|
|
|
|
|
if (new_temp > temp) |
|
|
|
|
{ |
|
|
|
|
if (new_temp - temp > 1.0) |
|
|
|
|
temp = temp + 1.0; |
|
|
|
|
else |
|
|
|
|
temp = new_temp; |
|
|
|
|
} |
|
|
|
|
else if (new_temp < temp) |
|
|
|
|
{ |
|
|
|
|
if (new_temp - temp < -1.0) |
|
|
|
|
temp = temp - 1.0; |
|
|
|
|
else |
|
|
|
|
temp = new_temp; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
samples.add(temp); |
|
|
|
|
|
|
|
|
|
if (samples.getLowest() < temp_min) |
|
|
|
|