Neuen Sensor (Capacitive) zur Webseite hinzugefügt
* Printed die letzen 100 Werte, noch in komischer Reihenfolge
This commit is contained in:
parent
ef6995a334
commit
bd25950be3
58
src/main.cpp
58
src/main.cpp
|
@ -3,21 +3,36 @@
|
|||
#include <ESP8266WebServer.h>
|
||||
#include <ESP8266mDNS.h>
|
||||
|
||||
#ifndef STASSID
|
||||
#define STASSID "machbar"
|
||||
#define STAPSK "machbar-wireless"
|
||||
#endif
|
||||
//Capacitive touch sensor
|
||||
#define ANALOG_READ_PIN A0 //GPIO 5
|
||||
#include <CapacitiveSensor.h>
|
||||
|
||||
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);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/// Brauchen wir bald nicht mehr
|
||||
int pushButton = D8;
|
||||
int lastbuttonstate = 0;
|
||||
|
||||
|
||||
|
||||
|
||||
int auftrittmillis = 0;
|
||||
int abtrittmillis = 0;
|
||||
|
||||
int auftrittzeiten[20];
|
||||
int kontaktzeiten[20];
|
||||
|
||||
|
||||
int idx = 0;
|
||||
|
||||
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() {
|
||||
String liste;
|
||||
for(int i = 0; i < 20; i++) {
|
||||
liste = liste + kontaktzeiten[i] + "\r\n";
|
||||
for(int i = 0; i < 100; i++) {
|
||||
liste = liste + letzteWerte[i] + "\r\n";
|
||||
}
|
||||
server.send(200, "text/plain", websiteA + liste + websiteB);
|
||||
server.send(200, "text/html", websiteA + liste + websiteB);
|
||||
}
|
||||
|
||||
|
||||
|
@ -47,33 +62,42 @@ void handleNotFound() {
|
|||
|
||||
void setup(void) {
|
||||
pinMode(pushButton, INPUT);
|
||||
pinMode(ANALOG_READ_PIN, INPUT);
|
||||
pinMode(led, OUTPUT);
|
||||
digitalWrite(led, 0);
|
||||
Serial.begin(115200);
|
||||
WiFi.softAPConfig(apIP, apIP, IPAddress(255, 255, 255, 0));
|
||||
WiFi.softAP("Drucksensor");
|
||||
Serial.println("");
|
||||
|
||||
|
||||
|
||||
Serial.println("");
|
||||
Serial.print("Connected to ");
|
||||
Serial.println(ssid);
|
||||
Serial.print("IP address: ");
|
||||
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.onNotFound(handleNotFound);
|
||||
|
||||
server.begin();
|
||||
Serial.println("HTTP server started");
|
||||
Serial.println("HTTP server eierstarted");
|
||||
}
|
||||
|
||||
|
||||
|
||||
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:
|
||||
int buttonState = digitalRead(pushButton);
|
||||
// print out the state of the button:
|
||||
|
@ -97,7 +121,9 @@ void loop(void) {
|
|||
idx = (idx + 1)%20;
|
||||
}
|
||||
lastbuttonstate = buttonState;
|
||||
delay(1); // delay in between reads for stability
|
||||
*/
|
||||
|
||||
delay(10); // delay in between reads for stability
|
||||
server.handleClient();
|
||||
MDNS.update();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue