EPS8266 Acryl LED - Gravierte Acryl-Schreibe mit LED-Beleuchtung und Steuerung per Web-App im eigenen WLAN
Schaltplan
Bauteile
| Bauteil | Menge | Einzelpreis [€] | Summe [€] |
|---|---|---|---|
| Acrylplatte | 1 | 4,95 | 4,95 |
| Kohleschichtwiderstand 1/4W, 5%, 10 K-Ohm | 3 | 0,01 | 0,03 |
| RAD 10/16 :: Elektrolytkondensator, 6,3x11mm, RM 2,5mm | 2 | 0,04 | 0,08 |
| Z5U-2,5 100N :: Vielschicht-Keramikkondensator 100N, 20% | 1 | 0,04 | 0,04 |
| HT7333A-1 TO-92 HT7333 | 1 | 0,16 | 0,16 |
| Stiftleisten gerade | 1 | 0,17 | 0,17 |
| Buchsenleisten 2,54 mm, 1X04, gerade | 2 | 0,16 | 0,32 |
| H25SR050 :: Streifenrasterplatine, Hartpapier, 50x100mm | 1 | 0,58 | 0,58 |
| ESP8266 Esp-01 Serial Port WIFI Transceiver Wireless Module LWIP AP+STA TE139 | 1 | 2,67 | 2,67 |
| RAD FR 1.000/16 :: Elko radial, 105°C, low ESR, RM 3,5mm | 1 | 0,29 | 0,29 |
| USB-Einbaubuchse, B-Mini, gew., Printmontage | 1 | 0,49 | 0,49 |
| 1m WS2812B Smart RGB LED Pixel Strip Black PCB 60 leds/m DC5V IP30 | 1 | 6,16 | 6,16 |
| 15,94 |
Bilder
Web-App
Bei Starten des Acryl LED-Programms wird zunächst versucht, sich an einem bestehenden (zuvor eingerichtetem) WLAN anzumelden. Funktioniert das nicht, wird selber ein Access Point (hier "Wichteln2017") aufgebaut. Verbindet man sich mit diesem Access Point, wird automatisch ein Einrichtungsassistent (Captive Portal) gestartet.
Die Qualität der gefundenen WLANs wird mit .oO angezeigt. Der Stern deutet auf ein verschlüsseltes WLAN hin. Es kann auch der Timeout eingestellt werden, wie lange ein Verbindungsaufbau versucht werden soll.
Nach dem letzten Schritt startet das Programm neu und versucht sich am eben eingerichteten WLAN anzubinden. Danach kann im eigenen WLAN die Acryl LED über folgende URL erreicht werden: http://wichteln2017.local
Auf dem Reiter "Farbauswahl" kann über das Farbrad eine Farbe gewählt werden. Eine Vorschau der gewählten Farbe wird im oberen Bereich angezeigt. Mit dem Button "OK" wird die Farbe an der Acryl LED angezeigt. Der Reiter "Timer" steuert die Ein- und Ausschaltzeiten der Acryl LED. Im Reiter "Animation" können zwei verschiedene Farb-Animationen aktiviert werden. Zusätzlich können Systeminformationen abgerufen werden.
Mit der URL http://wichteln2017.local/update können auch Updates online durchgeführt werden.
Software
Die Entwicklung läuft über die Arduino IDE (http://arduino.cc) Version 1.6.12.
Hier die Einstellungen der IDE:
Sourcecode
Aufgrund der Übersichtlichkeit ist der Sourcecode auf mehrere Dateien aufgeteilt.
LED-strip.ino
/* EEPROM Aufteilung für Konfigurationsdaten
Position Länge Wert
0 1 Firststart Flag
2 1 Connectiontimeout
4 1 IP Typ 0=DHCP, 1=Statisch
5 4 IP-Adresse
9 4 Gateway IP-Adresse
13 4 Subnet Mask
17 4 DNS-Server IP-Adresse
18-20 3 Frei
21-52 32 WLAN SSID
53-116 64 WLAN PWD
117 2 Einschaltzeit
119 2 Ausschaltzeit
*/
/*
typedef enum {
WL_NO_SHIELD = 255, // for compatibility with WiFi Shield library
WL_IDLE_STATUS = 0,
WL_NO_SSID_AVAIL = 1,
WL_SCAN_COMPLETED = 2,
WL_CONNECTED = 3,
WL_CONNECT_FAILED = 4,
WL_CONNECTION_LOST = 5,
WL_DISCONNECTED = 6
} wl_status_t;
*/
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <DNSServer.h>
#include <ESP8266mDNS.h>
#include <EEPROM.h>
#include <Adafruit_NeoPixel.h>
#include <TimeLib.h>
#include <WiFiUdp.h>
#include <ESP8266HTTPUpdateServer.h>
#ifdef __AVR__
#include <avr/power.h>
#endif
const String SOFTWAREVERSION="1.181216.F"; //Version der Software (X.YYYYYY.Z X = Build des Tages, Y = Datum, Z = Typ (Z=Zwischenversion, F=Finale Version))
ADC_MODE(ADC_VCC); //Der ADC wird so konfiguriert das er die Systemspannung misst, es darf nichts am ADC (TOUT) Pin angechlossen sein!
//Variablen werden mit EEPROM Konfiguration überschrieben wenn FirstStartFlag im EEPROM = 111 (bedeutet Sensor ist konfiguriert) ist!
byte FIRSTSTARTFLAG=0; //Flag zur Erkennung ob System im Setup Modus starten muss weil es keine Konfiguration im EEPROM hat
byte CONNECTIONTIMEOUT=60; //Verbindungstimeout für die Verbindung mit unserem WLAN (Sekunden)
byte STATICIP=0; //Art der IP-Adresszuteilung 0=IP per DHCP, 1=Statische IP
String WLANSSID=""; //Die SSID des WLAN kommt hier rein
String WLANPWD=""; //Das WLAN Passwort des WLAN kommt hier rein
IPAddress ip(0,0,0,0); //Sensor Server IP-Adresse bei statischer Konfiguration
IPAddress gw(0,0,0,0); //Gateway IP-Adresse bei statischer Konfiguration
IPAddress sub(255,255,255,0); //Subnet Mask bei statischer Konfiguration
IPAddress dns(0,0,0,0); //DNS Server IP-Adresse bei statischer Konfiguration
// Which pin on the Arduino is connected to the NeoPixels?
// On a Trinket or Gemma we suggest changing this to 1
//#define PIN 14 // ESP-12E
#define PIN 2 // ESP-01
// How many NeoPixels are attached to the Arduino?
#define NUMPIXELS 11
int prevColors[11];
String WLANSSIDSETUP = "Wichteln2017";
String WLANPWDSETUP = "12345678";
String WLANHOSTNAME = "wichteln2017"; // Hostname für mDNS (http://wichteln2017.local)
const char *myHostname = "wichteln2017";
boolean isSetup = false;
bool brainbow = false;
bool brainbowCycle = false;
// Timer
// NTP Servers:
IPAddress timeServer; // time.nist.gov NTP server address
const char* ntpServerName = "time.nist.gov";
WiFiUDP Udp;
unsigned int localPort = 8888; // local port to listen for UDP packets
const int timeZone = 1; // Central European Time
byte ontimeHour = 18;
byte ontimeMinute = 0;
byte offtimeHour = 22;
byte offtimeMinute = 0;
unsigned long checkTime = 0;
#define MAXCHECKTIME 1000
bool curCheckTimeOn;
bool prevCheckTimeOn;
// DNS server
const byte DNS_PORT = 53;
DNSServer dnsServer;
// Web server
ESP8266WebServer server ( 80 );
ESP8266HTTPUpdateServer httpUpdater;
/* Soft AP network parameters */
IPAddress apIP(192, 168, 4, 1);
IPAddress netMsk(255, 255, 255, 0);
// Parameter 1 = number of pixels in strip
// Parameter 2 = Arduino pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)
// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
// NEO_RGBW Pixels are wired for RGBW bitstream (NeoPixel RGBW products)
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
void handleRoot() {
if (captivePortal()) { // If captive portal redirect instead of displaying the page.
return;
}
Serial.println(F("Lade Root..."));
String temp = "<!DOCTYPE html>";
temp += "<html>";
temp += "<head>";
temp += "<meta charset='utf-8' />";
temp += "<meta name='viewport' content='initial-scale=1.0, user-scalable=no' />";
temp += "<meta name='apple-mobile-web-app-capable' content='yes' />";
temp += "<meta name='apple-mobile-web-app-status-bar-style' content='black' />";
temp += "<title>";
temp += "</title>";
temp += "<link rel='stylesheet' href='http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css' />";
temp += "<script src='http://code.jquery.com/jquery-1.11.1.min.js'></script>";
temp += "<script src='http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js'></script>";
temp += "<script type='text/javascript' src='https://cdn.rawgit.com/F1LT3R/farbtastic-color-picker/master/farbtastic.js'></script>";
temp += "<link rel='stylesheet' href='https://cdn.rawgit.com/F1LT3R/farbtastic-color-picker/master/farbtastic.css' />";
temp += "<script type='text/javascript' charset='utf-8'>";
temp += "$(document).ready(function() {";
temp += "$('#picker').farbtastic(function(e){";
temp += "$('#color').css({backgroundColor:e}).val(e);";
temp += "$('#color').css({color:e}).val(e);";
temp += "});";
temp += "$('#colorok').click(function(event) {";
temp += "var pickercolor = $('input[name=color]').val();";
temp += "$.post('/color', { color: pickercolor } );";
temp += "});";
temp += "$('#timerok').click(function(event) {";
temp += "var starttime = $('input[name=starttime]').val();";
temp += "var endtime = $('input[name=endtime]').val();";
temp += "$.post('/timer', { starttime: starttime, endtime: endtime } );";
temp += "});";
temp += "$('#rainbow').click(function(event) {";
temp += "$.post('/rainbow');";
temp += "});";
temp += "$('#rainbowCycle').click(function(event) {";
temp += "$.post('/rainbowCycle');";
temp += "});";
temp += "});";
temp += "</script>";
temp += "</head>";
temp += "<body>";
temp += "<!-- Start of first page -->";
temp += "<div data-role='page' id='page1' data-theme='b'>";
temp += "<div data-role='header' data-theme='b'>";
temp += "<h1>Farbauswahl</h1>";
temp += "</div><!-- /header -->";
temp += "<div role='main' class='ui-content' data-theme='b'> ";
temp += "<div data-role='content' data-theme='b'>";
temp += "<input type='text' id='color' name='color' value='#2a2a2a' style='height: 150px; text-shadow:none; color:#2a2a2a; backgroundcolor:#2a2a2a;'/>";
temp += "<div id='picker' align='center'></div>";
temp += "<input type='button' id='colorok' value='OK.' />";
temp += "</div> <!-- /content -->";
temp += "</div><!-- /main -->";
temp += "<div data-role='footer' data-theme='b' data-position='fixed'>";
temp += "<div data-role='navbar'>";
temp += "<ul>";
temp += "<li><a href='#page1' data-icon='star'>Farbauswahl</a></li>";
temp += "<li><a href='#page2' data-icon='clock'>Timer</a></li>";
temp += "<li><a href='#page3' data-icon='gear'>Animation</a></li>";
temp += "</ul>";
temp += "</div><!-- /navbar -->";
temp += "</div><!-- /footer -->";
temp += "</div><!-- /page -->";
temp += "<!-- Start of second page -->";
temp += "<div data-role='page' id='page2' data-theme='b'>";
temp += "<div data-role='header' data-theme='b'>";
temp += "<h1>Timer</h1>";
temp += "</div><!-- /header -->";
temp += "<div role='main' class='ui-content' data-theme='b'>";
temp += "<div data-role='content' data-theme='b'>";
temp += "<label for='starttime'>Einschaltzeit:</label>";
temp += "<input type='time' data-clear-btn='false' name='starttime' id='starttime' value='";
if (ontimeHour <= 9) temp += "0";
temp += String(ontimeHour) + ":";
if (ontimeMinute <= 9) temp += "0";
temp += String(ontimeMinute);
temp += "'>";
temp += "<label for='endtime'>Ausschaltzeit:</label>";
temp += "<input type='time' data-clear-btn='false' name='endtime' id='endtime' value='";
if (offtimeHour <= 9) temp += "0";
temp += String(offtimeHour) + ":";
if (offtimeMinute <= 9) temp += "0";
temp += String(offtimeMinute);
temp += "'>";
temp += "<input type='button' id='timerok' value='Speichern' />";
temp += "</div><!-- /content -->";
temp += "</div><!-- /main -->";
temp += "<div data-role='footer' data-theme='b' data-position='fixed'>";
temp += "<div data-role='navbar'>";
temp += "<ul>";
temp += "<li><a href='#page1' data-icon='star'>Farbauswahl</a></li>";
temp += "<li><a href='#page2' data-icon='clock'>Timer</a></li>";
temp += "<li><a href='#page3' data-icon='gear'>Animation</a></li>";
temp += "</ul>";
temp += "</div><!-- /navbar -->";
temp += "</div><!-- /footer -->";
temp += "</div><!-- /page -->";
temp += "<!-- Start of third page -->";
temp += "<div data-role='page' id='page3' data-theme='b'>";
temp += "<div data-role='header' data-theme='b'>";
temp += "<h1>Animation</h1>";
temp += "</div><!-- /header -->";
temp += "<div role='main' class='ui-content' data-theme='b'>";
temp += "<div data-role='content' data-theme='b'>";
temp += "<input type='button' id='rainbow' value='Regenbogen Animation' />";
temp += "<input type='button' id='rainbowCycle' value='Regenbogen Animation Wellen' />";
temp += "<input type='button' id='pulse' value='Aktuelle Farbe pulsieren' />";
temp += "<br /><br />";
temp += "<a href='#page4' class='ui-btn'>System-Info</a>";
temp += "</div><!-- /content -->";
temp += "</div><!-- /main -->";
temp += "<div data-role='footer' data-theme='b' data-position='fixed'>";
temp += "<div data-role='navbar'>";
temp += "<ul>";
temp += "<li><a href='#page1' data-icon='star'>Farbauswahl</a></li>";
temp += "<li><a href='#page2' data-icon='clock'>Timer</a></li>";
temp += "<li><a href='#page3' data-icon='gear'>Animation</a></li>";
temp += "</ul>";
temp += "</div><!-- /navbar -->";
temp += "</div><!-- /footer -->";
temp += "</div><!-- /page -->";
temp += "<!-- Start of forth page -->";
temp += "<div data-role='page' id='page4' data-theme='b'>";
temp += "<div data-role='header' data-theme='b'>";
temp += "<h1>System-Info</h1>";
temp += "</div><!-- /header -->";
temp += "<div role='main' class='ui-content' data-theme='b''>";
temp += "<div data-role='content' data-theme='b'>";
temp += "<table style='border-spacing: 10px 10px;' align='center'>";
temp += "<tr>";
temp += "<th style='text-align:right;'>Software-Version</th>";
temp += "<td>";
temp += SOFTWAREVERSION;
temp += "</td>";
temp += "</tr>";
temp += "<tr>";
temp += "<th style='text-align:right;'>SDK-Version</th>";
temp += "<td>";
temp += ESP.getSdkVersion();
temp += "</td>";
temp += "</tr>";
temp += "<tr>";
temp += "<th style='text-align:right;'>ESP8266 Chip-ID</th>";
temp += "<td>";
temp += ESP.getChipId();
temp += "</td>";
temp += "</tr>";
temp += "<tr>";
temp += "<th style='text-align:right;'>ESP8266 Speed</th>";
temp += "<td>";
temp += ESP.getCpuFreqMHz();
temp += " MHz";
temp += "</td>";
temp += "</tr>";
temp += "<tr>";
temp += "<th style='text-align:right;'>Free Heap Size</th>";
temp += "<td>";
temp += ESP.getFreeHeap();
temp += " Bytes";
temp += "</td>";
temp += "</tr>";
temp += "<tr>";
temp += "<tr>";
temp += "<th style='text-align:right;'>Free Sketch Space</th>";
temp += "<td>";
temp += ESP.getFreeSketchSpace();
temp += " Bytes";
temp += "</td>";
temp += "</tr>";
temp += "<tr>";
temp += "<th style='text-align:right;'>Sketch Size</th>";
temp += "<td>";
temp += ESP.getSketchSize();
temp += " Bytes";
temp += "</td>";
temp += "</tr>";
temp += "<th style='text-align:right;'>Systemspannung</th>";
temp += "<td>";
temp += String(ESP.getVcc()).substring(0,1);
temp += ",";
temp += String(ESP.getVcc()).substring(1);
temp += " Volt";
temp += "</td>";
temp += "</tr>";
temp += "<tr>";
temp += "<th style='text-align:right;'>Uhrzeit</th>";
temp += "<td>";
if (hour() <= 9) temp += "0";
temp += String(hour()) + ":";
if (minute() <= 9) temp += "0";
temp += String(minute());
temp += "</td>";
temp += "</tr>";
temp += "<tr>";
temp += "<th style='text-align:right;'>WLAN SSID</th>";
temp += "<td>";
temp += WLANSSID.c_str();
temp += "</td>";
temp += "</tr>";
temp += "<tr>";
temp += "<th style='text-align:right;'>IP Adresse</th>";
temp += "<td>";
temp += WiFi.localIP().toString();
temp += "</td>";
temp += "</tr>";
temp += "</table>";
temp += "</div><!-- /content -->";
temp += "</div><!-- /main -->";
temp += "<div data-role='footer' data-theme='b' data-position='fixed'>";
temp += "<div data-role='navbar'>";
temp += "<ul>";
temp += "<li><a href='#page1' data-icon='star'>Farbauswahl</a></li>";
temp += "<li><a href='#page2' data-icon='clock'>Timer</a></li>";
temp += "<li><a href='#page3' data-icon='gear'>Animation</a></li>";
temp += "</ul>";
temp += "</div><!-- /navbar -->";
temp += "</div><!-- /footer -->";
temp += "</div><!-- /page -->";
temp += "</body>";
temp += "</html>";
server.send ( 200, "text/html", temp );
Serial.println(F("Root geladen."));
}
void handleColor() {
brainbow = false;
brainbowCycle = false;
String str;
if (server.args() > 0) {
for ( uint8_t i = 0; i < server.args(); i++ ) {
str += server.argName(i) + " = " + server.arg(i) + "\r\n";
Serial.println("Arg "+ String(i)+":"+ server.argName(i) + " = " + server.arg(i));
}
}
String hexstring = server.arg(0);
long long number = strtol( &hexstring[1], NULL, 16);
long long r = number >> 16;
long long g = number >> 8 & 0xFF;
long long b = number & 0xFF;
if (checkTimerOn()) {
for(int i=0; i < NUMPIXELS; i++) {
pixels.setPixelColor(i, pixels.Color(r, g, b));
pixels.show();
}
}
}
void handleTimer() {
String str;
Serial.println(F("Hole Server Parameter..."));
if (server.args() > 0) {
for ( uint8_t i = 0; i < server.args(); i++ ) {
str += server.argName(i) + " = " + server.arg(i) + "\r\n";
Serial.println("Arg "+ String(i)+":"+ server.argName(i) + " = " + server.arg(i));
if (server.argName(i) == "starttime") {
int Index = server.arg(i).indexOf(':');
ontimeHour = server.arg(i).substring(0, Index).toInt();
ontimeMinute = server.arg(i).substring(Index+1).toInt();
}
if (server.argName(i) == "endtime") {
int Index = server.arg(i).indexOf(':');
offtimeHour = server.arg(i).substring(0, Index).toInt();
offtimeMinute = server.arg(i).substring(Index+1).toInt();
}
}
}
Serial.println(F("Server Parameter ermittelt."));
Serial.println(F("Schreibe EEPROM..."));
EEPROM.begin(512);
delay(10);
//Lösche alte Konfiguration
for (int i=117; i<121; i++) {
EEPROM.write(i ,0);
}
Serial.println(F(""));
Serial.println(F("Schreibe neue Einschaltzeit:"));
EEPROM.write(117, ontimeHour);
Serial.print(F("schreibe: "));
Serial.println(ontimeHour);
EEPROM.write(118, ontimeMinute);
Serial.print(F("schreibe: "));
Serial.println(ontimeMinute);
Serial.println(F(""));
Serial.println(F("Schreibe neue Ausschaltzeit:"));
EEPROM.write(119, offtimeHour);
Serial.print(F("schreibe: "));
Serial.println(offtimeHour);
EEPROM.write(120, offtimeMinute);
Serial.print(F("schreibe: "));
Serial.println(offtimeMinute);
EEPROM.commit();
EEPROM.end();
Serial.println(F("EEPROM geschrieben."));
}
void handleRainbow() {
brainbow = true;
brainbowCycle = false;
}
void handleRainbowCycle() {
brainbow = false;
brainbowCycle = true;
}
/** Redirect to captive portal if we got a request for another domain. Return true in that case so the page handler do not try to handle the request again. */
boolean captivePortal() {
if (!isIp(server.hostHeader()) && server.hostHeader() != (String(WLANHOSTNAME.c_str())+".local")) {
Serial.println("Request redirected to captive portal");
server.sendHeader("Location", String("http://") + toStringIp(server.client().localIP()) + String("/setup01"), true);
server.send ( 302, "text/plain", ""); // Empty content inhibits Content-length header so we have to close the socket ourselves.
server.client().stop(); // Stop is needed because we sent no content length
return true;
}
return false;
}
void handleNotFound() {
if (captivePortal()) { // If caprive portal redirect instead of displaying the error page.
return;
}
String message = "File Not Found\n\n";
message += "URI: ";
message += server.uri();
message += "\nMethod: ";
message += ( server.method() == HTTP_GET ) ? "GET" : "POST";
message += "\nArguments: ";
message += server.args();
message += "\n";
for ( uint8_t i = 0; i < server.args(); i++ ) {
message += " " + server.argName ( i ) + ": " + server.arg ( i ) + "\n";
}
server.sendHeader("Cache-Control", "no-cache, no-store, must-revalidate");
server.sendHeader("Pragma", "no-cache");
server.sendHeader("Expires", "-1");
server.send ( 404, "text/plain", message );
}
void createAP() {
Serial.println();
Serial.print("Starte Access Point...");
WiFi.softAPConfig(apIP, apIP, netMsk);
WiFi.softAP(WLANSSIDSETUP.c_str(), WLANPWDSETUP.c_str());
delay(500); // Without delay I've seen the IP address blank
Serial.println(F(""));
Serial.println(F("AP Modus gestartet"));
Serial.print(F("SSID: "));
Serial.println(WLANSSIDSETUP.c_str());
Serial.print(F("AP IP-Adresse: "));
Serial.println(WiFi.softAPIP());
Serial.println(F(""));
Serial.println(F("Starte DNS-Server..."));
/* Setup the DNS server redirecting all the domains to the apIP */
dnsServer.setErrorReplyCode(DNSReplyCode::NoError);
dnsServer.start(DNS_PORT, "*", apIP);
Serial.println(F("DNS-Server gestartet"));
Serial.println(F(""));
}
bool checkTimerOn() {
if (isSetup) return true;
int now = (hour()*100)+minute();
int on = (ontimeHour * 100) + ontimeMinute;
int off = (offtimeHour * 100) + offtimeMinute;
if (on > off) off += 2400;
if (now > on && now < off) {
return true;
} else {
return false;
}
}
void setup ( void ) {
Serial.begin ( 115200 );
Serial.println(F(""));
Serial.println(F(""));
Serial.println(F("Starte den ESP8266..."));
Serial.println(F(""));
Serial.println(F("Initialisiere NeoPixel..."));
pixels.begin(); // This initializes the NeoPixel library.
int progress = 0;
//bootProgress(++progress, true);
Serial.println(F(""));
Serial.println(F("Hole Konfiguration aus EEPROM..."));
Serial.println(F(""));
ReadEEPROMConfig();
//bootProgress(++progress, true);
ShowSysInfo(1);
//bootProgress(++progress, true);
// Show strip in white
for(int i=0; i<NUMPIXELS; i++){
pixels.setPixelColor(i, pixels.Color(255, 255, 255));
pixels.show();
}
Serial.print(F("Verbinde mit WLAN"));
if (STATICIP == 1) {
WiFi.config(ip, gw, sub, dns);
}
WiFi.begin ( WLANSSID.c_str(), WLANPWD.c_str() );
//bootProgress(++progress, true);
// Wait for connection
byte maxtimeout = CONNECTIONTIMEOUT * 2;
byte timeoutcount = 0;
while ( WiFi.status() != WL_CONNECTED ) {
if (isSetup)
break;
delay ( 500 );
Serial.print (F("."));
//bootProgress(++progress, true);
timeoutcount++;
if (timeoutcount >= maxtimeout) {
Serial.println(F(""));
Serial.println(F("Timeout für WLAN-Verbindung"));
WiFi.disconnect();
createAP();
isSetup = true;
//bootProgress(++progress, false);
}
}
if (!isSetup) {
Serial.println (F(""));
Serial.print (F("Connected to "));
Serial.println ( WLANSSID.c_str() );
Serial.print (F("IP address: "));
Serial.println ( WiFi.localIP() );
if (!MDNS.begin(myHostname)) {
Serial.println("Error setting up MDNS responder!");
} else {
Serial.println("mDNS responder started");
// Add service to MDNS-SD
MDNS.addService("http", "tcp", 80);
}
}
httpUpdater.setup(&server);
server.on ( "/", handleRoot );
server.on ( "/generate_204", handleRoot ); //Android captive portal. Maybe not needed. Might be handled by notFound handler.
server.on ( "/fwlink", handleRoot ); //Microsoft captive portal. Maybe not needed. Might be handled by notFound handler.
server.on ( "/color", handleColor );
server.on ( "/timer", handleTimer );
server.on ( "/rainbow", handleRainbow );
server.on ( "/rainbowCycle", handleRainbowCycle );
server.on ( "/setup01", handleSetup01 );
server.on ( "/setup02", handleSetup02 );
server.on ( "/setup03", handleSetup03 );
server.on ( "/setup04", handleSetup04 );
server.on ( "/setup05", handleSetup05 );
server.onNotFound ( handleNotFound );
server.begin();
Serial.println (F("HTTP server started"));
//bootProgress(++progress, true);
Serial.println(F("Hole Uhrzeit ..."));
Serial.println("Starting UDP");
Udp.begin(localPort);
Serial.print("Local port: ");
Serial.println(Udp.localPort());
Serial.println("waiting for sync");
//get a random server from the pool
WiFi.hostByName(ntpServerName, timeServer);
setSyncProvider(getNtpTime);
Serial.print(F("Aktuelle Zeit: "));
Serial.print(hour());
Serial.print(":");
Serial.print(minute());
Serial.print(":");
Serial.print(second());
Serial.print(" ");
Serial.print(day());
Serial.print(".");
Serial.print(month());
Serial.print(".");
Serial.println(year());
Serial.println(F("Uhrzeit gesetzt."));
//bootProgress(++progress, true);
checkTime = millis();
curCheckTimeOn = checkTimerOn();
prevCheckTimeOn = !curCheckTimeOn;
// set previous colors to white
for(int i=0; i<NUMPIXELS; i++) {
prevColors[i] = pixels.Color(255, 255, 255);
}
}
void loop ( void ) {
//DNS
dnsServer.processNextRequest();
//HTTP
server.handleClient();
if (millis() - checkTime > MAXCHECKTIME) {
checkTime = millis();
curCheckTimeOn = checkTimerOn();
if (prevCheckTimeOn != curCheckTimeOn) {
if (curCheckTimeOn) {
Serial.println("Statuswechsel: Licht an");
for(int i=0; i<NUMPIXELS; i++){
pixels.setPixelColor(i, prevColors[i]);
pixels.show();
}
} else {
Serial.println("Statuswechsel: Licht aus");
for(int i=0; i<NUMPIXELS; i++) {
prevColors[i] = pixels.getPixelColor(i);
pixels.setPixelColor(i, pixels.Color(0, 0, 0));
pixels.show();
}
}
}
prevCheckTimeOn = curCheckTimeOn;
}
// rainbow
if (brainbow && checkTimerOn()) {
uint16_t i, j;
for(j=0; j<256; j++) {
for(i=0; i<pixels.numPixels(); i++) {
pixels.setPixelColor(i, Wheel((i+j) & 255));
server.handleClient();
if (brainbow == false) break;
}
pixels.show();
delay(40);
server.handleClient();
if (brainbow == false) break;
}
} // if
// rainbowCycle
if (brainbowCycle && checkTimerOn()) {
uint16_t i, j;
for(j=0; j<256*5; j++) { // 5 cycles of all colors on wheel
for(i=0; i< pixels.numPixels(); i++) {
pixels.setPixelColor(i, Wheel(((i * 256 / pixels.numPixels()) + j) & 255));
server.handleClient();
if (brainbowCycle == false) break;
}
pixels.show();
delay(20);
server.handleClient();
if (brainbowCycle == false) break;
}
}
}
NTP.ino
/*-------- NTP code ----------*/
const int NTP_PACKET_SIZE = 48; // NTP time is in the first 48 bytes of message
byte packetBuffer[NTP_PACKET_SIZE]; //buffer to hold incoming & outgoing packets
time_t getNtpTime()
{
while (Udp.parsePacket() > 0) ; // discard any previously received packets
Serial.println("Transmit NTP Request");
sendNTPpacket(timeServer);
delay(1000);
uint32_t beginWait = millis();
while (millis() - beginWait < 1500) {
int size = Udp.parsePacket();
if (size >= NTP_PACKET_SIZE) {
Serial.println("Receive NTP Response");
Udp.read(packetBuffer, NTP_PACKET_SIZE); // read packet into the buffer
unsigned long secsSince1900;
// convert four bytes starting at location 40 to a long integer
secsSince1900 = (unsigned long)packetBuffer[40] << 24;
secsSince1900 |= (unsigned long)packetBuffer[41] << 16;
secsSince1900 |= (unsigned long)packetBuffer[42] << 8;
secsSince1900 |= (unsigned long)packetBuffer[43];
return secsSince1900 - 2208988800UL + timeZone * SECS_PER_HOUR;
}
}
Serial.println("No NTP Response :-(");
return 0; // return 0 if unable to get the time
}
// send an NTP request to the time server at the given address
void sendNTPpacket(IPAddress &address)
{
// set all bytes in the buffer to 0
memset(packetBuffer, 0, NTP_PACKET_SIZE);
// Initialize values needed to form NTP request
// (see URL above for details on the packets)
packetBuffer[0] = 0b11100011; // LI, Version, Mode
packetBuffer[1] = 0; // Stratum, or type of clock
packetBuffer[2] = 6; // Polling Interval
packetBuffer[3] = 0xEC; // Peer Clock Precision
// 8 bytes of zero for Root Delay & Root Dispersion
packetBuffer[12] = 49;
packetBuffer[13] = 0x4E;
packetBuffer[14] = 49;
packetBuffer[15] = 52;
// all NTP fields have been given values, now
// you can send a packet requesting a timestamp:
Udp.beginPacket(address, 123); //NTP requests are to port 123
Udp.write(packetBuffer, NTP_PACKET_SIZE);
Udp.endPacket();
}
EEPROM.ino
void ReadEEPROMConfig() {
EEPROM.begin(512);
EEPROM.get(2,CONNECTIONTIMEOUT);
Serial.print(F("CONNECTIONTIMEOUT="));
Serial.println(CONNECTIONTIMEOUT);
EEPROM.get(4,STATICIP);
Serial.print(F("STATICIP="));
Serial.println(STATICIP);
ip[0]=EEPROM.read(5);
ip[1]=EEPROM.read(6);
ip[2]=EEPROM.read(7);
ip[3]=EEPROM.read(8);
gw[0]=EEPROM.read(9);
gw[1]=EEPROM.read(10);
gw[2]=EEPROM.read(11);
gw[3]=EEPROM.read(12);
sub[0]=EEPROM.read(13);
sub[1]=EEPROM.read(14);
sub[2]=EEPROM.read(15);
sub[3]=EEPROM.read(16);
dns[0]=EEPROM.read(17);
dns[1]=EEPROM.read(18);
dns[2]=EEPROM.read(19);
dns[3]=EEPROM.read(20);
Serial.print(F("IP="));
Serial.println(ip);
Serial.print(F("GATEWAY="));
Serial.println(gw);
Serial.print(F("SUBNET="));
Serial.println(sub);
Serial.print(F("DNS="));
Serial.println(dns);
WLANSSID="";
for (int i = 21; i < 53; ++i)
{
WLANSSID += char(EEPROM.read(i));
}
Serial.print(F("WLANSSID="));
Serial.println(WLANSSID.c_str());
WLANPWD="";
for (int i = 53; i < 117; ++i)
{
WLANPWD += char(EEPROM.read(i));
}
Serial.print(F("WLANPWD="));
Serial.println(WLANPWD.c_str());
EEPROM.get(117, ontimeHour);
EEPROM.get(118, ontimeMinute);
Serial.print(F("Einschaltzeit="));
if (ontimeHour < 9) Serial.print("0");
Serial.print(ontimeHour);
Serial.print(":");
if (ontimeMinute < 9) Serial.print("0");
Serial.println(ontimeMinute);
EEPROM.get(119, offtimeHour);
EEPROM.get(120, offtimeMinute);
Serial.print(F("Ausschaltzeit="));
if (offtimeHour < 9) Serial.print("0");
Serial.print(offtimeHour);
Serial.print(":");
if (offtimeMinute < 9) Serial.print("0");
Serial.println(offtimeMinute);
EEPROM.end();
}
tools.ino
/** Is this an IP? */
boolean isIp(String str) {
for (int i = 0; i < str.length(); i++) {
int c = str.charAt(i);
if (c != '.' && (c < '0' || c > '9')) {
return false;
}
}
return true;
}
/** IP to String? */
String toStringIp(IPAddress ip) {
String res = "";
for (int i = 0; i < 3; i++) {
res += String((ip >> (8 * i)) & 0xFF) + ".";
}
res += String(((ip >> 8 * 3)) & 0xFF);
return res;
}
// Input a value 0 to 255 to get a color value.
// The colours are a transition r - g - b - back to r.
uint32_t Wheel(byte WheelPos) {
WheelPos = 255 - WheelPos;
if(WheelPos < 85) {
return pixels.Color(255 - WheelPos * 3, 0, WheelPos * 3);
}
if(WheelPos < 170) {
WheelPos -= 85;
return pixels.Color(0, WheelPos * 3, 255 - WheelPos * 3);
}
WheelPos -= 170;
return pixels.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
}
void ShowSysInfo(int typ) {
if (typ==1) {
Serial.print(F("Software-Version: "));
Serial.println(SOFTWAREVERSION);
Serial.print(F("SDK-Version: "));
Serial.println(ESP.getSdkVersion());
Serial.print(F("ESP8266 Chip-ID: "));
Serial.println(ESP.getChipId());
Serial.print(F("ESP8266 Speed: "));
Serial.print(ESP.getCpuFreqMHz());
Serial.println(F(" MHz"));
Serial.print(F("Free Sketch Space: "));
Serial.print(ESP.getFreeSketchSpace());
Serial.println(F(" Bytes"));
Serial.print(F("Sketch Size: "));
Serial.print(ESP.getSketchSize());
Serial.println(F(" Bytes"));
}
Serial.print(F("Free Heap Size: "));
Serial.print(ESP.getFreeHeap());
Serial.println(F(" Bytes"));
Serial.print(F("Systemspannung: "));
Serial.print(String(ESP.getVcc()).substring(0,1));
Serial.print(F(","));
Serial.print(String(ESP.getVcc()).substring(1));
Serial.println(F(" Volt"));
Serial.println(F(""));
}
void bootProgress(int progress, bool color) {
if (progress > NUMPIXELS) progress = progress - NUMPIXELS;
for(int i=0; i < progress; i++) {
if (color == true) {
pixels.setPixelColor(i, pixels.Color(0, 255, 0));
} else {
pixels.setPixelColor(i, pixels.Color(255, 0, 0));
}
}
for(int i=progress+1; i < NUMPIXELS; i++) {
pixels.setPixelColor(i, pixels.Color(0, 0, 0));
}
pixels.show();
}
setup.ino
///////////////////////////////////////////////////////
// Scan nach verfügbaren WLAN (2,4 GHz)
///////////////////////////////////////////////////////
String wlanScan() {
Serial.println(F(""));
Serial.println(F("WLAN-Netzwerk-Scan gestartet..."));
int n = WiFi.scanNetworks();
Serial.println(F("WLAN-Netzwerk-Scan abgeschlossen."));
Serial.println(F(""));
if (n == 0) {
Serial.println(F("Kein WLAN-Netzwerk gefunden!"));
} else {
Serial.print(n);
if(n<=1) {
Serial.println(F(" WLAN-Netzwerk gefunden"));
} else {
Serial.println(F(" WLAN-Netzwerke gefunden"));
}
Serial.println(F(""));
for (int i = 0; i < n; ++i) {
Serial.print(i + 1);
Serial.print(F(": "));
Serial.print(WiFi.SSID(i));
Serial.print(F(" ("));
Serial.print(WiFi.RSSI(i));
Serial.print(F(")"));
Serial.println((WiFi.encryptionType(i) == ENC_TYPE_NONE)?" ":"*");
}
}
String HTMLFORMULARWLAN = "";
for (int i = 0; i < n; ++i) {
// Erstelle Webseite mit allen SSID und RSSI Werten der gefundenen Netzwerke
HTMLFORMULARWLAN += "<input type='radio' name='WLANSSID' value='";
HTMLFORMULARWLAN += WiFi.SSID(i);
HTMLFORMULARWLAN += "'";
HTMLFORMULARWLAN += ">";
HTMLFORMULARWLAN += WiFi.SSID(i);
HTMLFORMULARWLAN += " (";
if (WiFi.RSSI(i) >= -85)
HTMLFORMULARWLAN += ".";
if (WiFi.RSSI(i) >= -75)
HTMLFORMULARWLAN += "o";
if (WiFi.RSSI(i) >= -55)
HTMLFORMULARWLAN += "O";
HTMLFORMULARWLAN += ")";
HTMLFORMULARWLAN += (WiFi.encryptionType(i) == ENC_TYPE_NONE)?" ":" *";
HTMLFORMULARWLAN += "<br />";
}
Serial.println(F(""));
return HTMLFORMULARWLAN;
}
///////////////////////////////////////////////////////
// Erste Setup-Seite mit Starttext
///////////////////////////////////////////////////////
void handleSetup01() {
for(int i=0; i<NUMPIXELS; i++) {
prevColors[i] = pixels.Color(255, 0, 255);
}
Serial.println(F("Lade Setup01..."));
String temp = "<!DOCTYPE html><html><head>";
temp += "<meta name='viewport' content='initial-scale=1.0, user-scalable=no' />";
temp += "<meta name='apple-mobile-web-app-capable' content='yes' />";
temp += "<meta name='apple-mobile-web-app-status-bar-style' content='black' />";
temp += "<title></title></head>";
temp += "<body style='font-family:Verdana, Arial, Sans-Serif'><center>";
temp += "<br /><br /><fieldset style='width:300px'><br />";
temp += "<b>Herzlich Willkommen zum Setup<br />";
temp += "von Caro's Wichtelgeschenk 2017.<br /><br />";
temp += "Du wirst jetzt Schritt für Schritt<br />";
temp += "durch das Setup geführt.<br /><br /></fieldset><br />";
temp += "<form method='POST' action='setup02'>";
temp += "<input type='submit' value='Weiter zu Schritt 1...'></form>";
temp += "</center></body></html>";
server.send ( 200, "text/html", temp );
Serial.println(F("Setup01 angezeigt."));
}
///////////////////////////////////////////////////////
// Auwahl SSID und Eingabe Passwort
///////////////////////////////////////////////////////
void handleSetup02() {
Serial.println(F("Lade Setup02..."));
String temp = "<!DOCTYPE html><html><head>";
temp += "<meta name='viewport' content='initial-scale=1.0, user-scalable=no' />";
temp += "<meta name='apple-mobile-web-app-capable' content='yes' />";
temp += "<meta name='apple-mobile-web-app-status-bar-style' content='black' />";
temp += "<script>";
temp += "function checkForm(form) {";
temp += "if(radioValue = checkRadio(form.WLANSSID)) {";
temp += "return true;";
temp += "} else {";
temp += "alert('Bitte ein WLAN auswählen!');";
temp += "return false;";
temp += "}}";
temp += "function checkRadio(field) {";
temp += "if((typeof field.length == 'undefined') && (field.type == 'radio')) {";
temp += "if(field.checked) return field.value;";
temp += "} else {";
temp += "for(var i=0; i < field.length; i++) {";
temp += "if(field[i].checked) return field[i].value;";
temp += "}}";
temp += "return false;";
temp += "}";
temp += "</script>";
temp += "<title></title></head>";
temp += "<body style='font-family:Verdana, Arial, Sans-Serif'><center>";
temp += "<br /><br /><fieldset style='width:300px'><legend>Setup Schritt 1</legend>";
temp += "<form method='POST' action='setup03' onsubmit='return checkForm(this);'>";
temp += "<br /><b>WLAN Einstellungen</b><br /><hr /><br />";
temp += "<b><u>WLAN-Netzwerk auswählen:</u></b><br /><br />";
temp += "<div style='text-align:left;width:200px;'>";
temp += wlanScan();
temp += "</div>";
temp += "<br />WLAN-Passwort: <input name='WLANPWD' type='password' size='30' maxlength='64' value=''></input><br />";
temp += "<br />Verbindungs-Timeout: ";
temp += "<select name='CONNECTIONTIMEOUT' size='1'>";
temp += "<option value='10' selected>10</option><option value='30'>30</option><option value='60'>60</option>";
temp += "</select> Sekunden<br />";
temp += "<br /></fieldset>";
temp += "<br /><input type='submit' value='Einstellungen speichern und weiter zu Schritt 2...'></form>";
temp += "</center></body></html>";
server.send ( 200, "text/html", temp );
Serial.println(F("Setup02 angezeigt."));
}
///////////////////////////////////////////////////////
// Speichern SSID und Passwort in EEPROM
// Auswahl dyn. oder stat. IP
///////////////////////////////////////////////////////
void handleSetup03() {
String NeueWLANSSID;
String NeuesWLANPWD;
int NeuesCONNECTIONTIMEOUT;
Serial.println(F("Hole Server Parameter..."));
if (server.args() > 0) {
for ( uint8_t i = 0; i < server.args(); i++ ) {
Serial.println("Arg "+ String(i)+":"+ server.argName(i) + " = " + server.arg(i));
if (server.argName(i) == "WLANSSID")
NeueWLANSSID = server.arg(i);
if (server.argName(i) == "WLANPWD")
NeuesWLANPWD = server.arg(i);
if (server.argName(i) == "CONNECTIONTIMEOUT")
NeuesCONNECTIONTIMEOUT = server.arg(i).toInt();
}
}
Serial.println(F("Server Parameter ermittelt."));
Serial.println(F("Schreibe EEPROM..."));
EEPROM.begin(512);
delay(10);
//Lösche alte Konfiguration
for (int i=21; i<117; i++) {
EEPROM.write(i ,0);
}
Serial.println(F(""));
Serial.println(F("Schreibe neue WLANSSID ins EEPROM:"));
for (int i = 0; i < NeueWLANSSID.length(); ++i){
EEPROM.write(21+i, NeueWLANSSID[i]);
Serial.print(F("schreibe: "));
Serial.println(NeueWLANSSID[i]);
}
Serial.println(F(""));
Serial.println(F("Schreibe neues WLANPWD ins EEPROM:"));
for (int i = 0; i < NeuesWLANPWD.length(); ++i){
EEPROM.write(53+i, NeuesWLANPWD[i]);
Serial.print(F("schreibe: "));
Serial.println(NeuesWLANPWD[i]);
}
Serial.println(F(""));
Serial.print(F("Schreibe neues CONNECTIONTIMEOUT ins EEPROM: "));
Serial.print(F("schreibe: "));
Serial.println(NeuesCONNECTIONTIMEOUT);
EEPROM.write(2, NeuesCONNECTIONTIMEOUT);
EEPROM.commit();
EEPROM.end();
Serial.println(F("EEPROM geschrieben."));
Serial.println(F("Lade Setup03..."));
String temp = "<!DOCTYPE html><html><head>";
temp += "<meta name='viewport' content='initial-scale=1.0, user-scalable=no' />";
temp += "<meta name='apple-mobile-web-app-capable' content='yes' />";
temp += "<meta name='apple-mobile-web-app-status-bar-style' content='black' />";
temp += "<script>";
temp += "function checkForm(form) {";
temp += "if (form.STATICIP.value == 1) {";
temp += "if (!ValidateIPaddress(form.IP)) {";
temp += "alert('IP-Adresse nicht korrekt!');";
temp += "return false";
temp += "}";
temp += "if (!ValidateIPaddress(form.GWIP)) {";
temp += "alert('Gateway IP-Adresse nicht korrekt!');";
temp += "return false";
temp += "}";
temp += "if (!ValidateIPaddress(form.MASK)) {";
temp += "alert('Subnet Mask nicht korrekt!');";
temp += "return false";
temp += "}";
temp += "return true;";
temp += "}";
temp += "function ValidateIPaddress(inputText) {";
temp += "var ipformat = /^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/;";
temp += "if(inputText.value != '' && inputText.value.match(ipformat)) { return true; } else { return false; }";
temp += "}";
temp += "}";
temp += "</script>";
temp += "<title></title>";
temp += "</head><body style='font-family:Verdana, Arial, Sans-Serif'><center><br /><br />";
temp += "<br /><br /><fieldset style='width:300px'><legend>Setup Schritt 2</legend>";
temp += "<form method='POST' action='setup04' onsubmit='return checkForm(this);'>";
temp += "<br /><b>IP Einstellungen</b><br /><hr />";
temp += "<br />IP-Adresstyp:";
temp += "<select name='STATICIP' size='1'>";
temp += "<option value='0' selected>DHCP</option>";
temp += "<option value='1'>Statisch</option></select>";
temp += "<br /><br />IP-Adresse:<br />";
temp += "<input name='IP' type='text' size='15' maxlength='15' value=''></input>";
temp += "<br /><br />Gateway IP-Adresse:<br />";
temp += "<input name='GWIP' type='text' size='15' maxlength='15' value=''></input>";
temp += "<br /><br />Subnet Mask:<br />";
temp += "<input name='MASK' type='text' size='15' maxlength='15' value='255.255.255.0'></input>";
temp += "<br /><br />DNS-Server IP-Adresse:<br />";
temp += "<input name='DNSIP' type='text' size='15' maxlength='15' value=''></input>";
temp += "<br /></fieldset>";
temp += "<br /><input type='submit' value='Einstellungen speichern und weiter zu Schritt 3...'>";
temp += "</form></center></body></html>";
server.send ( 200, "text/html", temp );
Serial.println(F("Setup03 angezeigt."));
}
///////////////////////////////////////////////////////
// Speichern stat./dyn. IP im EEPROM
// Abschlussseite Setup
///////////////////////////////////////////////////////
void handleSetup04() {
int NeueSTATICIP;
String NeueIP;
String NeueGWIP;
String NeueMASK;
String NeueDNSIP;
Serial.println(F("Hole Server Parameter..."));
if (server.args() > 0) {
for ( uint8_t i = 0; i < server.args(); i++ ) {
Serial.println("Arg "+ String(i)+":"+ server.argName(i) + " = " + server.arg(i));
if (server.argName(i) == "STATICIP")
NeueSTATICIP = server.arg(i).toInt();
if (server.argName(i) == "IP")
NeueIP = server.arg(i);
if (server.argName(i) == "GWIP")
NeueGWIP = server.arg(i);
if (server.argName(i) == "MASK")
NeueMASK = server.arg(i);
if (server.argName(i) == "DNSIP")
NeueDNSIP = server.arg(i);
}
}
Serial.println(F("Server Parameter ermittelt."));
Serial.println(F("Schreibe EEPROM..."));
int Index1, Index2, Index3;
String Value1, Value2, Value3, Value4;
EEPROM.begin(512);
delay(10);
//Alte Konfigurationsdaten löschen
for (int i=4; i<21; i++) {
EEPROM.write(i, 0);
}
Serial.println(F(""));
Serial.println(F("Schreibe neuen IPTYP ins EEPROM:"));
EEPROM.write(4, NeueSTATICIP);
Serial.print(F("schreibe: "));
Serial.println(NeueSTATICIP);
if (NeueSTATICIP == 1) {
Serial.println(F(""));
Serial.println(F("Schreibe neue IP-Adresse Teil 1 ins EEPROM:"));
Index1 = NeueIP.indexOf('.');
Value1 = NeueIP.substring(0, Index1);
EEPROM.write(5, Value1.toInt());
Serial.print(F("schreibe: "));
Serial.println(Value1);
Serial.println(F(""));
Serial.println(F("Schreibe neue IP-Adresse Teil 2 ins EEPROM:"));
Index2 = NeueIP.indexOf('.', Index1+1);
Value2 = NeueIP.substring(Index1+1, Index2);
EEPROM.write(6, Value2.toInt());
Serial.print(F("schreibe: "));
Serial.println(Value2);
Serial.println(F(""));
Serial.println(F("Schreibe neue IP-Adresse Teil 3 ins EEPROM:"));
Index3 = NeueIP.indexOf('.', Index2+1);
Value3 = NeueIP.substring(Index2+1, Index3);
EEPROM.write(7, Value3.toInt());
Serial.print(F("schreibe: "));
Serial.println(Value3);
Serial.println(F(""));
Serial.println(F("Schreibe neue IP-Adresse Teil 4 ins EEPROM:"));
Value4 = NeueIP.substring(Index3+1);
EEPROM.write(8, Value4.toInt());
Serial.print(F("schreibe: "));
Serial.println(Value4);
Serial.println(F(""));
Serial.println(F("Schreibe neue Gateway IP-Adresse Teil 1 ins EEPROM:"));
Index1 = NeueGWIP.indexOf('.');
Value1 = NeueGWIP.substring(0, Index1);
EEPROM.write(9, Value1.toInt());
Serial.print(F("schreibe: "));
Serial.println(Value1);
Serial.println(F(""));
Serial.println(F("Schreibe neue Gateway IP-Adresse Teil 2 ins EEPROM:"));
Index2 = NeueGWIP.indexOf('.', Index1+1);
Value2 = NeueGWIP.substring(Index1+1, Index2);
EEPROM.write(10, Value2.toInt());
Serial.print(F("schreibe: "));
Serial.println(Value2);
Serial.println(F(""));
Serial.println(F("Schreibe neue Gateway IP-Adresse Teil 3 ins EEPROM:"));
Index3 = NeueGWIP.indexOf('.', Index2+1);
Value3 = NeueGWIP.substring(Index2+1, Index3);
EEPROM.write(11, Value3.toInt());
Serial.print(F("schreibe: "));
Serial.println(Value3);
Serial.println(F(""));
Serial.println(F("Schreibe neue Gateway IP-Adresse Teil 4 ins EEPROM:"));
Value4 = NeueIP.substring(Index3+1);
EEPROM.write(12, Value4.toInt());
Serial.print(F("schreibe: "));
Serial.println(Value4);
Serial.println(F(""));
Serial.println(F("Schreibe neue Subnet Mask Teil 1 ins EEPROM:"));
Index1 = NeueMASK.indexOf('.');
Value1 = NeueMASK.substring(0, Index1);
EEPROM.write(13, Value1.toInt());
Serial.print(F("schreibe: "));
Serial.println(Value1);
Serial.println(F(""));
Serial.println(F("Schreibe neue Subnet Mask Teil 2 ins EEPROM:"));
Index2 = NeueMASK.indexOf('.', Index1+1);
Value2 = NeueMASK.substring(Index1+1, Index2);
EEPROM.write(14, Value2.toInt());
Serial.print(F("schreibe: "));
Serial.println(Value2);
Serial.println(F(""));
Serial.println(F("Schreibe neue Subnet Mask Teil 3 ins EEPROM:"));
Index3 = NeueMASK.indexOf('.', Index2+1);
Value3 = NeueMASK.substring(Index2+1, Index3);
EEPROM.write(15, Value3.toInt());
Serial.print(F("schreibe: "));
Serial.println(Value3);
Serial.println(F(""));
Serial.println(F("Schreibe neue Subnet Mask Teil 4 ins EEPROM:"));
Value4 = NeueMASK.substring(Index3+1);
EEPROM.write(16, Value4.toInt());
Serial.print(F("schreibe: "));
Serial.println(Value4);
if (NeueDNSIP == "") {
NeueDNSIP = NeueIP;
}
Serial.println(F(""));
Serial.println(F("Schreibe neue DNS Server IP-Adresse Teil 1 ins EEPROM:"));
Index1 = NeueDNSIP.indexOf('.');
Value1 = NeueDNSIP.substring(0, Index1);
EEPROM.write(17, Value1.toInt());
Serial.print(F("schreibe: "));
Serial.println(Value1);
Serial.println(F(""));
Serial.println(F("Schreibe neue DNS Server IP-Adresse Teil 2 ins EEPROM:"));
Index2 = NeueDNSIP.indexOf('.', Index1+1);
Value2 = NeueDNSIP.substring(Index1+1, Index2);
EEPROM.write(18, Value2.toInt());
Serial.print(F("schreibe: "));
Serial.println(Value2);
Serial.println(F(""));
Serial.println(F("Schreibe neue DNS Server IP-Adresse Teil 3 ins EEPROM:"));
Index3 = NeueDNSIP.indexOf('.', Index2+1);
Value3 = NeueDNSIP.substring(Index2+1, Index3);
EEPROM.write(19, Value3.toInt());
Serial.print(F("schreibe: "));
Serial.println(Value3);
Serial.println(F(""));
Serial.println(F("Schreibe neue DNS Server IP-Adresse Teil 4 ins EEPROM:"));
Value4 = NeueDNSIP.substring(Index3+1);
EEPROM.write(20, Value4.toInt());
Serial.print(F("schreibe: "));
Serial.println(Value4);
}
EEPROM.commit();
EEPROM.end();
Serial.println(F("EEPROM geschrieben."));
Serial.println(F("Lade Setup04..."));
String temp = "<!DOCTYPE html><html><head>";
temp += "<meta name='viewport' content='initial-scale=1.0, user-scalable=no' />";
temp += "<meta name='apple-mobile-web-app-capable' content='yes' />";
temp += "<meta name='apple-mobile-web-app-status-bar-style' content='black' />";
temp += "<title></title>";
temp += "</head><body style='font-family:Verdana, Arial, Sans-Serif'><center><br /><br />";
temp += "<br /><br /><fieldset style='width:300px'><br />";
temp += "<b>Juhuu! Das Setup<br />";
temp += "ist abgeschlossen.<br /><br />";
temp += "Dein Wichtel-Geschenk <br />";
temp += "startet jetzt neu<br />";
temp += "und versucht sich an<br />";
temp += "Deinem WLAN anzumelden.<br /><br />";
temp += "Wenn das nicht klappt<br />";
temp += "sehen wir uns gleich wieder!<br /><br />";
temp += "<form method='POST' action='setup05'>";
temp += "<input type='submit' value='OK let´s go...'></form><br />";
temp += "</fieldset></center></body></html>";
server.send ( 200, "text/html", temp );
Serial.println(F("Setup04 angezeigt."));
}
///////////////////////////////////////////////////////
// Access Point beenden und Reboot Controller
///////////////////////////////////////////////////////
void handleSetup05() {
Serial.println(F("AP disconnect..."));
WiFi.disconnect();
Serial.println(F("AP beenden..."));
WiFi.softAPdisconnect();
ESP.restart();
}
Video


























