V2.17 230227 alle unbekannten Seiten Leiten auf die IP um

This commit is contained in:
2023-02-27 13:01:57 +01:00
parent 04e2975cb1
commit addcac6d6e
3 changed files with 76 additions and 1555 deletions

View File

@@ -1,4 +1,13 @@
#define VERSION (char *) "V2.11"
#define VERSION (char *) "V2.17"
/*
V2.12 230205 neues SDK 8266; AP+Wifi Client; lokaleip eingebaut
V2.13 230206 Datum/Uhrzeit zeit auch KW an
V2.14 230208 AP+STA nur wenn Wifi verbunden ist sonst geht der AP nicht
V2.15 230212 Verbesserung AP_STA modus;Wlan auf 1 Connect beschränkt;
V2.16 230212 MaxConnect auf 2; Beacon auf 250ms
V2.17 230227 alle unbekannten Seiten Leiten auf die IP um
*/
// Pins for LED MATRIX
#include <Ticker.h>
@@ -10,7 +19,7 @@
#define P_D 0
//#define P_E 0
#define P_OE 2
#define PxMATRIX_COLOR_DEPTH 3 // This is how many color levels the display shows - the more the slower the update
#define PxMATRIX_COLOR_DEPTH 2 // This is how many color levels the display shows - the more the slower the update
#define double_buffer // Creates a second buffer for backround drawing (doubles the required RAM)
#define MATRIX_WIDTH 64
#define MATRIX_HEIGHT 32
@@ -33,11 +42,26 @@
IPAddress ip_local(192, 168, 13, 1);
IPAddress ip_gateway(192, 168, 13, 1);
IPAddress ip_subnet(255, 255, 255, 0);
char localip[16];
boolean APEnabled = false;
char ssid[30] = "THW Freifunk";
char pass[30] = "";
char appass[30] = "gibteskeins";
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;
}
void html_handle_notsuccess(AsyncWebServerRequest *request);
void html_handle_notsuccess(AsyncWebServerRequest *request){
request->send(200, "text/html", String("<a href='http://") + toStringIp(ip_local) + String("'>zur Konfigurationsseite</a><script> location.href = 'http://") + toStringIp(ip_local) + String("'; </script>"));
}
//permanenter Speicher
#include <ESP_EEPROM.h>
@@ -119,10 +143,10 @@ void LineV(uint8_t x, uint8_t y, uint8_t z, uint8_t red, uint8_t green, uint8_t
}
//eigene Schriften
#include "D:\arduino\Projekte\_includes\char3x5.h"
#include "D:\arduino\Projekte\_includes\char5x7.h"
#include "D:\arduino\Projekte\_includes\char6x8.h"
#include "D:\arduino\Projekte\_includes\char10x16.h"
#include <char3x5.h>
#include <char5x7.h>
#include <char6x8.h>
#include <char10x16.h>
void doClearLEDsSeconds(int8_t ycorrection=0){
@@ -344,12 +368,6 @@ void drawSeconds(time_t t,int8_t ycorrection=0){
void showTimeTactical(time_t t){
uint16_t tmp = 0;
uint8_t x = 0;
uint8_t y = 0;
uint8_t r = timeColor[0];
uint8_t g = timeColor[1];
uint8_t b = timeColor[2];
tmp = minute(t);
if(lastminutes != tmp){
@@ -393,7 +411,7 @@ void drawDate(time_t t){
uint8_t g = dateColor[1];
uint8_t b = dateColor[2];
uint8_t x = 2;
uint8_t y = 3;
uint8_t y = 0;
UnixTime stamp(0);
stamp.getDateTime(t);
@@ -455,9 +473,17 @@ void drawDate(time_t t){
void showDateTime(time_t t){
doClearLEDs();
drawDate(t);
drawTime(t);
drawTime(t,-6);
if(withSeconds)
drawSeconds(t);
drawSeconds(t,-6);
uint8_t kw = GetWeekNumber(year(t),month(t),day(t));
char str[6];
char kws[3];
itoa(kw,kws,10);
strcpy(str, "KW ");
strcat(str, kws);
show3x5(0,26,str,kwColor[0],kwColor[1],kwColor[2]);
}
uint8_t clock_center_x = 16;
@@ -723,6 +749,9 @@ void setup() {
strcpy(APName, "NTUhr VPx ");
strcat(APName, ChipID);
WiFi.persistent(false);
WiFi.mode(WIFI_AP_STA);
WiFi.begin(ssid,pass);
WiFi.hostname(NetName);
int xc = 0;
@@ -733,7 +762,6 @@ void setup() {
display_doupdate();
}
if (WiFi.status() == WL_CONNECTED) {
char localip[16];
char str[5];
IPAddress lip;
lip = WiFi.localIP();
@@ -764,14 +792,11 @@ void setup() {
if(timenow > SECS_YR_2000){
timenow += 1;
int Year;
byte Month, Day, Hour, Minute, Second;
byte Month, Day, Hour;
setTime(timenow);
Year = year(timenow);
Month = month(timenow);
Day = day(timenow);
Hour = hour(timenow);
Minute = minute(timenow);
Second = second(timenow);
if(isDayLight(Hour,Day,weekday(),Month))
timenow += (SECS_PER_HOUR * 2);
else
@@ -793,18 +818,19 @@ void setup() {
display_doupdate();
alwaysAccessPoint = true;
}
if(alwaysAccessPoint){
WiFi.disconnect();
delay(1000);
ESP.eraseConfig();
delay(1000);
WiFi.mode(WIFI_OFF);
WiFi.mode(WIFI_AP);
delay(1000);
if (WiFi.status() != WL_CONNECTED) {
WiFi.disconnect();
delay(100);
WiFi.mode(WIFI_OFF);
delay(100);
WiFi.mode(WIFI_AP);
}
delay(100);
WiFi.softAPConfig(ip_local, ip_gateway, ip_subnet);
//appass = ;
APEnabled = WiFi.softAP(APName, appass,2,0,1);
APEnabled = WiFi.softAP(APName, appass,2,0,2,250);
if(!APEnabled)
display.drawPixelRGB888(3,0,255,0,0);
else
@@ -818,17 +844,19 @@ void setup() {
display_doupdate();
//für die automatische Umleitung
webServer.on("/generate_204", HTTP_GET, [](AsyncWebServerRequest *request){html_redirect(request);}); //Android captive portal.
webServer.on("/fwlink", HTTP_GET, [](AsyncWebServerRequest *request){html_redirect(request);}); //Microsoft captive portal.
webServer.on("/connecttest.txt", HTTP_GET, [](AsyncWebServerRequest *request){html_redirect(request);}); //www.msftconnecttest.com
webServer.on("/hotspot-detect.html", HTTP_GET, [](AsyncWebServerRequest *request){html_redirect(request);}); //captive.apple.com
/*webServer.on("/generate_204", HTTP_GET, [](AsyncWebServerRequest *request){html_root(request);}); //Android captive portal.
webServer.on("/fwlink", HTTP_GET, [](AsyncWebServerRequest *request){html_root(request);}); //Microsoft captive portal.
webServer.on("/connecttest.txt", HTTP_GET, [](AsyncWebServerRequest *request){html_root(request);}); //www.msftconnecttest.com
webServer.on("/hotspot-detect.html", HTTP_GET, [](AsyncWebServerRequest *request){html_root(request);}); //captive.apple.com
webServer.on("/success.txt", HTTP_GET, [](AsyncWebServerRequest *request){html_handle_success(request);}); //detectportal.firefox.com/sucess.txt
webServer.onNotFound([](AsyncWebServerRequest *request){html_redirect(request);});
webServer.on("/redirect", HTTP_GET, [](AsyncWebServerRequest *request){html_root(request);}); //Microsoft captive portal.*/
webServer.onNotFound([](AsyncWebServerRequest *request){html_handle_notsuccess(request);});
//eigene Seiten
webServer.on("/", HTTP_GET, [](AsyncWebServerRequest *request){html_root(request);});
webServer.on("/do", HTTP_GET, [] (AsyncWebServerRequest *request) {html_do(request);});
webServer.on("/poll", HTTP_GET, [] (AsyncWebServerRequest *request) {html_poll(request);});
//webServer.on("/resetAP", HTTP_GET, [] (AsyncWebServerRequest *request) {html_resetAP(request);});
AsyncElegantOTA.begin(&webServer); // Start AsyncElegantOTA
webServer.begin();
@@ -856,7 +884,7 @@ void loop(){
Minute = minute(currentUNIXTime);
Second = second(currentUNIXTime);
WDay = weekday();
if((isDayLight(Hour,Day,WDay,Month) != iDL) && ((Month == 10 & Hour >= 3) | (Month == 3))){
if((isDayLight(Hour,Day,WDay,Month) != iDL) && (((Month == 10) & (Hour >= 3)) | (Month == 3))){
if(iDL){
doSetTime(currentUNIXTime - SECS_PER_HOUR);
}else{
@@ -887,6 +915,7 @@ void loop(){
showAnalogTime(currentUNIXTime);
showAnalogDate(currentUNIXTime);
break;
}
display_doupdate();
@@ -1091,12 +1120,22 @@ void html_do(AsyncWebServerRequest *request) {
request->send(200, "text/plain", "NOK");
}
void html_resetAP(AsyncWebServerRequest *request) {
String s_value = "";
s_value.toCharArray(appass, 30);
EEPROM.put(151,appass);
EEPROM.commit();
request->send(200, "text/plain", "OK");
}
// Replaces placeholder with button section in your web page
char * html_processor(const String& var){
if(var == "VERSION"){
return VERSION;
}else if(var == "ID"){
return ChipID;
}else if(var == "LOCALIP"){
return localip;
}
return (char *) "not defined";
}
@@ -1109,22 +1148,3 @@ String toggleState(int toggle){
}
return "";
}
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;
}
void html_redirect(AsyncWebServerRequest *request){
AsyncWebServerResponse *response = request->beginResponse(302, "text/plain", ""); // Empty content inhibits Content-length header so we have to close the socket ourselves.
response->addHeader("Location", String("http://") + toStringIp(ip_local));
request->send(response);
}
void html_handle_success(AsyncWebServerRequest *request){
request->send(200, "text/plain", "success");
}

1500
PxMatrix.h

File diff suppressed because it is too large Load Diff

View File

@@ -175,6 +175,7 @@ const char html_page_index[] PROGMEM = R"rawliteral(
<h1>N-Tools Uhr VPx</h1>
<h3>`VERSION`</h3>
<h3>`ID`</h3>
<span style='font-size: 0.7rem;'>lokale IP: `LOCALIP`</span>
</div>
<div id="site" class="site">
<div id="message"></div>