Mobile Application Overview
Relevant source files
The following files were used as context for generating this wiki page:
The HomeSecurity project includes a companion Android mobile application that serves as the primary user interface for system monitoring and interaction. It is the client-tier component in the system's three-tier architecture, responsible for receiving real-time alerts, displaying live video feeds, and managing user authentication. The application provides a modern, reactive interface for users to stay informed about their home's security status from anywhere.
The app is designed to work in concert with the ESP32 edge device and the Firebase cloud backend. It receives push notifications orchestrated by Firebase Cloud Functions, which are triggered by HTTP requests from the ESP32 upon sensor activation. This architecture ensures timely and efficient communication of security events to the user.
Sources: HomeSecurity/README.md:16-21, 50-57, 303-306
Technology Stack and Architecture
The Android application is built using a modern technology stack focused on the Kotlin programming language and Google's recommended practices. It follows an MVVM (Model-View-ViewModel) architecture to ensure a clean separation of concerns between the UI, business logic, and data layers.
Sources: HomeSecurity/README.md:308-311
Core Technologies
| Technology | Purpose |
|---|---|
| Kotlin | Primary programming language for development. |
| Jetpack Compose | Declarative UI framework for building the user interface. |
| MVVM Architecture | Architectural pattern for separating UI logic from business logic. |
| Firebase Auth | Manages user authentication, supporting email/password and Google Sign-In. |
| Firebase Cloud Messaging | Receives real-time push notifications from the backend. |
| LibVLC | Handles the RTSP video stream rendering from the IP camera. |
Sources: HomeSecurity/README.md:308-317
Architectural Placement
The mobile application is the "Client Tier" in the overall system, interacting with cloud services and the local network IP camera.
This diagram illustrates the mobile app's position within the HomeSecurity ecosystem.
Key Features
The mobile application provides several key features to the end-user for monitoring and system interaction.
| Feature | Description |
|---|---|
| User Authentication | Secure login using Email/Password or Google Sign-In, managed by Firebase Auth. |
| Real-time Notifications | Receives push alerts via Firebase Cloud Messaging when sensors are triggered. |
| Live Video Streaming | Displays a live video feed from a TP-Link Tapo C200 camera using the RTSP protocol. |
| Dark/Light Theme | Allows users to toggle between dark and light UI modes for visual comfort. |
| Reactive UI | The interface, built with Jetpack Compose, automatically updates based on state changes. |
Sources: HomeSecurity/README.md:110-115, 319-325
User Interface Screens
The application is structured around three main screens:
- Login Screen: Provides authentication options for the user.
- Home Screen: The main dashboard, featuring the live video feed and system status indicators.
- Notification Display: Shows a history of alert details.
Sources: HomeSecurity/README.md:327-331
Notification System
A core function of the mobile app is to receive and display security alerts. The notification process is initiated by the ESP32 device and brokered by Firebase.
Notification Flow
The following sequence diagram shows the end-to-end flow from sensor detection on the ESP32 to a push notification arriving on the mobile app.
Notification Triggers and Payload
The ESP32 sends notifications based on a two-stage alert logic.
- Stage 1: Initial Alert: Triggered immediately when the PIR (motion) or Hall (door/window) sensor is activated. The app receives a "Warning" notification.
- Stage 2: Confirmation Alert: Triggered if the RCWL-0516 radar sensor detects continuous movement for over 2 seconds. The app receives a "Confirmation" notification.
The ESP32 makes an HTTP POST request to a Firebase Cloud Function. The FirebaseNotifier class encapsulates this logic.
Sources: HomeSecurity/README.md:261-280, HomeSecurity/src/motion_logic.cpp:44-62, 100-115
The sendNotification method constructs and sends the JSON payload.
// File: HomeSecurity/src/firebase_notifier.cpp:7-29
bool FirebaseNotifier::sendNotification(const String& title, const String& body, const String& token) {
// ... client setup ...
https.addHeader("Content-Type", "application/json");
String jsonPayload = "{\"title\":\"" + title + "\",\"body\":\"" + body + "\",\"token\":\"" + token + "\"}";
int httpCode = https.POST(jsonPayload);
// ... response handling ...
}
Sources: HomeSecurity/src/firebase_notifier.cpp:7-29
The structure of the JSON payload sent to the cloud function is defined in the README.md and implemented in firebase_notifier.cpp.
{
"title": "Mișcare detectată",
"body": "Sistemul a detectat o posibilă mișcare umană.",
"token": "device-fcm-token"
}
Sources: HomeSecurity/README.md:350-355, HomeSecurity/src/firebase_notifier.cpp:16
Summary
The Android mobile application is an essential component of the HomeSecurity system, providing the user with a direct window into their home's security status. Through its integration with Firebase services for authentication and messaging, and LibVLC for video streaming, it delivers a rich, real-time monitoring experience. The app's reactive UI and clear separation of concerns via MVVM architecture make it a robust and modern client for the IoT ecosystem.