Erster Stand Webseite
* Note: Das ist noch mit dem alten ("Schalter")-Sensor
This commit is contained in:
commit
265b0b202d
|
@ -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
|
|
@ -0,0 +1,103 @@
|
|||
#include <ESP8266WiFi.h>
|
||||
#include <WiFiClient.h>
|
||||
#include <ESP8266WebServer.h>
|
||||
#include <ESP8266mDNS.h>
|
||||
|
||||
#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 = "<!doctype html><html lang=en><head><meta charset=utf-8><title>Sensor</title></head><body style='background:#2d2d2d'>"
|
||||
"<div style='position:fixed;top:10%;left:10%;width:80%;height:80%;color:#ffffff;text-align:left;vertical-align:left;line-height:400%;font-size:400%;font-family:Arial,Helvetica,sans-serif;''> <ul style='list-style-type:none;'> ";
|
||||
String websiteB = "</ul></div><div style='position:fixed;bottom:0;left:0;width:100%;height:20%;background:#9ade00;color:#00252c;text-align:center;vertical-align:middle;line-height:400%;font-size:400%'> <p><b>Start</b></p> </div> </body></html>";
|
||||
|
||||
|
||||
|
||||
|
||||
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();
|
||||
}
|
Loading…
Reference in New Issue