Differences

This shows you the differences between two versions of the page.

Link to this comparison view

iothings:proiecte:2025sric:securitysystem [2025/05/29 00:45]
roxana.popa2703 [General description]
iothings:proiecte:2025sric:securitysystem [2025/05/29 01:06] (current)
roxana.popa2703
Line 14: Line 14:
  
 For the implementation of this project, the following hardware components were used: For the implementation of this project, the following hardware components were used:
-  * ESP32+  * ESP-WROOM-32 
 +  * 2 x LED (one red, one green) 
 +  * 1 x Passive buzzer 
 +  * 1 x Breadboard 
 +  * 1 x Keyboard module 
 +  * Wires 
 + 
 +{{:​iothings:​proiecte:​2025sric:​hw.png|}} 
 + 
 +==== Software description ==== 
 + 
 +The following libraries were used: 
 +---- 
 + 
 +  #​include ​ <​WiFi.h> ​              // to connect ​ESP32 via WiFi 
 +  #include "​time.h" ​               // for logs timestamps 
 +  #include <​Firebase_ESP_Client.h>​ // to read/write data to Firebase 
 +   
 +The Wi-Fi setup and connection:​ 
 +      WiFi.mode(WIFI_STA);​ 
 +      WiFi.begin(WIFI_SSID,​ WIFI_PASSWORD);​ 
 +      uint8_t status = WiFi.waitForConnectResult();​ 
 +      if (status == WL_CONNECTED) {        
 +        Serial.println();​ 
 +        Serial.println("​connected (WL_CONNECTED)"​);​ 
 +      }  
 + 
 +The NTP server sync: 
 +     ​configTime(gmtOffset_sec,​ daylightOffset_sec,​ ntpServer);​ 
 +     ​Serial.print("​Waiting for NTP time sync..."​);​ 
 +     while (time(nullptr) < 100000) { 
 +       ​delay(500);​ 
 +       ​Serial.print("​."​);​ 
 +     } 
 +    Serial.println("​\nTime synced!"​);​ 
 +     
 +Access logging: 
 +     ​FirebaseJson log; 
 +     ​log.set("​password",​ password);​ 
 +     ​log.set("​status",​ status); 
 +     ​time_t now; 
 +     ​time(&​now);​ 
 +     ​String timestamp = String(now);​ 
 +     ​String path = "​users/​logs/"​ + timestamp;​ 
 +     if (Firebase.RTDB.setJSON(&​data,​ path, &log)) { 
 +        Serial.println("​Log sent at " + timestamp);​ 
 +     } else { 
 +     ​Serial.print("​Failed to send log: "); 
 +     ​Serial.println(data.errorReason());​ 
 +     } 
 +      
 +The **setup** function: 
 + 
 +    Serial.begin(115200);​ 
 +    Serial.setTimeout(1000);​ 
 +    pinMode(RED_LED,​ OUTPUT); 
 +    pinMode(GREEN_LED,​ OUTPUT); 
 +    pinMode(BUZZER,​ OUTPUT); 
 +    connectToWiFi();​ 
 +    initTime();​ 
 +    // Configure Firebase 
 +    config.api_key = API_KEY; 
 +    config.database_url = DATABASE_URL;​ 
 +    // Sign in anonymously (or use email/​password) 
 +    auth.user.email = USER_EMAIL;​ 
 +    auth.user.password = USER_PASSWORD;​ 
 +    // Initialize Firebase 
 +    Firebase.begin(&​config,​ &​auth);​ 
 +    Firebase.reconnectWiFi(true);​ 
 +    // Delay to ensure connection setup 
 +    delay(2000);​ 
 +     
 +The **loop** function: 
 +    if (Serial.available() > 0) { 
 +    String password = Serial.readString();​ 
 +    password.trim();​ 
 +    Serial.println(password);​ 
 +    if (!Firebase.RTDB.getJSON(&​data,​ listenerPath)) { 
 +      Serial.printf("​Stream begin error, %s\n", data.errorReason().c_str());​ 
 +    } 
 +    json = data.jsonObject();​ 
 +    String jsonStr; 
 +    json.toString(jsonStr,​ true); ​ // '​true'​ = pretty print (multi-line,​ indented) 
 +    Serial.println(jsonStr);​ 
 +    FirebaseJsonData status; 
 +    json.get(status,​ password);​ 
 +    if (!status.success) { 
 +      Serial.println("​Key '​status'​ not found!"​);​ 
 +    } else { 
 +      logAccess(password,​ status.stringValue);​ 
 +      if(status.stringValue == "​allowed"​){ 
 +        digitalWrite(GREEN_LED,​ HIGH); 
 +        tone(BUZZER,​ 1000); 
 +        delay(200);​ 
 +        digitalWrite(GREEN_LED,​ LOW); 
 +        noTone(BUZZER);​ 
 +      } 
 +      else{ 
 +        digitalWrite(RED_LED,​ HIGH); 
 +        tone(BUZZER,​ 400); 
 +        delay(200);​ 
 +        digitalWrite(RED_LED,​ LOW); 
 +        noTone(BUZZER);​ 
 +      } 
 +    } 
 +  }  
 + 
 + 
iothings/proiecte/2025sric/securitysystem.1748468739.txt.gz · Last modified: 2025/05/29 00:45 by roxana.popa2703
CC Attribution-Share Alike 3.0 Unported
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0