The program is not going back it is just stuck at some point

hey this is my code , i know its kinda long but i'll explain it briefly , the code is a security system with a fingerprint sensor, first of all get the finger id if its valid then show a menu and then the user have to choose from it and when the select button is cliqued and after the digitalwrite and the firebase request 'IFTTTRequete' the program suppose to re-demand the finger again, and start all over again.
didnt know what to do; knowing that i'am forbidden to use the software reset.

#include <Adafruit_Fingerprint.h>
#include <LiquidCrystal_I2C.h>
#include <HardwareSerial.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 = "Orange-BFAA";
const char* mdp = "topnetbnh";

LiquidCrystal_I2C lcd(0x27, 20, 4);
Adafruit_Fingerprint lecteurEmpreinte = Adafruit_Fingerprint(&Serial2);

int BouttonBas = 4;
int BouttonHaut = 0;
int BouttonSelect = 2;
int buzzer = 15;
int capteur = 18;
int serrure = 27;
int menu = 1;
int i = 0;

void setup()
{
  configurerBroche();
  afficherMessage();
  initialiserConnexionWifi();
  detecterLecteurEmpreinte();
}
void configurerBroche() {
  pinMode(BouttonHaut, INPUT_PULLUP);
  pinMode(BouttonBas, INPUT_PULLUP);
  pinMode(BouttonSelect, INPUT_PULLUP);
  pinMode(capteur, INPUT_PULLUP);
  pinMode(15, OUTPUT);
  pinMode(33, OUTPUT);
  pinMode(32, OUTPUT);
  pinMode(35, OUTPUT);
  pinMode(27, OUTPUT);

}
void afficherMessage() {
  lcd.init();
  lcd.backlight();
  lcd.print("SFE");
  lcd.setCursor(0, 2 );
  lcd.print(" BENHAMAD AHMED ");
  lcd.setCursor(0, 3);
  lcd.print(" AYEB MONDHER ");
  delay(2000);
  lcd.clear();

}
void initialiserConnexionWifi() {

  lcd.print("tentative de connexion WiFi: ");
  WiFi.begin(utilisateur, mdp);

  int timeout = 10 * 4; // 10 seconds
  while (WiFi.status() != WL_CONNECTED  && (timeout-- > 0)) {
    delay(250);
    lcd.print(".");
  }

  if (WiFi.status() != WL_CONNECTED) {
    lcd.clear();
    lcd.print("erreur de connexion");
  }
  else {
    lcd.clear();
    lcd.print("WiFi connecte a: ");
    lcd.setCursor(0, 1);
    lcd.print(utilisateur);
    delay(3000);
    lcd.clear();
  }

}
void detecterLecteurEmpreinte() {

  delay(5);
  lecteurEmpreinte.begin(57600);
  delay(5);
  if (lecteurEmpreinte.verifyPassword()) {
    lcd.setCursor(0, 1);
    lcd.print("lecteur d'empreinte detecté");

  } else {
    lcd.setCursor(0, 1);
    lcd.println("aucun lecteur d'empreinte detecte");
  }
  delay(1000);
  lcd.clear();
}



void loop() {
  alarme();
  lcd.clear();
  lcd.print("placer votre doigt SVP");
  verifierEmpreinte();

  while (NOM == "ahmed benhamad" || NOM == "mondher ayeb") {
    afficherMenu();
  }
  NOM = "";
}




