# OCTv2 (Oreo Cookie Thrower v2) - Raspberry Pi Server Python server to control your Oreo Cookie Thrower hardware from the iOS app. ## 🚀 Quick Setup ### 1. Install on Raspberry Pi ```bash # Copy files to your Pi scp -r raspberry_pi_server/ pi@your-pi-ip:~/octv2/ # SSH into your Pi ssh pi@your-pi-ip cd ~/octv2 ``` ### 2. Install Dependencies ```bash # Update system sudo apt update # Install Python camera library sudo apt install python3-picamera2 # Install GPIO library (usually pre-installed) sudo apt install python3-rpi.gpio # Or install from requirements pip3 install -r requirements.txt ``` ### 3. Configure Hardware Edit `octv2_server.py` to match your hardware: ```python # GPIO pins (adjust for your hardware) self.SERVO_PIN = 18 # Servo for aiming self.STEPPER_PINS = [19, 20, 21, 22] # Stepper motor pins self.FIRE_PIN = 23 # Fire mechanism trigger ``` ### 4. Run the Server ```bash # Make executable chmod +x octv2_server.py # Run the server python3 octv2_server.py # Or run in background nohup python3 octv2_server.py & ``` ### 5. Connect from iOS App 1. **Find your Pi's IP address:** ```bash hostname -I ``` 2. **In OCTv2 iOS app:** - Tap the ⚙️ settings button - Enter your Pi's IP address - Port: 8080 (default) - Tap "Connect to Launcher" ## 🎮 Supported Commands The server handles these commands from the iOS app: | Command | Description | |---------|-------------| | `aim_left` | Move aim left by 5° | | `aim_right` | Move aim right by 5° | | `fire` | Fire Oreo at specified angle | | `home` | Home device to reference position | | `set_mode` | Set auto/manual mode | | `capture_photo` | Take high-res photo | | `start_video_stream` | Begin video streaming | | `stop_video_stream` | Stop video streaming | | `status` | Get device status | ## 🔧 Hardware Configuration ### Servo Control (Aiming) - **Pin:** GPIO 18 (default) - **Type:** Standard servo (0-60° range) - **PWM:** 50Hz frequency ### Fire Mechanism - **Pin:** GPIO 23 (default) - **Type:** Digital output (relay/solenoid) - **Trigger:** 100ms pulse ### Camera - **Type:** Pi Camera Module - **Streaming:** 320x240 @ ~10fps - **Photos:** Full resolution saved to Pi ## 🐛 Troubleshooting ### "Camera not available" ```bash # Enable camera sudo raspi-config # Interface Options → Camera → Enable # Test camera libcamera-hello ``` ### "Permission denied" GPIO ```bash # Add user to gpio group sudo usermod -a -G gpio $USER # Logout and login again ``` ### "Connection refused" from app ```bash # Check if server is running ps aux | grep octv2_server # Check firewall sudo ufw status # Test connectivity telnet your-pi-ip 8080 ``` ### Server won't start ```bash # Check Python version python3 --version # Check dependencies pip3 list | grep -E "(picamera2|RPi.GPIO)" # Run with verbose logging python3 octv2_server.py --debug ``` ## 📝 Log Files Server logs are displayed in the terminal. To save logs: ```bash python3 octv2_server.py 2>&1 | tee octv2.log ``` ## 🔒 Security Note The server runs on port 8080 without authentication. For local network use only. ## 🍪 Happy Oreo Launching! Your OCTv2 is ready to launch cookies with precision control from your iPhone!