Neuen Sensor (Capacitive) zur Webseite hinzugefügt

* Printed die letzen 100 Werte, noch in komischer Reihenfolge
This commit is contained in:
Christoph Sterz 2024-10-03 21:12:28 +02:00
parent ef6995a334
commit bd25950be3
1 changed files with 42 additions and 16 deletions

View File

@ -3,21 +3,36 @@
#include <ESP8266WebServer.h> #include <ESP8266WebServer.h>
#include <ESP8266mDNS.h> #include <ESP8266mDNS.h>
#ifndef STASSID //Capacitive touch sensor
#define STASSID "machbar" #define ANALOG_READ_PIN A0 //GPIO 5
#define STAPSK "machbar-wireless" #include <CapacitiveSensor.h>
#endif
const char* ssid = STASSID;
const char* password = STAPSK; int sensorValue = 0;
int letzteWerte[100];
int idWert = 0;
// IP Addresse wie bei der Feuerwehr!
IPAddress apIP(192, 168, 112, 1); IPAddress apIP(192, 168, 112, 1);
/// Brauchen wir bald nicht mehr
int pushButton = D8; int pushButton = D8;
int lastbuttonstate = 0; int lastbuttonstate = 0;
int auftrittmillis = 0; int auftrittmillis = 0;
int abtrittmillis = 0; int abtrittmillis = 0;
int auftrittzeiten[20]; int auftrittzeiten[20];
int kontaktzeiten[20]; int kontaktzeiten[20];
int idx = 0; int idx = 0;
String websiteA = "<!doctype html><html lang=en><head><meta charset=utf-8><title>Sensor</title></head><body style='background:#2d2d2d'>" String websiteA = "<!doctype html><html lang=en><head><meta charset=utf-8><title>Sensor</title></head><body style='background:#2d2d2d'>"
@ -33,10 +48,10 @@ const int led = 13;
void handleRoot() { void handleRoot() {
String liste; String liste;
for(int i = 0; i < 20; i++) { for(int i = 0; i < 100; i++) {
liste = liste + kontaktzeiten[i] + "\r\n"; liste = liste + letzteWerte[i] + "\r\n";
} }
server.send(200, "text/plain", websiteA + liste + websiteB); server.send(200, "text/html", websiteA + liste + websiteB);
} }
@ -47,6 +62,7 @@ void handleNotFound() {
void setup(void) { void setup(void) {
pinMode(pushButton, INPUT); pinMode(pushButton, INPUT);
pinMode(ANALOG_READ_PIN, INPUT);
pinMode(led, OUTPUT); pinMode(led, OUTPUT);
digitalWrite(led, 0); digitalWrite(led, 0);
Serial.begin(115200); Serial.begin(115200);
@ -56,24 +72,32 @@ void setup(void) {
Serial.println(""); Serial.println("");
Serial.print("Connected to ");
Serial.println(ssid);
Serial.print("IP address: "); Serial.print("IP address: ");
Serial.println(WiFi.localIP()); Serial.println(WiFi.localIP());
if (MDNS.begin("esp8266")) { Serial.println("MDNS responder started"); } if (MDNS.begin("esp8266")) { Serial.println("MDNS responder osestarted"); }
server.on("/", handleRoot); server.on("/", handleRoot);
server.onNotFound(handleNotFound); server.onNotFound(handleNotFound);
server.begin(); server.begin();
Serial.println("HTTP server started"); Serial.println("HTTP server eierstarted");
} }
void loop(void) { void loop(void) {
sensorValue = analogRead(ANALOG_READ_PIN);
Serial.println(sensorValue);
letzteWerte[idWert] = sensorValue;
idWert = (idWert + 1) % 100;
// Hier Logik ändern
/*
// read the input pin: // read the input pin:
int buttonState = digitalRead(pushButton); int buttonState = digitalRead(pushButton);
// print out the state of the button: // print out the state of the button:
@ -97,7 +121,9 @@ void loop(void) {
idx = (idx + 1)%20; idx = (idx + 1)%20;
} }
lastbuttonstate = buttonState; lastbuttonstate = buttonState;
delay(1); // delay in between reads for stability */
delay(10); // delay in between reads for stability
server.handleClient(); server.handleClient();
MDNS.update(); MDNS.update();
} }