-
Notifications
You must be signed in to change notification settings - Fork 0
/
fingerprint.ino
177 lines (148 loc) · 3.77 KB
/
fingerprint.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#include <Adafruit_Fingerprint.h>
#include <LiquidCrystal_I2C.h>
#include <ESP8266WiFi.h>
LiquidCrystal_I2C lcd(0x3F, 20, 4);
SoftwareSerial mySerial(D7, D8);
Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);
const char* ssid = "INSEA-WLAN"; //replace with your own SSID
const char* password = ""; //replace with your own password
const char* host = "api.pushingbox.com";
String member = "";
int flag = 0;
void setup(){
lcd.begin();
lcd.backlight();
lcd.setCursor(4, 0);
lcd.print("WELCOME");
delay(2000);
lcd.clear();
Serial.begin(57600);
delay(10);
Serial.println();
Serial.println();
lcd.setCursor(0, 0);
Serial.write("Connecting to WiFi... ");
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
lcd.setCursor(0, 0);
lcd.print("WiFi connected ");
lcd.setCursor(0, 1);
lcd.print("IP:");
lcd.setCursor(4, 1);
lcd.print(WiFi.localIP());
delay(1500);
while (!Serial);
delay(100);
Serial.write("Waiting for Fingerprint Sensor");
lcd.setCursor(0, 0);
lcd.print(" Waiting for ");
lcd.setCursor(0, 1);
lcd.print(" Sensor ");
delay(1500);
finger.begin(57600);
if (finger.verifyPassword())
{
Serial.println("Found Successfully");
lcd.setCursor(0, 0);
lcd.print("Sensor found! ");
lcd.setCursor(0, 1);
lcd.print(" ");
delay(1500);
} else
{
Serial.println("Fingerprint sensor not found!!!");
lcd.setCursor(0, 0);
lcd.print("Sensor Not found! ");
lcd.setCursor(0, 1);
lcd.print(" ");
while (1)
{
delay(1);
}
}
}
int getFingerprintID()
{
uint8_t p = finger.getImage();
if (p != FINGERPRINT_OK) return -1;
p = finger.image2Tz();
if (p != FINGERPRINT_OK) return -1;
p = finger.fingerFastSearch();
if (p != FINGERPRINT_OK) return -1;
return finger.fingerID;
}
void loop()
{
int fingerprintID = getFingerprintID();
delay(50);
if (fingerprintID == 1)
{
Serial.println("Welcome Boutaina");
lcd.setCursor(0, 0);
lcd.print("Welcome Boutaina ");
lcd.setCursor(0, 1);
lcd.print(" ");
connecthost("Boutaina");
flag = 0;
}else
{
Serial.println("Waiting for valid finger!!!");
lcd.setCursor(0, 0);
lcd.print(" Place a Valid ");
lcd.setCursor(0, 1);
lcd.print(" Finger ");
}
}
void connecthost(String data)
{
if (flag == 0)
{
member = data;
flag = 1;
Serial.print("connecting to ");
Serial.println(host);
WiFiClient client;
const int httpPort = 80;
if (!client.connect(host, httpPort))
{
Serial.println("connection failed");
return;
}
// We now create a URL for the request
String url = "/pushingbox?";
url += "devid=";
url += "v9DEF04C912228FC";
url += "&Name=" + String(member);
Serial.print("Requesting URL: ");
Serial.println(url);
client.print(String("GET ") + url + " HTTP/1.1\r\n" +
"Host: " + host + "\r\n" +
"Connection: close\r\n\r\n");
unsigned long timeout = millis();
while (client.available() == 0) {
if (millis() - timeout > 5000) {
Serial.println(">>> Client Timeout !");
client.stop();
return;
}
}
while (client.available()) {
String line = client.readStringUntil('\r');
Serial.print(line);
Serial.print("Data Sent!");
}
Serial.println();
Serial.println("closing connection");
}
}