Guten Morgen,
ich weiß, ich nerve langsam tierisch. Ich habe ungelogen seit 6 Uhr daran gesessen, aber ich bekomme es einfach nicht hin ....
***************************************************************** */
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h> // for the webserver
#include <ESP8266mDNS.h> // Bonjour/multicast DNS ... find the device on network by name
#include <ArduinoOTA.h> // OTA Upload via ArduinoIDE
#define USE_BOARD 250 // the actual board to compile
#define VERSION "9.1" // This is just the Version of the Arduino Sketch
/* *******************************************************************
the board settings / die Einstellungen der verschiedenen Boards
********************************************************************/
#if USE_BOARD == 250 // Example Board
#define TXT_BOARDID "250" // an ID for the board
#define TXT_BOARDNAME "ESP8266 Server" // The name of the board
#define CSS_MAINCOLOR "blue" // don't get confused by the different webservers and use a different color for each board
#endif
/* *******************************************************************
other settings / weitere Einstellungen für den Anwender
********************************************************************/
const char* ssid = "";
const char* password = "";
/* *******************************************************************
Globals - Variables and constants
********************************************************************/
unsigned long ss = 0; // current second since startup
const uint16_t ajaxIntervall = 5; // Intervall for AJAX call of website in seconds
const uint16_t pulseMs = 300; // durance of a pulse
const int BUTTON1_PIN = 0; // GPIO00/D3 on NodeMCU is the Flash Button - use this for testing an input
const int OUTPUT1_PIN = 4; // GPIO16/D0 on NodeMCU is a (red) LED on the NodeMCU Board - use this for testing the html switch
const int OUTPUT2_PIN = 2; // GPIO02/D4 on NodeMCU is the (blue) LED on the ESP-12E
ADC_MODE(ADC_VCC); // to use getVcc
uint32_t internalVcc = ESP.getVcc();
ESP8266WebServer server(80);
// Anmelderoutine
const char* www_username = "admin";
const char* www_password = "esp8266";
// Webinterface
#ifndef CSS_MAINCOLOR
#define CSS_MAINCOLOR "#8A0829" // fallback if no CSS_MAINCOLOR was declared for the board
#endif
/* *******************************************************************
S E T U P
********************************************************************/
void setup(void) {
digitalWrite(OUTPUT1_PIN, HIGH);
digitalWrite(OUTPUT2_PIN, HIGH);
pinMode(OUTPUT1_PIN, OUTPUT);
pinMode(OUTPUT2_PIN, OUTPUT);
pinMode(BUTTON1_PIN, INPUT);
Serial.begin(115200);
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
if(WiFi.waitForConnectResult() != WL_CONNECTED) {
Serial.println("WiFi Connect Failed! Rebooting...");
delay(1000);
ESP.restart();
}
ArduinoOTA.begin();
char myhostname[8] = {"esp"};
strcat(myhostname, TXT_BOARDID);
WiFi.hostname(myhostname);
WiFi.begin(ssid, password);
// Wait for connection
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(F("."));
}
Serial.print("Open http://");
Serial.println(F(""));
Serial.print(F("Connected to "));
Serial.println(ssid);
Serial.print(F("IP address: "));
Serial.println(WiFi.localIP());
if (MDNS.begin("esp8266")) {
Serial.println(F("MDNS responder started"));
}
server.on("/", [](){
if(!server.authenticate(www_username, www_password))
return server.requestAuthentication();
server.send(200, "text/plain", "Login OK");
});
// define the pages and other content for the webserver
server.on("/", handlePage); // send root page
server.on("/0.htm", handlePage);
// server.on("/1.htm", handlePage);
// server.on("/2.htm", handlePage);
// server.on("/x.htm", handleOtherPage); // just another page to explain my usage of HTML pages ...
server.on("/f.css", handleCss); // a stylesheet
server.on("/j.js", handleJs); // a javascript to handle AJAX/JSON Update of the page
server.on("/json", handleJson); // send data in JSON
server.on("/c.php", handleCommand); // process commands
// server.onNotFound(handleNotFound); // show a typical 404 page
server.begin();
Serial.print("Open http://192.168.178.40");
Serial.print(WiFi.localIP());
Serial.println("/ in your browser to see it working");
Serial.println(F("HTTP server started"));
//IDE OTA
ArduinoOTA.setHostname(myhostname); // give a name to your ESP for the Arduino IDE
ArduinoOTA.begin(); // OTA Upload via ArduinoIDE https://arduino-esp8266.readthedocs.io/en/latest/ota_updates/readme.html
}
/* *******************************************************************
M A I N L O O P
********************************************************************/
void loop(void) {
ss = millis() / 1000;
server.handleClient();
ArduinoOTA.handle(); // OTA Upload via ArduinoIDE
// do your calculation, sensor readings etc...
// add displays, serial outputs here
}
Zwar kommt der die Anmeldeaufforderung, aber wenn ich mich angemeldet habe, springt er nicht auf die Root Seite, sondern schreibt nur Login OK.
Leider kann man 0.htm auch so aufrufen, ohne mit einer PW-Abfrage konfrontiert zu werden....
Ich raff es einfach nicht.