in void loop() i need bouttons(); work only if the fingerprint is found and true.
not that good in programming so i'll be really apperciated.
#include <Adafruit_Fingerprint.h>
#include <LiquidCrystal_I2C.h>
#include <HardwareSerial.h>
//#include <Wire.h>
#include <WiFi.h>
const char* NOM;
const char* ACCES;
String Event_Name = "historique des entrés";
String Key = "cmzj-mXCZk0corohNRlWAMndXnKjDLqJIjwlslpECJ7";
String resource = "/trigger/" + Event_Name + "/with/key/" + Key;
const char* serveur = "maker.ifttt.com";
const char* utilisateur = "Nokia de Mondher";
const char* mdp = "12345678";
LiquidCrystal_I2C lcd(0x27, 20, 4);
Adafruit_Fingerprint empreinte = Adafruit_Fingerprint(&Serial2);
int BouttonBas = 4;
int BouttonHaut = 0;
int BouttonSelect = 2;
int menu = 1;
void setup()
{
initialisation();
configurationBroche();
}
void loop() {
Empreinte();
Bouttons();
}
void initialisation() {
Serial.begin(9600);
Serial2.begin(9600);
lcd.init();
lcd.backlight();
lcd.print("SFE");
lcd.setCursor(0, 2 );
lcd.print(" BENHAMAD AHMED ");
lcd.setCursor(0, 3);
lcd.print(" AYEB MONDHER ");
while (!Serial); // For Yun/Leo/Micro/Zero/...
delay(100);
delay(2000);
lcd.clear();
lcd.print("placer votre doigt");
empreinte.begin(57600);
delay(5);
Serial.print("Connection a: ");
Serial.print(utilisateur);
WiFi.begin(utilisateur, mdp);
int timeout = 10 * 4; // 10 seconds
while (WiFi.status() != WL_CONNECTED && (timeout-- > 0)) {
delay(250);
Serial.print(".");
}
Serial.println("");
if (WiFi.status() != WL_CONNECTED) {
Serial.println("erreur de connexion");
}
Serial.print("WiFi connecte a: ");
Serial.print(millis());
Serial.print(",IP address : ");
Serial.println(WiFi.localIP());
}
void configurationBroche() {
pinMode(BouttonHaut, INPUT_PULLUP);
pinMode(BouttonBas, INPUT_PULLUP);
pinMode(BouttonSelect, INPUT_PULLUP);
pinMode(33, OUTPUT);
pinMode(32, OUTPUT);
pinMode(35, OUTPUT);
}
void Empreinte() {
getFingerprintID();
if (empreinte.fingerID == 1) {
NOM = "ahmed benhamad";
}
if (empreinte.confidence >= 60) {
Serial.println(NOM);
}
delay(50);
if (empreinte.fingerID == 88 ) {
NOM = "mondher ayeb";
if (empreinte.confidence >= 60) {
Serial.println(NOM);
}
}
empreinte.fingerID = 0;
}
void Bouttons() {
if (!digitalRead(BouttonBas)) {
menu++;
MAJMenu();
delay(100);
while (!digitalRead(BouttonBas));
}
if (!digitalRead(BouttonHaut)) {
menu--;
MAJMenu();
delay(100);
while (!digitalRead(BouttonHaut));
}
if (!digitalRead(BouttonSelect)) {
executionAction();
MAJMenu();
delay(100);
while (!digitalRead(BouttonSelect));
}
}
void MAJMenu() {
switch (menu) {
case 0:
menu = 1;
break;
case 1:
lcd.clear();
lcd.print(">Armoire 1");
lcd.setCursor(0, 1);
lcd.print(" Armoire 2");
lcd.setCursor(0, 2);
lcd.print(" Armoire 3");
lcd.setCursor(0, 3);
lcd.print(" Annuler");
break;
case 2:
lcd.clear();
lcd.print(" Armoire 1");
lcd.setCursor(0, 1);
lcd.print(">Armoire 2");
lcd.setCursor(0, 2);
lcd.print(" Armoire 3");
lcd.setCursor(0, 3);
lcd.print(" Annuler");
break;
case 3:
lcd.clear();
lcd.print(" Armoire 1");
lcd.setCursor(0, 1);
lcd.print(" Armoire 2");
lcd.setCursor(0, 2);
lcd.print(">Armoire 3");
lcd.setCursor(0, 3);
lcd.print(" Annuler");
break;
case 4:
lcd.clear();
lcd.print(" Armoire 1");
lcd.setCursor(0, 1);
lcd.print(" Armoire 2");
lcd.setCursor(0, 2);
lcd.print(" Armoire 3");
lcd.setCursor(0, 3);
lcd.print(">Annuler");
break;
case 5:
menu = 4;
break;
}
}
uint8_t getFingerprintID() {
uint8_t p = empreinte.getImage();
switch (p) {
case FINGERPRINT_OK:
break;
case FINGERPRINT_NOFINGER:
return p;
case FINGERPRINT_PACKETRECIEVEERR:;
return p;
case FINGERPRINT_IMAGEFAIL:
return p;
default:
return p;
}
p = empreinte.image2Tz();
switch (p) {
case FINGERPRINT_OK:
break;
case FINGERPRINT_IMAGEMESS:
return p;
case FINGERPRINT_PACKETRECIEVEERR:
return p;
case FINGERPRINT_FEATUREFAIL:
return p;
case FINGERPRINT_INVALIDIMAGE:
return p;
default:
return p;
}
p = empreinte.fingerSearch();
if (p == FINGERPRINT_OK) {
lcd.clear();
lcd.print("Empreinte validee");
delay(2000);
lcd.clear();
MAJMenu();
} else if (p == FINGERPRINT_PACKETRECIEVEERR) {
return p;
} else if (p == FINGERPRINT_NOTFOUND) {
lcd.clear();
lcd.print("aucune correspondance");
delay(3000);
lcd.clear();
lcd.print("Ressayer une autre fois");
return p;
} else {
return p;
}
return empreinte.fingerID;
}
void executionAction() {
switch (menu) {
case 1:
action1();
break;
case 2:
action2();
break;
case 3:
action3();
break;
case 4:
action4();
break;
}
}
void action1() {
lcd.clear();
lcd.print("N'oublie pas de fermer la porte à fin de finir votre travaille");
digitalWrite(33, HIGH);//diode led pointé au dessus l'armoire juste pour guider
delay(1500);
ACCES = "Armoire 1";
IFTTTRequete();
delay(3000);
digitalWrite(33, LOW); // led s'eteind apres 3 seconds
ESP.restart();
}
void action2() {
lcd.clear();
lcd.print("N'oublie pas de fermer la porte à fin de finir votre travaille");
digitalWrite(32, HIGH);//diode led pointé au dessus l'armoire juste pour guider
delay(1500);
ACCES = "Armoire 2";
IFTTTRequete();
delay(3000);
digitalWrite(32, LOW);// led s'eteind apres 3 seconds
ESP.restart();
}
void action3() {
lcd.clear();
lcd.print("N'oublie pas de fermer la porte à fin de finir votre travaille");
delay(1500);
digitalWrite(35, HIGH); //diode led pointé au dessus l'armoire juste pour guider
ACCES = "Armoire 3";
IFTTTRequete();
delay(3000);
digitalWrite(35, LOW);// led s'eteind apres 3 seconds
ESP.restart();
}
void action4() {
lcd.clear();
lcd.print("Annulation...");
delay(1500);
ESP.restart();
}
void IFTTTRequete() {
Serial.print("Connection à ");
Serial.print(serveur);
WiFiClient client;
int retries = 5;
while (!client.connect(serveur, 80) && (retries-- > 0)) {
Serial.print(".");
}
Serial.println();
if (!client.connected()) {
Serial.println("erreur de connexion...");
}
Serial.print("Request resource: ");
Serial.println(resource);
String jsonObject = String("{\"value1\":\"") + NOM + "\",\"value2\":\"" + ACCES
+ "\"}";
client.println(String("POST ") + resource + " HTTP/1.1");
client.println(String("Host: ") + serveur);
client.println("Connection: close\r\nContent-Type: application/json");
client.print("Content-Length: ");
client.println(jsonObject.length());
client.println();
client.println(jsonObject);
int timeout = 5 * 10; // 5 seconds
while (!client.available() && (timeout-- > 0)) {
delay(100);
}
client.stop();
}