Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "ESP8266WiFi.h"
- #include "ESP8266WebServer.h"
- const char* ssid = "asd";
- const char* pass = "asd";
- IPAddress ip(192,168,2,200); // 192.168.178.xxx = freie IP Adresse, ggf. müsst ihr auch die anderen Zahlen anpassen; schaut am besten in euren Router
- IPAddress gateway(192,168,2,1);
- IPAddress subnet(255,255,255,0);
- ESP8266WebServer server(80);
- #define LEDPIN 2
- String led1= "<a href=\"/steckdose_an\">Steckdose An</a>";
- String led0= "<a href=\"/steckdose_aus\">Steckdose Aus</a>";
- void handleRoot() {
- String message="<h1>Testprogramm - Minimalprogramm ESP8266</h1>";
- message += "Hallo ..., das ist ein Gruß vom ESP8266 Server</BR></BR>";
- message += led1;
- server.send(200, "text/html", message);
- }
- void steckdoseAn(){
- digitalWrite(LEDPIN, HIGH);
- server.send(200, "text/html", led0);
- }
- void steckdoseAus(){
- digitalWrite(LEDPIN, LOW);
- server.send(200, "text/html", led1);
- }
- void setup(){
- Serial.begin(9600);
- Serial.println("Start");
- pinMode(0, OUTPUT);
- pinMode(LEDPIN, OUTPUT);
- digitalWrite(LEDPIN, LOW);
- // Serial.begin(9600);
- // Serial.println("Testprogramm - Minimalprogramm ESP8266");
- // Serial.print("Verbinde mich mit Netz: ");
- // Serial.println(ssid);
- WiFi.begin(ssid, pass);
- WiFi.config(ip, gateway, subnet);
- // while(WiFi.status() != WL_CONNECTED){
- // delay(500); Serial.print(".");
- // }
- // Serial.println("");
- // Serial.println("WiFi Verbindung aufgebaut");
- // Serial.print("Eigene IP des ESP-Modul: ");
- // Serial.println(WiFi.localIP());
- server.on("/",handleRoot);
- server.on("/steckdose_an", steckdoseAn);
- server.on("/steckdose_aus", steckdoseAus);
- server.begin();
- Serial.println("Server started, Setup done");
- // Serial.println("HTTP Server wurde gestartet!");
- }
- void loop(){
- server.handleClient();
- }
Advertisement
Add Comment
Please, Sign In to add comment