# Capture Service

Reads RTL-SDR (or generates fake test data) and writes raw ADS-B packets to PostgreSQL.

## What it does

1. Waits for PostgreSQL to be ready
2. Creates a row in `fr24.captures` with session metadata
3. Writes fake `fr24.raw_packets` rows every ~2 seconds (14-byte DF17 Mode-S format)
4. Touches `/tmp/capture-ready` for Docker healthcheck
5. On SIGTERM: marks the capture session as `stopped`

In production, replace the fake packet loop in `main.py` with real RTL-SDR / dump1090 input.

## Dependencies

- `psycopg2-binary` — PostgreSQL driver

## Environment variables

| Variable | Default | Description |
|---|---|---|
| `POSTGRES_HOST` | required | DB host |
| `POSTGRES_PORT` | `5432` | DB port |
| `POSTGRES_DB` | required | DB name |
| `POSTGRES_USER` | required | DB user |
| `POSTGRES_PASSWORD` | required | DB password |
| `RTLSDR_CENTER_FREQUENCY` | `1090000000` | Center freq Hz |
| `RTLSDR_SAMPLE_RATE` | `2000000` | Sample rate Hz |
| `RTLSDR_DEVICE_INDEX` | `0` | RTL-SDR device index |
| `RTLSDR_GAIN` | `auto` | Gain dB or `auto` |
| `PACKET_INTERVAL_SECONDS` | `2.0` | Interval between fake packets |

## Run locally

```bash
pip install -r requirements.txt
export POSTGRES_HOST=localhost POSTGRES_DB=fr24 POSTGRES_USER=fr24 POSTGRES_PASSWORD=change-me
python main.py
```

## Build & run via Docker

```bash
docker build -t fr24-capture .
docker run --env-file ../../compose/.env fr24-capture
```
