1 | #include <ESP8266WiFi.h>
|
2 | #include <ESP8266WebServer.h>
|
3 |
|
4 | #define WLAN_OK D1 //LED leuchtet, wenn WLAN-Anbindung vorhanden
|
5 | #define Messung D2 //LED leuchtet kurz, wenn DHT22 ausgewertet wird
|
6 | #define Kontrol D3 //LED für Testzwecke
|
7 | #define Poti A0 //Analogeingang
|
8 | #define Taste D4 //Binäreingang geht auf LOW wenn Taste gedrückt
|
9 |
|
10 | int AD_Wert = 0;
|
11 |
|
12 | unsigned long letzterCheck = 0; //Speicher für den Zeitpunkt der letzten
|
13 | unsigned long aktZeit = 0; //Erfassung und den aktuellen Zeitwert in ms
|
14 | const long Interval = 5000L; //Unbedingt unsigned nehmen!!!
|
15 | //Der Messinterval ist 5 Sekunden
|
16 | const char* SSID = "geheim"; //Name meines WLANs (SSID)
|
17 | const char* NWSch = "sag ich nicht"; //Netzwerkschlüssel
|
18 |
|
19 | ESP8266WebServer MiniServ(80); //Mini-WEB-Server starten. Komunikation
|
20 | //über Port 80. Das ist ein Standartport
|
21 | void Antwort_Root()
|
22 | {
|
23 | MiniServ.send(200, "text/html", "Nichts im Root-Bereich");
|
24 | }
|
25 |
|
26 | void Antwort_Analog()
|
27 | {
|
28 | AD_Wert = analogRead(Poti);
|
29 | MiniServ.send(200, "text/html", String(AD_Wert));
|
30 | }
|
31 |
|
32 | void Antwort_Taste()
|
33 | {
|
34 | MiniServ.send(200, "text/html", String("Taste ist ") +
|
35 | ((digitalRead(Taste)) ? "frei" : "betaetigt"));
|
36 | }
|
37 | void setup(void)
|
38 | {
|
39 | pinMode(WLAN_OK, OUTPUT);
|
40 | pinMode(Messung, OUTPUT);
|
41 | pinMode(Kontrol, OUTPUT);
|
42 | pinMode(Taste, INPUT_PULLUP);
|
43 |
|
44 | //Verbindung zum WLAN herstellen
|
45 | WiFi.begin(SSID, NWSch);
|
46 |
|
47 | //LED blinkt während des Verbindungsaufbaus
|
48 | while (WiFi.status() != WL_CONNECTED)
|
49 | {
|
50 | digitalWrite(WLAN_OK, true);
|
51 | delay(150);
|
52 | digitalWrite(WLAN_OK, false);
|
53 | delay(150);
|
54 | }
|
55 | digitalWrite(WLAN_OK, true); //WLAN-Verbindung steht
|
56 |
|
57 | MiniServ.on("/", Antwort_Root);
|
58 | MiniServ.on("/analog", Antwort_Analog);
|
59 | MiniServ.on("/Taste", Antwort_Taste);
|
60 | //Mini-Server starten
|
61 | MiniServ.begin();
|
62 | }
|
63 |
|
64 | void loop(void)
|
65 | {
|
66 | //Prüft, ob anfragen von einem Client kommen
|
67 | MiniServ.handleClient();
|
68 | }
|