commit 265b0b202dd832aa7f30d8dabb9b6d2ea1d7ac25 Author: Christoph Sterz Date: Thu Oct 3 20:36:28 2024 +0200 Erster Stand Webseite * Note: Das ist noch mit dem alten ("Schalter")-Sensor diff --git a/platformio.ini b/platformio.ini new file mode 100644 index 0000000..aa89331 --- /dev/null +++ b/platformio.ini @@ -0,0 +1,16 @@ +; PlatformIO Project Configuration File +; +; Build options: build flags, source filter +; Upload options: custom upload port, speed and extra flags +; Library options: dependencies, extra library storages +; Advanced options: extra scripting +; +; Please visit documentation for the other options and examples +; https://docs.platformio.org/page/projectconf.html + +[env:d1_mini] +platform = espressif8266 +board = d1_mini_pro +framework = arduino +upload_port = /dev/ttyUSB0 +lib_deps = paulstoffregen/CapacitiveSensor@^0.5.1 diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..ab26b0a --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,103 @@ +#include +#include +#include +#include + +#ifndef STASSID +#define STASSID "machbar" +#define STAPSK "machbar-wireless" +#endif + +const char* ssid = STASSID; +const char* password = STAPSK; +IPAddress apIP(192, 168, 112, 1); +int pushButton = D8; +int lastbuttonstate = 0; +int auftrittmillis = 0; +int abtrittmillis = 0; + +int auftrittzeiten[20]; +int kontaktzeiten[20]; +int idx = 0; + +String websiteA = "Sensor" +"
    "; +String websiteB = "

Start

"; + + + + +ESP8266WebServer server(80); + +const int led = 13; + +void handleRoot() { + String liste; + for(int i = 0; i < 20; i++) { + liste = liste + kontaktzeiten[i] + "\r\n"; + } + server.send(200, "text/plain", websiteA + liste + websiteB); +} + + + +void handleNotFound() { + handleRoot(); +} + +void setup(void) { + pinMode(pushButton, 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"); } + + server.on("/", handleRoot); + + server.onNotFound(handleNotFound); + + server.begin(); + Serial.println("HTTP server started"); +} + + + +void loop(void) { + // read the input pin: + int buttonState = digitalRead(pushButton); + // print out the state of the button: + //Serial.println(buttonState); + //Serial.println(millis()); + if(lastbuttonstate == 0 && buttonState == 1) + { + auftrittmillis = millis(); + Serial.print("Auftritt: "); + Serial.println(auftrittmillis); + } + if(lastbuttonstate == 1 && buttonState == 0) + { + abtrittmillis = millis(); + Serial.print("Abgehoben: "); + Serial.println(abtrittmillis); + Serial.print("Bodenkontakt: "); + Serial.println(abtrittmillis - auftrittmillis); + auftrittzeiten[idx] = auftrittmillis; + kontaktzeiten[idx] = abtrittmillis - auftrittmillis; + idx = (idx + 1)%20; + } + lastbuttonstate = buttonState; + delay(1); // delay in between reads for stability + server.handleClient(); + MDNS.update(); +}