Hi, Hoping someone can guide me on what to change. I want the finger print code to only run after the motion is triggered. I have it working, sort of. The issue if it is an issue seems when there is no motion, I think it may be connecting and disconnecting from my network over and over and over again. Any advice?
thanks
#include <Adafruit_Fingerprint.h>
#include <ESP8266WiFi.h>
#include <LiquidCrystal_I2C.h>
#include <PubSubClient.h>
//LiquidCrystal_I2C lcd(0x3F, 16, 2);
#include "CTBot.h"
SoftwareSerial mySerial(D3, D4);
Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);
const char* ssid = "xxx"; //replace with your own SSID
const char* password = "xxxx"; //replace with your own password
//const char* host = "api.pushingbox.com";
const char* mqtt_server = "xxx";
WiFiClient espClient;
PubSubClient client(espClient);
String member = "";
int flag = 0;
int sensor = 13; // Motion Sensor Digital pin D7
void setup()
{
Serial.begin(115200);
pinMode(sensor, INPUT);
//long state = digitalRead(sensor);
// while (state == LOW);
delay(10);
Serial.println();
client.setServer(mqtt_server, 1883);
Serial.println();
Serial.print("Connecting to WiFi... ");
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
// set the telegram bot token
myBot.setTelegramToken(token);
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
delay(1500);
while (!Serial);
delay(100);
Serial.println("\n\n Waiting for Fingerprint Sensor");
delay(1500);
finger.begin(57600);
if (finger.verifyPassword())
{
Serial.println("Found Successfully");
delay(1500);
} else
{
Serial.println("Fingerprint sensor not found!!!");
while (1)
{
delay(1);
}
}
}
void loop()
{
Serial.println("Waiting");
long state = digitalRead(sensor);
while (state == LOW);
int fingerprintID = getFingerprintID();
delay(50);
if (fingerprintID == 1)
{
Serial.println("Welcome Bob");
flag = 0;
}
else if (fingerprintID == 2)
{
Serial.println("Welcome Jack");
flag = 0;
}
else if (fingerprintID == 3)
{
Serial.println("Welcome Tara");
flag = 0;
}
else
{
Serial.println("Waiting for valid finger!!!");
}
}
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;
}