# Printer Bridge - Connect to Home WiFi Printer from Extension Network

**Printer:** Brother DCP-T820DW  
**Home Network:** B901_4G  
**Extension Network:** 901 EXT5G (or similar)

This tool helps you connect to your Brother printer on the B901_4G network while you're connected to the extension WiFi network.

## The Problem

When you're on an extension WiFi network (often a different subnet), you typically can't directly access devices on the main home WiFi network, including printers. Your Brother printer is configured but uses a `.local` hostname that doesn't resolve when you're on a different network.

## Quick Start

### Step 1: Connect to B901_4G and Setup Printer

1. **Connect to B901_4G network** (the home WiFi where the printer is)

2. **Run the setup script:**
   ```bash
   ./setup_printer.sh
   ```

   This script will:
   - Find your Brother printer on the network
   - Get its IP address
   - Configure it using the IP address (instead of .local hostname)
   - Save the IP for future use

3. **Switch back to your extension network** (901 EXT5G)

### Step 2: Fix Connection on Extension Network

After switching back to your extension network, run:

```bash
./fix_printer_connection.sh
```

This will reconfigure the printer using the saved IP address. If the networks can communicate, printing will work!

## Solutions

### Option 1: Network Bridge/Router Configuration (Recommended for Permanent Fix)

If your extension WiFi is set up as a separate access point, configure your router to allow communication:

1. **Check if networks can communicate:**
   - Both networks should ideally be on the same subnet (e.g., 192.168.0.x)
   - Or configure routing between subnets on your router

2. **Access router settings:**
   - Log into your router's admin panel (usually 192.168.0.1 or 192.168.1.1)
   - Look for "Wireless Bridge" or "AP Mode" settings
   - Ensure the extension WiFi is in "Bridge Mode" or "Access Point Mode" (not router mode)
   - Disable "Client Isolation" or "AP Isolation" if enabled

### Option 2: Use IP Address Instead of Hostname

The scripts automatically configure the printer using its IP address, which works better across networks than the `.local` hostname.

### Option 3: Manual Printer Addition

If you know the printer's IP address:

1. **Find the printer IP:**
   - Check your router's connected devices list
   - Or check the printer's display/network settings

2. **Add printer manually:**
   ```bash
   # For HP JetDirect (port 9100)
   lpadmin -p PrinterName -v socket://PRINTER_IP:9100 -E
   
   # For IPP printing (port 631)
   lpadmin -p PrinterName -v ipp://PRINTER_IP:631/ipp/print -E
   
   # For LPD printing (port 515)
   lpadmin -p PrinterName -v lpd://PRINTER_IP -E
   ```

### Option 4: VPN/Network Solution

If networks are completely isolated, consider:
- Setting up a VPN between networks
- Using a network bridge device
- Configuring your router to bridge the networks

## Troubleshooting

### Can't find printer
- Ensure both networks can communicate (ping the printer IP)
- Check firewall settings
- Verify printer is powered on and connected

### Printer added but won't print
- Check printer is accessible: `ping PRINTER_IP`
- Test connection: `nc -zv PRINTER_IP 9100` (or port 631/515)
- Check printer queue: `lpstat -p`

### Networks are on different subnets
- Configure static routing on your router
- Or set up a network bridge/VPN solution

## Requirements

- Python 3.x
- macOS (uses `lpadmin`, `lpstat`, `ifconfig`)
- Admin privileges (for adding printers)

## Usage

### Initial Setup (on B901_4G network)

```bash
./setup_printer.sh
```

This will:
1. Find the Brother printer on B901_4G
2. Configure it with its IP address
3. Save the IP to `/tmp/brother_printer_ip.txt`

### Fix Connection (on extension network)

```bash
./fix_printer_connection.sh
```

This will:
1. Use the saved IP address
2. Test if printer is reachable
3. Reconfigure printer if accessible

### Manual IP Entry

If automatic detection fails, you can manually enter the printer IP when prompted by the scripts.

## Files

- `setup_printer.sh` - Main setup script (run on B901_4G)
- `fix_printer_connection.sh` - Fix connection script (run on extension network)
- `printer_bridge.py` - Python tool for printer discovery
- `network_check.py` - Network diagnostic tool
- `connect_brother_printer.py` - Python version of setup script

## Notes

- Scripts require admin privileges to add printers
- Brother printers typically use IPP (port 631) or Socket (port 9100)
- The printer IP is saved to `/tmp/brother_printer_ip.txt` for future use
- If networks cannot communicate, you'll need router-level configuration
- The `.local` hostname (BRW44FA66B8BFAA.local) only works on the same network segment
