Firmware Configuration
Relevant source files
The following files were used as context for generating this wiki page:- HomeSecurity/include/wifi_manager.h
- HomeSecurity/src/wifi_manager.cpp
- HomeSecurity/include/firebase_notifier.h
- HomeSecurity/src/firebase_notifier.cpp
- HomeSecurity/src/motion_logic.cpp
- HomeSecurity/include/alarm.h
- HomeSecurity/include/led.h
- HomeSecurity/include/pir_sensor.h
- HomeSecurity/include/hall_sensor.h
- HomeSecurity/include/microwave_sensor.h
- HomeSecurity/README.md
The HomeSecurity firmware requires several compile-time configurations to function correctly. These settings define network connectivity, cloud service endpoints, and hardware-specific parameters like GPIO pin assignments and operational timings. Proper configuration is essential for connecting the ESP32 device to the local network, enabling communication with Firebase for push notifications, and ensuring sensors and actuators behave as expected.
This document outlines the key configuration parameters that must be set in the source code before building and uploading the firmware. It covers network credentials, Firebase integration details, and hardware definitions.
Network Configuration
Network configuration is managed within the wifi_manager module and is critical for the device's IoT capabilities. It includes WiFi credentials and connection management logic.
Sources: HomeSecurity/src/wifi_manager.cpp, HomeSecurity/include/wifi_manager.h
WiFi Credentials
The WiFi network name (SSID) and password must be hardcoded into the firmware. These are defined as global variables.
Sources: HomeSecurity/src/wifi_manager.cpp:6-7
char* WIFI_SSID = "IonutMoto";
char* WIFI_PASSWORD = "12345678";
Connection Management
The system implements an automatic reconnection mechanism managed by a dedicated FreeRTOS task, WiFiCheckTask. If the WiFi connection is lost, this task will attempt to reconnect using the configured credentials. A timeout is defined to prevent the system from hanging indefinitely during the initial connection attempt.
The following diagram illustrates the WiFi connection and reconnection flow.
Key connection parameters are summarized below.
| Parameter | File | Default Value | Description |
|---|---|---|---|
WIFI_SSID | src/wifi_manager.cpp | "IonutMoto" | The SSID of the WiFi network to connect to. |
WIFI_PASSWORD | src/wifi_manager.cpp | "12345678" | The password for the WiFi network. |
WIFI_CONNECTION_TIMEOUT | src/wifi_manager.cpp | 15000 (ms) | Maximum time to wait for a WiFi connection before timing out. |
Sources: HomeSecurity/src/wifi_manager.cpp:4-7
Cloud Service Configuration
The firmware integrates with Firebase via a Cloud Function to send push notifications to the companion mobile application. This requires configuring the specific Cloud Function URL and the target device's Firebase Cloud Messaging (FCM) token.
Sources: HomeSecurity/src/motion_logic.cpp, HomeSecurity/include/firebase_notifier.h, HomeSecurity/src/firebase_notifier.cpp
Firebase Notifier
The FirebaseNotifier class encapsulates the logic for sending HTTP POST requests to the notification service. It is instantiated with the URL of the Google Cloud Function.
The class diagram below shows the structure of FirebaseNotifier.
The configuration parameters are defined in motion_logic.cpp.
| Parameter | File | Default Value | Description |
|---|---|---|---|
notifier | src/motion_logic.cpp | FirebaseNotifier("https://trimitenotificare-k4cqa7es6q-uc.a.run.app") | The FirebaseNotifier object initialized with the Cloud Function URL. |
fcmToken | src/motion_logic.cpp | "d-OlFNUNSaSStUUsL05ofB:..." | The FCM token of the Android device that will receive the notifications. |
Sources: HomeSecurity/src/motion_logic.cpp:4-7
The sequence diagram below shows how a notification is sent when motion is detected.
Hardware & Timing Configuration
This section details the compile-time constants that map hardware components to ESP32 GPIO pins and define the timing for various operations.
GPIO Pin Mapping
All sensor and actuator pins are defined using #define macros in their respective header files. The README.md provides a consolidated view.
| Component | GPIO Pin | Header File |
|---|---|---|
| Hall Sensor | 33 | include/hall_sensor.h |
| PIR Sensor | 21 | include/pir_sensor.h |
| Radar Sensor | 22 | include/microwave_sensor.h |
| Buzzer | 25 | include/alarm.h |
| Yellow LED | 19 | include/led.h |
| Blue LED | 18 | include/led.h |
| Red LED | 23 | include/led.h |
| Green LED | 4 | include/led.h |
| White LED | 13 | include/led.h |
Sources: HomeSecurity/README.md, HomeSecurity/include/hall_sensor.h:5, HomeSecurity/include/pir_sensor.h:6, HomeSecurity/include/microwave_sensor.h:6, HomeSecurity/include/alarm.h:5, HomeSecurity/include/led.h:5-9
Timing Parameters
Operational timings, such as alarm duration and sensor calibration, are configured via #define macros or constants.
| Parameter | File | Default Value | Description |
|---|---|---|---|
ALARM_DURATION | include/alarm.h | 3000 (ms) | Duration for which the buzzer sounds when triggered. |
| PIR Calibration Time | src/pir_sensor.cpp | 30000 (ms) | Warm-up period for the PIR sensor after system boot. |
| Radar Confirmation Time | src/motion_logic.cpp | 2000 (ms) | Duration of continuous radar activity required to confirm presence. |
Sources: HomeSecurity/include/alarm.h:6, HomeSecurity/src/pir_sensor.cpp:12, HomeSecurity/src/motion_logic.cpp:111
Summary
The firmware's behavior is heavily influenced by a set of compile-time constants and definitions. These configurations, spread across several header and source files, control everything from basic network connectivity to the nuanced logic of the multi-stage alert system. Developers must ensure that the WiFi credentials, Firebase endpoint, and FCM token are correctly set for their specific environment. The GPIO and timing parameters are tied to the physical hardware assembly and should only be changed if the circuit design is modified.