ardunio rewrite
Mon Jan 29 2024 05:08:44 GMT+0000 (Coordinated Universal Time)
Saved by @praveenmacha777
#include <Adafruit_Fingerprint.h> #include <WiFi.h> #include <HTTPClient.h> // Replace with your fingerprint sensor's serial port SoftwareSerial mySerial(3, 1); // Create an instance of the Adafruit Fingerprint library Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial); // Enter the ID of the fingerprint you want to enroll int fingerID = 1; // Enter the URL of the online web system const char* serverName = "https://example.com/verify"; // Enter the ID of the voter int voterID = 1; // Enter the vote ID int voteID = 1; // Enter your WiFi credentials const char* ssid = "your_SSID"; const char* password = "your_PASSWORD"; void setup() { // Start the serial communication Serial.begin(9600); // Set the data rate for the fingerprint sensor serial port finger.begin(57600); // Check if the fingerprint sensor is found if (finger.verifyPassword()) { Serial.println("Found fingerprint sensor!"); } else { Serial.println("Did not find fingerprint sensor :("); while (1) { delay(1); } } // Enroll a new fingerprint enrollFingerprint(fingerID); // Connect to WiFi WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { delay(1000); Serial.println("Connecting to WiFi..."); } Serial.println("Connected to WiFi"); // Find a fingerprint match if (findFingerprintMatch()) { // Send the fingerprint template to the online web system for verification if (verifyFingerprint()) { // Record the vote securely recordVote(); // Send a confirmation to the online web system sendConfirmation(); } else { // Display an error message Serial.println("Verification failed."); } } } void loop() { // Put your code here } void enrollFingerprint(int id) { // Wait for the user to place their finger on the sensor Serial.println("Please place your finger on the sensor..."); finger.getImage(); delay(100); // Convert the image to a template Serial.println("Converting image..."); finger.image2tz(1); delay(100); // Save the template to the specified ID Serial.println("Saving template..."); finger.storeModel(id); delay(100); // Print a success message Serial.println("Template saved!"); } bool findFingerprintMatch() { // Wait for the user to place their finger on the sensor Serial.println("Please place your finger on the sensor..."); finger.getImage(); delay(100); // Convert the image to a template Serial.println("Converting image..."); finger.image2tz(1); delay(100); // Search for a match Serial.println("Searching for a match..."); finger.searchModels(); delay(100); // Print the match result if (finger.fingerID == fingerID) { Serial.println("Match found!"); return true; } else { Serial.println("No match found."); return false; } } bool verifyFingerprint() { // Send the fingerprint template to the online web system for verification if (WiFi.status() == WL_CONNECTED) { HTTPClient http; // Prepare the HTTP request http.begin(serverName); http.addHeader("Content-Type", "application/json"); // Convert the fingerprint template to a JSON string String json = "{\"fingerprint\":"; finger.getModel(json); json += "}"; // Send the HTTP request int httpResponseCode = http.POST(json); // Check the HTTP response code if (httpResponseCode == 200) { // Parse the verification result from the response String response = http.getString(); if (response == "true") { Serial.println("Verification successful."); return true; } else { Serial.println("Verification failed."); return false; } } else { Serial.print("Error on sending POST: "); Serial.println(httpResponseCode); return false; } http.end(); } else { Serial.println("WiFi not connected."); return false; } } void recordVote() { // Record the vote securely // You can use a secure database or a blockchain to record the vote Serial.println("Vote recorded."); } void sendConfirmation() { // Send a confirmation to the online web system
re write 1and2
Comments