How herrera-dev/pircam_telegrambot_espcam works
Main Components
• Hardware:
• ESP32-CAM Board (the central processing and camera module).
• PIR Sensor (for motion detection).
• Power Management Unit (showing battery, TP4056, step-up converter, and external power inputs).
• Auxiliary components: LED indicators and any connection pins (note “pines_cam.h” serves as a pinout reference).
• Software/Firmware:
• Boot & Configuration Module: Responsible for loading stored configurations (token, WiFi credentials, user list) at startup; if not found, triggers WiFiManager’s AP mode.
• Telegram Bot Handler: Handles incoming Telegram commands (/estado, /foto, /VIGILAR, etc.), formats responses, and sends notifications.
• Camera & Sensor Handler: Manages image capture when the PIR sensor detects motion.
• Power Management / Deep Sleep Controller: Controls low-power state (deep sleep) and wakeup based on motion or timer.
• OTA Update Module: Enables over-the-air firmware updates.
• Debug Module: Implements remote debugging through TelnetStream.
• External Interactions:
• Telegram Servers (for receiving commands and sending images/status updates).
• Possibly additional services for battery monitoring or sensor diagnostics.
Relationships and Interactions
• On power-up, the Boot & Configuration module loads configuration data. If configuration data is missing (like the bot token or WiFi details), it activates WiFiManager in AP mode for reconfiguration.
• Once configured, the device connects to the user’s WiFi network. The Telegram Bot Handler then initiates a connection with the Telegram servers.
• The PIR sensor continuously monitors for motion. When motion is detected, the Camera & Sensor Handler captures an image.
• The captured image and status data (e.g., battery level or system state) are sent to registered users via the Telegram Bot Handler.
• Additionally, OTA updates can be triggered remotely, allowing firmware maintenance without physical access.
• The Debug Module (via TelnetStream) provides real-time diagnostics and logging information which can be crucial for troubleshooting.
Architectural Patterns & Design Principles
• Modularity: The firmware is designed as separate modules (configuration, sensor handling, bot communication) that clearly define responsibilities.
• Event-Driven Architecture: Events such as motion detection or incoming Telegram commands drive the flows within the system.
• Resilience & Fault Handling: The system is designed to handle missing configurations by switching to AP mode and includes fallback mechanisms (like disabling watchdog timers in some error cases).
• Energy Efficiency: Utilizes deep sleep modes for low-power operation especially when running on battery.