From 6d57da3402c61b43c7000eb8da0b0746f7a09a55 Mon Sep 17 00:00:00 2001 From: Jean Jacques Avril Date: Sun, 20 Mar 2022 16:08:47 +0100 Subject: [PATCH] fixed-> cleanup --- data/settings | Bin 79 -> 79 bytes data/settings.bak | Bin 79 -> 79 bytes src/Config.h | 9 +++------ src/WebConsole.cpp | 41 ++++++++++++++++------------------------- src/main.cpp | 22 +--------------------- 5 files changed, 20 insertions(+), 52 deletions(-) diff --git a/data/settings b/data/settings index 5a79756696b601f967dbef6cfdd74b6f43f5ee95..8b96c303829c8f2a9fb291f5186033c03c65ba02 100644 GIT binary patch delta 16 UcmebGpWwp%|NnmmFyLYZ05fz1iU0rr delta 16 WcmebGpWwoMV1>wkAZBFXVg&#;rUiun diff --git a/data/settings.bak b/data/settings.bak index a64427be648d55c7c9864769938d8e0074c9028b..171c69b10f4f05d7a6d29ea448e449d54d0cfccb 100644 GIT binary patch delta 18 XcmebGpWwtR!gyeX$bSY9;9>;;F&G3L delta 18 YcmebGpWwtBz<6Lqz<(fSWZ+^206_!>P5=M^ diff --git a/src/Config.h b/src/Config.h index f93a3da..11a3f11 100644 --- a/src/Config.h +++ b/src/Config.h @@ -20,12 +20,9 @@ public: ~Config(); const char *SSID = (char *)(buffer + OFFSET_SSID); const char *PASS = (char *)(buffer + OFFSET_PASS); - uint32_t *ip_ptr = (uint32_t*)(buffer+OFFSET_IP); - uint32_t &ip = *ip_ptr; - uint32_t *subnet_ptr = (uint32_t*)(buffer+OFFSET_SUBNET); - uint32_t &subnet = *subnet_ptr; - uint32_t *gw_ptr = (uint32_t*)(buffer+OFFSET_GW); - uint32_t &gw = *gw_ptr; + uint32_t &ip = *((uint32_t*)(buffer+OFFSET_IP)); + uint32_t &subnet = *((uint32_t*)(buffer+OFFSET_SUBNET)); + uint32_t &gw = *((uint32_t*)(buffer+OFFSET_GW)); uint8_t &mode = *(buffer + OFFSET_MODE); uint8_t &fail_timeout = *(buffer+OFFSET_FAIL_TIMEOUT); uint8_t &hold_time = *(buffer+OFFSET_HOLD_TIME); diff --git a/src/WebConsole.cpp b/src/WebConsole.cpp index 0fd0998..1e54a2e 100644 --- a/src/WebConsole.cpp +++ b/src/WebConsole.cpp @@ -15,30 +15,22 @@ bool WebConsole::init(Config *config, userdb::UserDb *userdb) this->userdb = userdb; this->_config = config; this->userdb = userdb; + // Wifi Setup + this->_dnsServer = new DNSServer; + WiFi.mode(WIFI_AP); + Serial.print("\t1. Network config... "); + Serial.println(WiFi.softAPConfig(_config->ip, _config->gw, _config->subnet) ? "Ready" : "Failed!"); + Serial.print("\t2. DNS config... "); + Serial.println(_dnsServer->start(53, "*", _config->ip) ? "Ready" : "Failed!"); + Serial.print("\t3 AP setup SSID) + "\"..."); + if (strlen(_config->PASS) > 0) + Serial.println(WiFi.softAP(_config->SSID, _config->PASS) ? "Ready" : "Failed!"); + else + Serial.println(WiFi.softAP(_config->SSID) ? "Ready" : "Failed!"); + WiFi.hostname("Doorlock"); + Serial.println("Please connect via http://" +WiFi.softAPIP().toString()+"/"); - // this->_dnsServer = new DNSServer; - // WiFi.mode(WIFI_AP); - // - // uint8_t *ipp = (uint8_t *)_config->ip_ptr; - // uint8_t *gwp = (uint8_t *)_config->gw_ptr; - // uint8_t *snp = (uint8_t *)_config->subnet_ptr; - //// IPAddress ip(*(ipp), *(ipp + 1), *(ipp + 2), *(ipp + 3)); - //// IPAddress gw(*(gwp), *(gwp + 1), *(gwp + 2), *(gwp + 3)); - //// IPAddress subnet(*(snp), *(snp + 1), *(snp + 2), *(snp + 3)); - // - // Serial.print("\t1. Network config ->"); - // Serial.println(WiFi.softAPConfig(ipp, gwp, snp) ? "Ready" : "Failed!"); - // Serial.print("\t2. DNS config ->"); - // //Serial.println(_dnsServer->start(53, "*", ip) ? "Ready" : "Failed!"); - // - // Serial.print("\t3 AP setup " + String(_config->SSID) + " -> "); - // if (strlen(_config->PASS) > 0) - // Serial.println(WiFi.softAP(_config->SSID, _config->PASS) ? "Ready" : "Failed!"); - // else - // Serial.println(WiFi.softAP(_config->SSID) ? "Ready" : "Failed!"); - // WiFi.hostname("Doorlock"); - // Serial.println(WiFi.softAPIP()); - // + // Webserver Setup this->_server = new ESP8266WebServer(80); const char *headerkeys[] = {"Authentification"}; size_t headerkeyssize = sizeof(headerkeys) / sizeof(char *); @@ -54,7 +46,6 @@ bool WebConsole::init(Config *config, userdb::UserDb *userdb) _server->on(UriBraces("/api/user/{}"), HTTPMethod::HTTP_PUT, std::bind(&WebConsole::_createUser, this)); _server->on(UriBraces("/api/user/{}"), HTTPMethod::HTTP_POST, std::bind(&WebConsole::_updateUser, this)); _server->on(UriBraces("/api/config/{}"), std::bind(&WebConsole::_deleteUser, this)); - //_server->on("/bypin",std::bind(&WebConsole::_findPin,this)); _server->serveStatic("/", LittleFS, "/s/"); _server->onNotFound(std::bind(&WebConsole::_handleUnknown, this)); return true; @@ -65,7 +56,7 @@ void WebConsole::attachRfid(Rfid *rfid) } void WebConsole::serve() { - //_dnsServer->processNextRequest(); + _dnsServer->processNextRequest(); if (catch_rfid) { if (millis() - catch_rfid_millis > 2000) diff --git a/src/main.cpp b/src/main.cpp index 904476a..525e2bb 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -8,8 +8,6 @@ #include "WebConsole.h" #include "UserDb.h" #include "Config.h" -#include -#include // File config Config config; @@ -23,28 +21,11 @@ Rfid rfid; Keyboard keyboard(200); Interface iface; -//DNSServer dnsServer; void setup() { config.loadBin(); Serial.begin(115200); - Serial.println("Starting System"); - IPAddress ip(192, 168, 80, 1); - IPAddress gw(192, 168, 80, 1); - IPAddress subnet(192, 168, 80, 255); - WiFi.mode(WIFI_AP); - Serial.print("\t1. Network config ->"); - Serial.println(WiFi.softAPConfig(ip, gw, subnet) ? "Ready" : "Failed!"); - Serial.print("\t2. DNS config ->"); - //Serial.println(dnsServer.start(53, "*", ip) ? "Ready" : "Failed!"); - Serial.print("\t3 AP setup " + String(config.SSID) + " -> "); - if (strlen(config.PASS) > 0) - Serial.println(WiFi.softAP(config.SSID, config.PASS) ? "Ready" : "Failed!"); - else - Serial.println(WiFi.softAP(config.SSID) ? "Ready" : "Failed!"); - WiFi.hostname("Doorlock"); - delay(50); - Serial.println(WiFi.softAPIP()); + Serial.println("Starting System..."); #ifdef DEBUG userdatabase.print_to_serial(); #endif @@ -58,7 +39,6 @@ void setup() void loop() { - //dnsServer.processNextRequest(); rfid.scan(); web.serve(); keyboard.scanAsync();