closed-beta

This commit is contained in:
Bedir Tuğra Karaabalı 2024-05-23 09:11:29 +03:00
commit d1bea7b04c
13 changed files with 640 additions and 0 deletions

5
.gitignore vendored Normal file
View File

@ -0,0 +1,5 @@
.pio
.vscode/.browse.c_cpp.db*
.vscode/c_cpp_properties.json
.vscode/launch.json
.vscode/ipch

10
.vscode/extensions.json vendored Normal file
View File

@ -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"
]
}

39
include/README Normal file
View File

@ -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

46
lib/README Normal file
View File

@ -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 <Foo.h>
#include <Bar.h>
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

240
lib/fProcess/fProcess.cpp Normal file
View File

@ -0,0 +1,240 @@
#include "fProcess.h"
#include <Adafruit_Fingerprint.h>
#include <Arduino.h>
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() {
}

22
lib/fProcess/fProcess.h Normal file
View File

@ -0,0 +1,22 @@
#ifndef FPROCESS_H
#define FPROCESS_H
#include <Arduino.h>
class fProcess{
public:
fProcess();
void Initialize();
void enRoll(uint16_t id);
uint16_t logIn();
void showUserList();
void delDB();
private:
String name;
};
#endif

80
lib/fServer/fServer.cpp Normal file
View File

@ -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>();
String message_code = document["function_code"].as<String>();
this->last_id = document["last_id"].as<uint16_t>();
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();
}

27
lib/fServer/fServer.h Normal file
View File

@ -0,0 +1,27 @@
#ifndef FSERVER_H
#define FSERVER_H
#include <WebServer.h>
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

View File

@ -0,0 +1,74 @@
#include "wifiConnect.h"
#include <HTTPClient.h>
#include <WiFi.h>
#include <WebServer.h>
#include <ArduinoJson.h>
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();
}

View File

@ -0,0 +1,32 @@
#pragma once
#ifndef WIFICONNECT_H
#define WIFICONNECT_H
#include <iostream>
#include <string>
#include <WiFi.h>
#include <HTTPClient.h>
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

19
platformio.ini Normal file
View File

@ -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

35
src/main.cpp Normal file
View File

@ -0,0 +1,35 @@
#include <Arduino.h>
#include <wifiConnect.h>
#include <HTTPClient.h>
#include <fProcess.h>
#include <fServer.h>
#include <WebServer.h>
#include <ArduinoJson.h>
#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Adafruit_Fingerprint.h>
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();
}

11
test/README Normal file
View File

@ -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