commit d1bea7b04ca11667c0ba7f1caad63e85eb70649e Author: bdrtr Date: Thu May 23 09:11:29 2024 +0300 closed-beta diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..89cc49c --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +.pio +.vscode/.browse.c_cpp.db* +.vscode/c_cpp_properties.json +.vscode/launch.json +.vscode/ipch diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000..080e70d --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,10 @@ +{ + // See http://go.microsoft.com/fwlink/?LinkId=827846 + // for the documentation about the extensions.json format + "recommendations": [ + "platformio.platformio-ide" + ], + "unwantedRecommendations": [ + "ms-vscode.cpptools-extension-pack" + ] +} diff --git a/include/README b/include/README new file mode 100644 index 0000000..194dcd4 --- /dev/null +++ b/include/README @@ -0,0 +1,39 @@ + +This directory is intended for project header files. + +A header file is a file containing C declarations and macro definitions +to be shared between several project source files. You request the use of a +header file in your project source file (C, C++, etc) located in `src` folder +by including it, with the C preprocessing directive `#include'. + +```src/main.c + +#include "header.h" + +int main (void) +{ + ... +} +``` + +Including a header file produces the same results as copying the header file +into each source file that needs it. Such copying would be time-consuming +and error-prone. With a header file, the related declarations appear +in only one place. If they need to be changed, they can be changed in one +place, and programs that include the header file will automatically use the +new version when next recompiled. The header file eliminates the labor of +finding and changing all the copies as well as the risk that a failure to +find one copy will result in inconsistencies within a program. + +In C, the usual convention is to give header files names that end with `.h'. +It is most portable to use only letters, digits, dashes, and underscores in +header file names, and at most one dot. + +Read more about using header files in official GCC documentation: + +* Include Syntax +* Include Operation +* Once-Only Headers +* Computed Includes + +https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html diff --git a/lib/README b/lib/README new file mode 100644 index 0000000..6debab1 --- /dev/null +++ b/lib/README @@ -0,0 +1,46 @@ + +This directory is intended for project specific (private) libraries. +PlatformIO will compile them to static libraries and link into executable file. + +The source code of each library should be placed in a an own separate directory +("lib/your_library_name/[here are source files]"). + +For example, see a structure of the following two libraries `Foo` and `Bar`: + +|--lib +| | +| |--Bar +| | |--docs +| | |--examples +| | |--src +| | |- Bar.c +| | |- Bar.h +| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html +| | +| |--Foo +| | |- Foo.c +| | |- Foo.h +| | +| |- README --> THIS FILE +| +|- platformio.ini +|--src + |- main.c + +and a contents of `src/main.c`: +``` +#include +#include + +int main (void) +{ + ... +} + +``` + +PlatformIO Library Dependency Finder will find automatically dependent +libraries scanning project source files. + +More information about PlatformIO Library Dependency Finder +- https://docs.platformio.org/page/librarymanager/ldf.html diff --git a/lib/fProcess/fProcess.cpp b/lib/fProcess/fProcess.cpp new file mode 100644 index 0000000..f6c49e0 --- /dev/null +++ b/lib/fProcess/fProcess.cpp @@ -0,0 +1,240 @@ +#include "fProcess.h" +#include +#include + + + +fProcess::fProcess() { + +}; + +void fProcess::Initialize() { + +} + +void fProcess::delDB() { + + Adafruit_Fingerprint finger = Adafruit_Fingerprint(&Serial2); + finger.emptyDatabase(); +} + +void fProcess::enRoll(uint16_t id) { + + + Adafruit_Fingerprint finger = Adafruit_Fingerprint(&Serial2); + finger.begin(57600); + + int data = -1; + Serial.print("Parmak izi şu kullanıcı için bekleniyor # "); Serial.println(id); + while (data != FINGERPRINT_OK) { + data = finger.getImage(); + switch (data) { + case FINGERPRINT_OK: + Serial.println("Parmak izi alındı "); + break; + case FINGERPRINT_NOFINGER: + Serial.print("."); + break; + case FINGERPRINT_PACKETRECIEVEERR: + Serial.println("Bağlantı hatası"); + break; + case FINGERPRINT_IMAGEFAIL: + Serial.println("Hatalı resim"); + break; + default: + Serial.println("Bir hata meydana geldi"); + break; + } + } + + + data = finger.image2Tz(1); + switch (data) { + case FINGERPRINT_OK: + Serial.println("Resim dönüştürüldü"); + break; + case FINGERPRINT_IMAGEMESS: + Serial.println("Resim belirsiz"); + return; + case FINGERPRINT_PACKETRECIEVEERR: + Serial.println("Bağlantı hatası"); + return; + case FINGERPRINT_FEATUREFAIL: + Serial.println("Parmak izinin nitelikleri belirgin değil"); + return; + case FINGERPRINT_INVALIDIMAGE: + Serial.println("Parmak izi niteliği anlaşılamadı"); + return; + default: + Serial.println("Hata"); + return; + } + + Serial.println("Yeniden girmeye hazır"); + delay(50); + data = 0; + while (data != FINGERPRINT_NOFINGER) { + data = finger.getImage(); + } + Serial.print("ID "); Serial.println(id); + data = -1; + Serial.println("aynı parmak tekrar girilmeli"); + while (data != FINGERPRINT_OK) { + data = finger.getImage(); + switch (data) { + case FINGERPRINT_OK: + Serial.println("resim alındı"); + break; + case FINGERPRINT_NOFINGER: + Serial.print("."); + break; + case FINGERPRINT_PACKETRECIEVEERR: + Serial.println("iletişim hatası"); + break; + case FINGERPRINT_IMAGEFAIL: + Serial.println("hata"); + break; + default: + Serial.println("hata"); + break; + } + } + + // OK success! + + data = finger.image2Tz(2); + switch (data) { + case FINGERPRINT_OK: + Serial.println("resim dönüştürüldü"); + break; + case FINGERPRINT_IMAGEMESS: + Serial.println("resim meşgul"); + return; + case FINGERPRINT_PACKETRECIEVEERR: + Serial.println("bağlantı hatası"); + return; + case FINGERPRINT_FEATUREFAIL: + Serial.println("parmak izi özellikleri eşleşmedi"); + return; + case FINGERPRINT_INVALIDIMAGE: + Serial.println("parmak izi özellikleri eşleşmedi"); + return; + default: + Serial.println("hata"); + return; + } + + Serial.print("Model Oluşturuldu #"); Serial.println(id); + + data = finger.createModel(); + if (data == FINGERPRINT_OK) { + Serial.println("Parmak izleri eşleşti!"); + } else if (data == FINGERPRINT_PACKETRECIEVEERR) { + Serial.println("Bağlantı hatası"); + return; + } else if (data == FINGERPRINT_ENROLLMISMATCH) { + Serial.println("Farklı parmak izleri"); + return; + } else { + Serial.println("hata"); + return; + } + + Serial.print("ID "); Serial.println(id); + + data = finger.storeModel(id); + + if (data == FINGERPRINT_OK) { + Serial.println("Hafızaya alındı"); + } else if (data == FINGERPRINT_PACKETRECIEVEERR) { + Serial.println("Communication error"); + return; + } else if (data == FINGERPRINT_BADLOCATION) { + Serial.println("Bu bölümde bir boşluk iz bulunamadı"); + return; + } else if (data == FINGERPRINT_FLASHERR) { + Serial.println("Belleğe yazma hatası"); + return; + } else { + Serial.println("Unknown error"); + return; + } + return; + +} + + +uint16_t fProcess::logIn() { + + + Adafruit_Fingerprint finger = Adafruit_Fingerprint(&Serial2); + finger.begin(57600); + + uint8_t data; + while (data != FINGERPRINT_OK) { + data = finger.getImage(); + switch (data) { + case FINGERPRINT_OK: + Serial.println("Parmak izi alındı "); + break; + case FINGERPRINT_NOFINGER: + Serial.print("."); + break; + case FINGERPRINT_PACKETRECIEVEERR: + Serial.println("Bağlantı hatası"); + break; + case FINGERPRINT_IMAGEFAIL: + Serial.println("Hatalı resim"); + break; + default: + Serial.println("Bir hata meydana geldi"); + break; + } + } + + data = finger.image2Tz(); + switch (data) { + case FINGERPRINT_OK: + Serial.println("Resim dönüştürüldü"); + break; + case FINGERPRINT_IMAGEMESS: + Serial.println("resim bozuk"); + return FINGERPRINT_NOTFOUND; + case FINGERPRINT_PACKETRECIEVEERR: + Serial.println("Bağlantı hatası"); + return FINGERPRINT_NOTFOUND; + case FINGERPRINT_FEATUREFAIL: + Serial.println("Could not find fingerprint features"); + return FINGERPRINT_NOTFOUND; + case FINGERPRINT_INVALIDIMAGE: + Serial.println("Could not find fingerprint features"); + return FINGERPRINT_NOTFOUND; + default: + Serial.println("Unknown error"); + return FINGERPRINT_NOTFOUND; + } + + data = finger.fingerSearch(); + if (data == FINGERPRINT_OK) { + Serial.println("Parmak izi eşleşti"); + } else if (data == FINGERPRINT_PACKETRECIEVEERR) { + Serial.println("Bağlantı hatası"); + return FINGERPRINT_NOTFOUND; + } else if (data == FINGERPRINT_NOTFOUND) { + Serial.println("Did not find a match"); + return FINGERPRINT_NOTFOUND; + } else { + Serial.println("Unknown error"); + return FINGERPRINT_NOTFOUND; + } + + Serial.print("Found ID #"); Serial.print(finger.fingerID); + Serial.print(" with confidence of "); Serial.println(finger.confidence); + + return finger.fingerID; + +} + +void fProcess::showUserList() { + +} \ No newline at end of file diff --git a/lib/fProcess/fProcess.h b/lib/fProcess/fProcess.h new file mode 100644 index 0000000..7a17107 --- /dev/null +++ b/lib/fProcess/fProcess.h @@ -0,0 +1,22 @@ +#ifndef FPROCESS_H +#define FPROCESS_H + +#include + +class fProcess{ + + + public: + + fProcess(); + void Initialize(); + void enRoll(uint16_t id); + uint16_t logIn(); + void showUserList(); + void delDB(); + private: + String name; + +}; + +#endif \ No newline at end of file diff --git a/lib/fServer/fServer.cpp b/lib/fServer/fServer.cpp new file mode 100644 index 0000000..33895da --- /dev/null +++ b/lib/fServer/fServer.cpp @@ -0,0 +1,80 @@ +#include "fServer.h" +#include "WebServer.h" +#include "ArduinoJson.h" +#include "Adafruit_Fingerprint.h" +#include "fProcess.h" + +fServer::fServer(int port) : server(port) { + + sprintf(info, "fserver established %s", "okey"); +} + + +void fServer::func() { + + if (server.hasArg("plain")) { + + String data = server.arg("plain"); + StaticJsonDocument<1024> document; + DeserializationError d_err = deserializeJson(document, data); + + if (d_err) sprintf(info, "err occured during deserialization %s\n", d_err.c_str()); + + String message = document["message"].as(); + String message_code = document["function_code"].as(); + this->last_id = document["last_id"].as(); + + this->selProcess(message_code); + } + + return; +} + +void fServer::sendReg() { + + fProcess fp; + uint16_t temp_id = this->last_id + 1; + fp.enRoll(temp_id); + + char RET[20]; + sprintf(RET, "last_id: %u", temp_id); + server.send(200, "text/plain", RET); + +} + +void fServer::sendLog() { + + fProcess fp; + char RET[20]; + uint8_t id = fp.logIn(); + + if (id != FINGERPRINT_NOTFOUND) { + + sprintf(RET, "current id: %u", id); + server.send(200, "text/plain", RET); + + } else { + + sprintf(RET, "current id: %d", -1); + server.send(200, "text/plain", RET); + } + + return; +} + +void fServer::selProcess(String message_code) { + + if (message_code == "1") sendLog(); + else if (message_code == "2") sendReg(); + +} + +void fServer::Initialize(String subdomain, http_method method) { + + server.on(subdomain, method, [this]() {this->func();}); + server.begin(); +} + +void fServer::listen() { + server.handleClient(); +} \ No newline at end of file diff --git a/lib/fServer/fServer.h b/lib/fServer/fServer.h new file mode 100644 index 0000000..9124112 --- /dev/null +++ b/lib/fServer/fServer.h @@ -0,0 +1,27 @@ +#ifndef FSERVER_H +#define FSERVER_H + +#include + +class fServer { + + + public: + fServer(int port); + void Initialize(String subdomain, http_method method); + void func(); + void listen(); + void selProcess(String message_code); + void sendReg(); + void sendLog(); + + + private: + WebServer server; + char info[1024]; + uint16_t last_id; + +}; + + +#endif \ No newline at end of file diff --git a/lib/wifiConnect/wifiConnect.cpp b/lib/wifiConnect/wifiConnect.cpp new file mode 100644 index 0000000..46d54fc --- /dev/null +++ b/lib/wifiConnect/wifiConnect.cpp @@ -0,0 +1,74 @@ +#include "wifiConnect.h" +#include +#include +#include +#include + +WifiConnect::WifiConnect(String SSID, String PASSWD) { + + this->SSID = SSID; + this->PASSWD = PASSWD; +} + +void WifiConnect::Initialize() { + + /* + IPAddress local_IP(192, 168, 1, 146); + IPAddress gateway (192, 168, 1, 1); + IPAddress subnet(255, 255, 255, 0); + IPAddress primaryDNS(192,168, 1, 1); + + connection_state = false; + if (!WiFi.config(local_IP, gateway, subnet, primaryDNS)) Serial.println("config hata"); + */ + connection_state = false; + WiFi.begin(SSID, PASSWD); + Serial.print("connection try to be in"); + + unsigned int get_current_time = millis(); + + while ( WiFi.status() != WL_CONNECTED && (millis() - get_current_time) < timeout) { + + delay(30); + Serial.print("."); + } + + while ( WiFi.status() != WL_CONNECTED) { + + delay(30); + Serial.print("."); + } + + + + + + connection_state = true; + IP = WiFi.localIP().toString(); + + Serial.print("connection okey"); + +} + +String WifiConnect::get_IP() { + + return WiFi.localIP().toString(); +} + +void WifiConnect::get_info() { + + Serial.printf("Ip adress : %s, SSID : %s \n", IP, SSID); +} + +void WifiConnect::set_timeout(unsigned int timeout) { + + this->timeout = timeout; +} + + +String WifiConnect::getIP() { + + return WiFi.softAPIP().toString(); +} + + diff --git a/lib/wifiConnect/wifiConnect.h b/lib/wifiConnect/wifiConnect.h new file mode 100644 index 0000000..974b66a --- /dev/null +++ b/lib/wifiConnect/wifiConnect.h @@ -0,0 +1,32 @@ +#pragma once +#ifndef WIFICONNECT_H +#define WIFICONNECT_H + +#include +#include +#include +#include + +class WifiConnect { + + + public: + WifiConnect(String SSID, String PASSWD); + void Initialize(); + String get_IP(); + void get_info(); + void set_timeout(unsigned int timeout); + String getIP(); + + + private: + String SSID; + String PASSWD; + String IP; + unsigned int timeout = 20000; + bool connection_state; + + +}; + +#endif \ No newline at end of file diff --git a/platformio.ini b/platformio.ini new file mode 100644 index 0000000..c296eb1 --- /dev/null +++ b/platformio.ini @@ -0,0 +1,19 @@ +; PlatformIO Project Configuration File +; +; Build options: build flags, source filter +; Upload options: custom upload port, speed and extra flags +; Library options: dependencies, extra library storages +; Advanced options: extra scripting +; +; Please visit documentation for the other options and examples +; https://docs.platformio.org/page/projectconf.html + +[env:esp32doit-devkit-v1] +platform = espressif32 +board = esp32doit-devkit-v1 +framework = arduino +lib_deps = + adafruit/Adafruit GFX Library@^1.11.9 + adafruit/Adafruit Fingerprint Sensor Library@^2.1.3 + bblanchon/ArduinoJson@^7.0.4 + arduino-libraries/ArduinoHttpClient@^0.6.0 diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..b14fba0 --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,35 @@ +#include + +#include +#include +#include +#include + +#include +#include +#include +#include +#include + + +const String SSID = "Kilicarslan"; +const String PASSWD = "14531453"; + + +WifiConnect connect(SSID, PASSWD); +fServer server(80); + +void setup() { + + Serial.begin(9600); + connect.Initialize(); + Serial.println(connect.get_IP()); + Serial.println(connect.getIP()); + server.Initialize("/post", HTTP_POST); + delay(20); + +} + +void loop() { + server.listen(); +} diff --git a/test/README b/test/README new file mode 100644 index 0000000..9b1e87b --- /dev/null +++ b/test/README @@ -0,0 +1,11 @@ + +This directory is intended for PlatformIO Test Runner and project tests. + +Unit Testing is a software testing method by which individual units of +source code, sets of one or more MCU program modules together with associated +control data, usage procedures, and operating procedures, are tested to +determine whether they are fit for use. Unit testing finds problems early +in the development cycle. + +More information about PlatformIO Unit Testing: +- https://docs.platformio.org/en/latest/advanced/unit-testing/index.html