# TLC Google Chat DSLR Camera Control

A Google Chat bot that provides remote control of DSLR cameras via SSH connections to Raspberry Pi devices. The bot responds to slash commands and interactive cards to capture images, view camera settings, and monitor error logs.

## Features

### Core Functionality
- **Remote Image Capture** - Trigger DSLR camera shots via SSH commands
- **Camera Settings Monitoring** - Real-time retrieval and display of camera configuration
- **Error Log Access** - View latest error logs from remote camera devices
- **Space-Based Management** - Independent camera assignments for each Google Chat space

### User Interface
- **Slash Commands** - `/capture`, `/settings`, `/errors`, `/setcamera`, `/list`, `/clear`
- **Interactive Cards** - Mobile-optimized button interface for quick actions
- **App Home Dashboard** - Comprehensive control panel accessible via Home tab
- **Smart Help System** - `@DSLR help` provides contextual assistance

### Advanced Features
- **Camera Selection Methods** - Dropdown search and visual thumbnail gallery
- **Concurrent Request Protection** - Lock system prevents operation conflicts
- **Enhanced Status Display** - Shows formatted camera names with IP addresses
- **Welcome System** - Automatic setup guidance for new spaces

## Architecture

### Entry Points
- **`app.php`** - Main Google Chat webhook handler
- **`app-home.php`** - App Home page dashboard handler

### Core Components
- **`capture.php`** - SSH-based image capture execution
- **`settings.php`** - Camera settings retrieval and formatting
- **`errors.php`** - Error log fetching and display
- **`input.php`** - Camera IP and space configuration management

### Database System
Space-based flat file database for camera assignments:
```
db/
├── {SPACE_ID}/
│   ├── VPN.txt     (Camera IP: "10.22")
│   └── NAME.txt    (Display name: "Client Location JN1234")
```

### Lock System
Prevents conflicts during concurrent operations:
- 30-second automatic expiration
- Operation-specific locking (capture, settings, errors, testing)
- Automatic cleanup of stale locks

## Quick Start

### Prerequisites
- Google Chat app configured with webhook endpoints
- SSH access to Raspberry Pi devices with DSLR cameras
- PHP environment with SSH2 extension

### Installation
1. Clone this repository to your web server
2. Configure Google Chat app webhook URLs:
   - Main webhook: `https://your-domain.com/path/to/app.php`
   - App Home: `https://your-domain.com/path/to/app-home.php`
3. Set proper file permissions: `claude:webproject` with 775/664
4. Configure SSH credentials in source files (see Security Notes)

### Configuration
1. Add the bot to a Google Chat space
2. Run `/setcamera` to select a camera from the master database
3. Use `/capture`, `/settings`, or `/errors` to control the camera
4. Access the App Home dashboard for comprehensive controls

## Usage

### Slash Commands
- **`/capture`** - Capture an image with the assigned camera
- **`/settings`** - View current camera settings and information
- **`/errors`** - Check latest error logs from the camera device
- **`/setcamera`** - Select camera using dropdown with search functionality
- **`/list`** - Alternative camera selection interface
- **`/clear`** - Remove camera assignment from current space

### Interactive Features
- **@DSLR help** - Display comprehensive help and command reference
- **Card Buttons** - Quick access to capture, settings, and testing functions
- **App Home** - Complete dashboard accessible via Home tab in DM spaces

### Camera Selection
Two methods available:
1. **Dropdown Selection** - Searchable list with client, location, and project filtering
2. **Thumbnail Gallery** - Visual interface with camera preview images

## Technical Details

### SSH Connection Pattern
All camera operations follow a consistent pattern:
1. Read camera IP from space-specific database
2. Connect using configured credentials
3. Execute remote commands with sudo privileges
4. Return formatted results with status indicators

### Google Chat Integration
- Supports all major interaction types: slash commands, button clicks, @mentions
- Mobile-optimized card layouts with responsive design
- Comprehensive error handling and user feedback
- Space-aware functionality with independent configurations

### Security Considerations
- SSH credentials are currently hardcoded in source files
- Camera IP addresses and space IDs stored in local flat files
- .gitignore configured to exclude sensitive configuration data
- Requires proper file permissions for multi-user access

## Development

### File Structure
```
├── app.php                 # Main webhook handler
├── app-home.php           # App Home dashboard
├── capture.php            # Image capture functionality
├── settings.php           # Camera settings retrieval
├── errors.php             # Error log access
├── input.php              # Configuration management
├── setCameraDialog.php    # Camera selection dialogs
├── testRelay.php          # Connection testing
├── testStorage.php        # Storage testing
├── images/                # Application assets
│   └── dslr-icon.png     # Bot icon
└── CLAUDE.md             # Development documentation
```

### Error Handling
- Comprehensive logging to `google-chat-errors.log`
- SSH connection timeouts and retry logic
- User-friendly error messages with troubleshooting guidance
- Validation for all user inputs and API responses

### Testing
- Built-in relay and storage testing functions
- Debug logging for troubleshooting
- Connection verification utilities

## License

Proprietary - TLC (Time Lapse Cameras)

## Support

For technical issues or questions, contact the development team or refer to the comprehensive troubleshooting section in `CLAUDE.md`.
