Compilation and Upload
Relevant source files
The following files were used as context for generating this wiki page:This document outlines the process for compiling the HomeSecurity firmware and uploading it to the ESP32 DOIT DevKit V1 microcontroller. The project utilizes the PlatformIO IDE within Visual Studio Code, which automates dependency management, compilation, and device programming.
The workflow involves cloning the repository, configuring project-specific credentials, and using PlatformIO commands or UI buttons to build the source code and flash the resulting binary onto the ESP32 board. This streamlined process is designed for rapid development and deployment.
Prerequisites
Before proceeding, ensure the following software is installed on your development machine:
- Visual Studio Code: The primary code editor.
- PlatformIO IDE Extension: An extension for VS Code that provides the necessary tools for embedded development.
Sources: HomeSecurity/README.md:200-202
Installation and Setup
The initial setup involves cloning the project repository and letting PlatformIO handle the necessary library installations.
Setup Flow
The following diagram illustrates the one-time setup process.
Sources: HomeSecurity/README.md:204-213
Step-by-Step Instructions
- Clone the Repository: Use Git to clone the project to your local machine.
git clone https://github.com/IonutMilitaru/HomeSecurity.git cd HomeSecurity - Open in VS Code: Open the cloned project folder in Visual Studio Code.
code . - Install Dependencies: Upon opening the project, the PlatformIO extension will automatically detect the
platformio.inifile and install the required libraries. The primary dependency is theFirebase Arduino Client Library for ESP8266 and ESP32.
Sources: HomeSecurity/README.md:204-213
Configuration Before Build
Before compiling and uploading, you must configure network and cloud service credentials directly in the source code.
WiFi Configuration
The WiFi network SSID and password must be set in src/wifi_manager.cpp.
// File: HomeSecurity/src/wifi_manager.cpp
char* WIFI_SSID = "YourNetworkName";
char* WIFI_PASSWORD = "YourPassword";
Sources: HomeSecurity/README.md:225-228, HomeSecurity/src/wifi_manager.cpp:4-5
Firebase Configuration
The Firebase Cloud Function URL and the target device's FCM token must be configured in src/motion_logic.cpp.
- FirebaseNotifier: The constructor takes the full URL of the
sendNotificationcloud function. - fcmToken: This constant holds the Firebase Cloud Messaging token for the mobile device that will receive notifications.
// File: HomeSecurity/src/motion_logic.cpp
FirebaseNotifier notifier("https://your-firebase-function-url.cloudfunctions.net/sendNotification");
const char* fcmToken = "your-device-fcm-token";
Sources: HomeSecurity/README.md:230-234, HomeSecurity/src/motion_logic.cpp:4,7
Timing Parameters
Several timing parameters that control the system's behavior can also be configured.
| Parameter | Location | Default Value | Description |
|---|---|---|---|
WIFI_CONNECTION_TIMEOUT | src/wifi_manager.cpp | 15000ms | Timeout for establishing a WiFi connection. |
ALARM_DURATION | include/alarm.h | 3000ms | Duration for which the buzzer remains active. |
| PIR Calibration | src/pir_sensor.cpp | 30000ms | Warm-up period for the PIR sensor. |
| Radar Confirmation | src/motion_logic.cpp | 2000ms | Time threshold for sustained radar motion to confirm presence. |
Sources: HomeSecurity/README.md:236-242, HomeSecurity/src/wifi_manager.cpp:3, HomeSecurity/include/alarm.h:8, HomeSecurity/src/pir_sensor.cpp:11, HomeSecurity/src/motion_logic.cpp:103
Build and Upload Process
Once configured, the firmware can be compiled and uploaded to the ESP32. This can be done via the PlatformIO command-line interface (CLI) or the VS Code user interface.
Upload Workflow
This diagram shows the process of deploying the code from the developer's machine to the ESP32.
Sources: HomeSecurity/README.md:215-223
Using PlatformIO CLI
Execute the following command in the VS Code terminal to compile the code and upload it to the connected ESP32 board.
pio run --target upload
Sources: HomeSecurity/README.md:218
Using PlatformIO IDE
Alternatively, use the "Upload" button (typically an arrow icon) in the PlatformIO toolbar at the bottom of the VS Code window.
Verification
After a successful upload, you can monitor the device's serial output to verify its status and observe runtime logs.
Monitor Command
Use the PlatformIO CLI to open a serial monitor session with the correct baud rate.
pio device monitor --baud 115200
Upon successful initialization and calibration, you should see the following message:
[SYSTEM] Initializare completă. Aștept calibrare...
Sources: HomeSecurity/README.md:221-223, HomeSecurity/src/main.cpp:6