void verifierEmpreinte() {
  getFingerprintID();
  if (lecteurEmpreinte.fingerID == 1) {

    NOM = "ahmed benhamad";
  }
  delay(50);
  if (lecteurEmpreinte.fingerID == 3 ) {
    NOM = "mondher ayeb";
  }

  lecteurEmpreinte.fingerID = 0;
}
void afficherMenu() {
  if (!digitalRead(BouttonBas)) {
    menu++;
    MAJMenu();
    delay(100);
    while (!digitalRead(BouttonBas));
  }
  if (!digitalRead(BouttonHaut)) {
    menu--;
    MAJMenu();
    delay(100);
    while (!digitalRead(BouttonHaut));
  }
  if (digitalRead(BouttonSelect)) {
    executionAction();
    NOM="";
    delay(100);
    while (digitalRead(BouttonSelect));
  }
}
void alarme() {
  while (digitalRead(capteur) == 1) {
    delay(50);
    i++;
    if (i <= 100) {
      digitalWrite(buzzer, 0);
    }
    else {
      digitalWrite(buzzer, 1);
      lcd.init();
      lcd.backlight();
      lcd.print("Priere de fermer ");
      lcd.setCursor(0, 1);
      lcd.print("la porte");
    }
  }
  digitalWrite(buzzer, 0);
  i = 0;
}
void MAJMenu() {
  switch (menu) {
    case 0:
      menu = 1;
      break;
    case 1:
      lcd.clear();
      lcd.print(">Salle 1");
      lcd.setCursor(0, 1);
      lcd.print(" Salle 2");
      lcd.setCursor(0, 2);
      lcd.print(" Salle 3");
      lcd.setCursor(0, 3);
      lcd.print(" Annuler");
      break;
    case 2:
      lcd.clear();
      lcd.print(" Salle 1");
      lcd.setCursor(0, 1);
      lcd.print(">Salle 2");
      lcd.setCursor(0, 2);
      lcd.print(" Salle 3");
      lcd.setCursor(0, 3);
      lcd.print(" Annuler");
      break;
    case 3:
      lcd.clear();
      lcd.print(" Salle 1");
      lcd.setCursor(0, 1);
      lcd.print(" Salle 2");
      lcd.setCursor(0, 2);
      lcd.print(">Salle 3");
      lcd.setCursor(0, 3);
      lcd.print(" Annuler");
      break;
    case 4:
      lcd.clear();
      lcd.print(" Salle 1");
      lcd.setCursor(0, 1);
      lcd.print(" Salle 2");
      lcd.setCursor(0, 2);
      lcd.print(" Salle 3");
      lcd.setCursor(0, 3);
      lcd.print(">Annuler");
      break;
    case 5:
      menu = 4;
      break;
  }
}


uint8_t getFingerprintID() {
  uint8_t p = lecteurEmpreinte.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 = lecteurEmpreinte.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 = lecteurEmpreinte.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");
    lcd.setCursor(0, 1);
    lcd.print("correspondance");
    delay(1000);
    lcd.clear();
    lcd.print("Ressayer ");
    delay(1000);
    return p;
  } else {

    return p;
  }

  return lecteurEmpreinte.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");
  lcd.setCursor(0, 1);
  lcd.print("fermer la porte");
  digitalWrite(serrure, HIGH);
  delay(2000);
  digitalWrite(serrure, LOW);
  digitalWrite(25, HIGH);//diode led pointé au dessus la salle juste pour guider
  delay(1500);
  ACCES = "salle 1";
  IFTTTRequete();
  delay(3000);
  digitalWrite(25, LOW); // led s'eteind apres 3 seconds
  
}
void action2() {
  lcd.clear();
  lcd.print("n oublie pas de");
  lcd.setCursor(0, 1);
  lcd.print("fermer la porte");
  digitalWrite(serrure, HIGH);
  delay(2000);
  digitalWrite(serrure, LOW);
  digitalWrite(33, HIGH);//diode led pointé au dessus la salle juste pour guider
  delay(1500);
  ACCES = "Salle 2";
  IFTTTRequete();
  delay(3000);
  digitalWrite(33, LOW);// led s'eteind apres 3 seconds
}
void action3() {
  lcd.clear();
  lcd.print("n oublie pas de");
  lcd.setCursor(0, 1);
  lcd.print("fermer la porte");
  digitalWrite(serrure, HIGH);
  delay(2000);
  digitalWrite(serrure, LOW);
  digitalWrite(32, HIGH); //diode led pointé au dessus la salle juste pour guider
  ACCES = "Salle 3";
  IFTTTRequete();
  delay(3000);
  digitalWrite(32, LOW);// led s'eteind apres 3 seconds
}
void action4() {
  lcd.clear();
  lcd.print("Annulation...");
  delay(1500);
}
void  IFTTTRequete() {
  Serial.print("Connexion à ");
  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();
}

Add some print statements into your code so you can trace where it goes , see the values of particular variables and find the issue

Do you ever get to the last line in above code? It does not matter what p is, you always return from the function.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.