This shows you the differences between two versions of the page.
iothings:proiecte:2025sric:security-system-to_detect-movement-and-capture-image [2025/05/29 10:34] felicia.saghin [Firebase] |
iothings:proiecte:2025sric:security-system-to_detect-movement-and-capture-image [2025/05/29 11:19] (current) felicia.saghin [Introduction] |
||
---|---|---|---|
Line 7: | Line 7: | ||
====== Introduction ====== | ====== Introduction ====== | ||
- | In today’s connected world, real-time security monitoring at home or in small offices has become both practical and affordable. This project delivers a lightweight IoT door-security solution by combining an ESP32-CAM module with a Hall-effect sensor. Whenever the door opens, the sensor immediately signals the ESP32-CAM to capture a high-resolution image. That image is then uploaded to Firebase Storage, and its publicly accessible URL is written to Firebase Realtime Database. Simultaneously, Twilio’s API is invoked to send an SMS to your smartphone. Finally, a web gallery hosted on Firebase displays the latest snapshot instantly, giving you secure and remote visibility of every entry event. | + | In today’s connected world, real-time security monitoring at home or in small offices is both practical and affordable. This project delivers a lightweight IoT door-security solution by combining an ESP32-CAM module with a Hall-effect sensor. Whenever the door opens, the sensor immediately signals the ESP32-CAM to capture a high-resolution JPEG, which is then Base64-encoded and stored directly in Firebase Realtime Database. Simultaneously, Twilio’s API sends an SMS alert with a link to your live web gallery. A responsive dashboard hosted on Firebase Hosting listens for new entries in the database and displays each snapshot instantly, giving you secure, remote visibility of every entry event. |
====== Context ====== | ====== Context ====== | ||
__**Diagram**__ | __**Diagram**__ | ||
Line 219: | Line 219: | ||
* **images/** | * **images/** | ||
- | A collection of timestamped entries, each holding the Base64-encoded JPEG and metadata (size, source). | + | - A collection of timestamped entries, each holding the Base64-encoded JPEG and metadata (size, source). |
* **latestImage** | * **latestImage** | ||
- | Stores the key of the most recent `images/{timestamp}` entry for quick access (optional). | + | - Stores the key of the most recent images/{timestamp} entry for quick access (optional). |
* **notificationsEnabled** | * **notificationsEnabled** | ||
- | A Boolean flag to enable or disable SMS alerts on the fly. | + | - A Boolean flag to enable or disable SMS alerts on the fly. |
All communication flows through the Realtime Database: | All communication flows through the Realtime Database: | ||
- | - **ESP32-CAM** writes a new child under `/images` on every door-open event. | + | * **ESP32-CAM** writes a new child under /images on every door-open event. |
- | - **Web dashboard** listens for `child_added` and updates the UI in real time. | + | * **Web dashboard** listens for child_added and updates the UI in real time. |
- | - **Toggles** to `/notificationsEnabled` can be flipped by the user to mute alerts without redeploy. | + | * **Toggles** to /notificationsEnabled can be flipped by the user to mute alerts without redeploy. |
+ | |||
+ | {{ :iothings:proiecte:2025sric:firebase2_feli.jpg?600 }} | ||
- | {{ :iothings:proiecte:2025sric:firebase_realtime_db.png?600 |Realtime Database Structure}} | ||
====== Challenges ====== | ====== Challenges ====== | ||
+ | |||
+ | One of the first hurdles I encountered was the ESP32-CAM’s limited onboard RAM. Capturing high-resolution JPEGs and then encoding them into Base64 demanded more memory than the 520 KB of SRAM could comfortably provide. To overcome this, I enabled the module’s external PSRAM and carefully managed my buffer allocations so that large image data would reside in PSRAM rather than exhausting the internal memory. | ||
+ | |||
+ | Another issue came up when trying to upload these large images all at once: memory would sometimes fragment, or the HTTP requests would time out, leading to failed uploads. I solved this by breaking the Base64 encoding into smaller, manageable chunks, freeing each buffer immediately after use, and adding a simple retry mechanism for any failed network calls. This approach dramatically reduced memory spikes and improved upload reliability. | ||
+ | |||
+ | Finally, my Hall-effect sensor occasionally produced multiple false “door open” triggers due to electrical noise or rapid swings near the magnet. Instead of acting on every glitch, I implemented a 500 ms software debounce in my sensor-reading routine. That way, once the sensor changes state, I wait half a second to ensure it’s stable before capturing a photo—guaranteeing exactly one image per genuine door-open event. | ||
====== References ====== | ====== References ====== | ||
+ | |||
+ | https://docs.espressif.com/projects/esp-idf/en/latest/esp32/hw-reference/esp32/get-started-wrover-kit.html | ||
+ | |||
+ | https://github.com/mobizt/Firebase-ESP-Client | ||
+ | |||
+ | https://github.com/ademuri/twilio-esp32-client | ||
+ | |||
+ | https://firebase.google.com/docs/database | ||
+ | |||
+ | https://docs.platformio.org/en/latest/ | ||
+ | |||
+ | https://github.com/espressif/esp32-camera | ||
+ | |||
+ | https://www.twilio.com/docs/sms/api | ||
+ | |||
+ | https://firebase.google.com/docs/web/setup | ||
+ | |||
+ | https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/external-ram.html | ||
+ | |||
+ | https://randomnerdtutorials.com/esp32-cam-pinout-gpios/ | ||