Hallo liebe Community,
ich hab folgende Tutorials ausprobiert um eine Webpage zum laufen zu bringen, leider ohne jeglichen Erfolg... Wäre super wenn mir jemand ein bessere Tutorial oder so empfehlen könnte.
Dabei stellt sich die Frage, ob das an meinem custom Nodemcu-Build von: Firmware-Builder liegt.... Wenn ja, wäre es cool wenn mir jemand ein besseres Firmware-Build zukommen lassen könnte. Ich benutze die Arduino IDE 2.0.0. Könnte es auch daran liegen? Hatte vor einige Zeit ein Problem mit derLiquidCrystal_I2C Libary.Sie funktioniertenur bei der 1.0.6er Version einwandfrei. Mittlerweile wurde der Fehler behoben und die ist auch bei neueren Versionen nutzbar.
Bei folgendem Tutorial, habe ich u.a.das Problem, dass bei :
/*Put your SSID & Password*/
const char* ssid = "BLACKLEAKZ"; // Enter SSID here
const char* password = "12345678"; //Enter Password here
Die Werte für:
Wifi.begin(ssid, password);
nicht übernommen werden.
Hier ein Link zum Tutorial: https://lastminuteengineers.com/creating-esp8266-web-server-arduino-ide/
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
/*Put your SSID & Password*/
const char* ssid = "YourNetworkName"; // Enter SSID here
const char* password = "YourPassword"; //Enter Password here
ESP8266WebServer server(80);
uint8_t LED1pin = D7;
bool LED1status = LOW;
uint8_t LED2pin = D6;
bool LED2status = LOW;
void setup() {
Serial.begin(115200);
delay(100);
pinMode(LED1pin, OUTPUT);
pinMode(LED2pin, OUTPUT);
Serial.println("Connecting to ");
Serial.println(ssid);
//connect to your local wi-fi network
WiFi.begin(ssid, password);
//check wi-fi is connected to wi-fi network
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected..!");
Serial.print("Got IP: "); Serial.println(WiFi.localIP());
server.on("/", handle_OnConnect);
server.on("/led1on", handle_led1on);
server.on("/led1off", handle_led1off);
server.on("/led2on", handle_led2on);
server.on("/led2off", handle_led2off);
server.onNotFound(handle_NotFound);
server.begin();
Serial.println("HTTP server started");
}
void loop() {
server.handleClient();
if(LED1status)
{digitalWrite(LED1pin, HIGH);}
else
{digitalWrite(LED1pin, LOW);}
if(LED2status)
{digitalWrite(LED2pin, HIGH);}
else
{digitalWrite(LED2pin, LOW);}
}
void handle_OnConnect() {
LED1status = LOW;
LED2status = LOW;
Serial.println("GPIO7 Status: OFF | GPIO6 Status: OFF");
server.send(200, "text/html", SendHTML(LED1status,LED2status));
}
void handle_led1on() {
LED1status = HIGH;
Serial.println("GPIO7 Status: ON");
server.send(200, "text/html", SendHTML(true,LED2status));
}
void handle_led1off() {
LED1status = LOW;
Serial.println("GPIO7 Status: OFF");
server.send(200, "text/html", SendHTML(false,LED2status));
}
void handle_led2on() {
LED2status = HIGH;
Serial.println("GPIO6 Status: ON");
server.send(200, "text/html", SendHTML(LED1status,true));
}
void handle_led2off() {
LED2status = LOW;
Serial.println("GPIO6 Status: OFF");
server.send(200, "text/html", SendHTML(LED1status,false));
}
void handle_NotFound(){
server.send(404, "text/plain", "Not found");
}
String SendHTML(uint8_t led1stat,uint8_t led2stat){
String ptr = "<!DOCTYPE html> <html>\n";
ptr +="<head><meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, user-scalable=no\">\n";
ptr +="<title>LED Control</title>\n";
ptr +="<style>html { font-family: Helvetica; display: inline-block; margin: 0px auto; text-align: center;}\n";
ptr +="body{margin-top: 50px;} h1 {color: #444444;margin: 50px auto 30px;} h3 {color: #444444;margin-bottom: 50px;}\n";
ptr +=".button {display: block;width: 80px;background-color: #1abc9c;border: none;color: white;padding: 13px 30px;text-decoration: none;font-size: 25px;margin: 0px auto 35px;cursor: pointer;border-radius: 4px;}\n";
ptr +=".button-on {background-color: #1abc9c;}\n";
ptr +=".button-on:active {background-color: #16a085;}\n";
ptr +=".button-off {background-color: #34495e;}\n";
ptr +=".button-off:active {background-color: #2c3e50;}\n";
ptr +="p {font-size: 14px;color: #888;margin-bottom: 10px;}\n";
ptr +="</style>\n";
ptr +="</head>\n";
ptr +="<body>\n";
ptr +="<h1>ESP8266 Web Server</h1>\n";
ptr +="<h3>Using Station(STA) Mode</h3>\n";
if(led1stat)
{ptr +="<p>LED1 Status: ON</p><a class=\"button button-off\" href=\"/led1off\">OFF</a>\n";}
else
{ptr +="<p>LED1 Status: OFF</p><a class=\"button button-on\" href=\"/led1on\">ON</a>\n";}
if(led2stat)
{ptr +="<p>LED2 Status: ON</p><a class=\"button button-off\" href=\"/led2off\">OFF</a>\n";}
else
{ptr +="<p>LED2 Status: OFF</p><a class=\"button button-on\" href=\"/led2on\">ON</a>\n";}
ptr +="</body>\n";
ptr +="</html>\n";
return ptr;
}
Und dem hier:
https://www.instructables.com/How-to-Build-a-ESP8266-Web-Server/
/*********
* Coding done by Andy Wong-MYBOTIC
* Control the LED by using webserver and update the information to webserver
*********/
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>
MDNSResponder mdns;
// Replace with your network credentials
const char* ssid = "X3PC0";
const char* password = "12345678";
ESP8266WebServer server(80);
String webSite="";
int sensorPin=12;
int led0=13;
int led1= 4;
int led2 = 5;
int ledSensor=16;
void setup(void){
webSite +="<meta http-equiv='refresh' content='3'><title>ESP8266 Demo</title>\n";
webSite += "<style>body{ background-color: #cccccc; font-family: Arial, Helvetica, Sans-Serif; Color: #000088; }</style>\n";
webSite +="<h2 dir=\"rtl\" style=\"text-align: left;\"><img alt=\"\" src=\"http://www.mybotic.com.my/webshaper/pcm/pictures/Mybotic-Logo-(5).jpg\" style=\"float: left; height: 103px; width: 999px; border-width: 15px; border-style: solid;\" /></h2>\n";
webSite +="<p> </p><p> </p><p> </p><p> </p><p> </p>\n";
webSite+="<button onclick='myFunction()'>HOME</button>";
webSite+="<script>function myFunction() {location.reload();}</script>";
webSite +="<h1>ESP8266 Web Server</h1><p>LED #1 <a href=\"socket1On\"><button>ON</button></a> <a href=\"socket1Off\"><button>OFF</button></a></p>\n";
webSite += "<p>LED #2 <a href=\"socket2On\"><button>ON</button></a> <a href=\"socket2Off\"><button>OFF</button></a></p>\n";
webSite +=" <p><h2>Condition read from flamesensor</h2></p>\n";
// preparing GPIOs
pinMode(led0, OUTPUT);
digitalWrite(led0, LOW);
pinMode(led1, OUTPUT);
digitalWrite(led1, LOW);
pinMode(led2, OUTPUT);
digitalWrite(led2, LOW);
pinMode(sensorPin,INPUT);
pinMode(ledSensor,OUTPUT);
Serial.begin(115200);
WiFi.begin(ssid, password);
Serial.println("");
// Wait for connection
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
digitalWrite(led0,HIGH);
Serial.println("");
Serial.print("Connected to ");
Serial.println(ssid);
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
if (mdns.begin("esp8266", WiFi.localIP())) {
Serial.println("MDNS responder started");
}
server.on("/", [](){
server.send(200, "text/html", webSite);
});
server.on("/socket1On", [](){
server.send(200, "text/html", webSite);
digitalWrite(led1, HIGH);
});
server.on("/socket1Off", [](){
server.send(200, "text/html", webSite);
digitalWrite(led1, LOW);
});
server.on("/socket2On", [](){
server.send(200, "text/html", webSite);
digitalWrite(led2, HIGH);
});
server.on("/socket2Off", [](){
server.send(200, "text/html", webSite);
digitalWrite(led2, LOW);
});
server.begin();
Serial.println("HTTP server started");
}
void loop(void){
server.handleClient();
String sentences="<p>Flame is detected!!!</p>";
if(WiFi.status() != WL_CONNECTED)
{
digitalWrite(led0, LOW);
Serial.println("");
Serial.print("Wifi is disconnected!");
Serial.println("");
Serial.print("Reconnecting");
Serial.println("");
//WiFi.begin(ssid,password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
digitalWrite(led0,HIGH);
}
if(digitalRead(sensorPin) ==LOW)
{
Serial.print("Flame is detected");
Serial.println("");
webSite+=sentences;
digitalWrite(ledSensor,HIGH);
delay(300);
}
else //if no detect
{
digitalWrite(ledSensor,LOW);
}
}
Vielen Dank im Vorraus.