# rpi-rtc - Raspberry Pi RTC & WatchDog Management

Complete solution for managing **DS3231 RTC** and hardware **WatchDog** on Raspberry Pi.

## Features

- **Web Panel** - Modern HTML/JS interface (FastAPI + WebSocket)
- **REST API** - Full REST API with real-time WebSocket updates
- **CLI Commands** - Direct commands for scripts and automation
- **CLI Shell** - Interactive command-line interface
- **Python Package** - Programmatic API (`piRTC` package)
- **Docker Support** - Containerized deployment

## Quick Links

| Document | Description |
|----------|-------------|
| [README_RTC.md](README_RTC.md) | RTC & WatchDog setup, CLI usage, testing |
| [README_piRTC.md](README_piRTC.md) | Python package (`piRTC`) documentation |

## Quick Start

### Method 1: Automated Installer (Recommended)
```bash
cd /home/tom/github/maskservice/rpi-rtc
./install.sh
```

### Method 2: Using Makefile
```bash
cd /home/tom/github/maskservice/rpi-rtc
make quick-start    # Installs deps, creates venv, installs package
make shell          # Run interactive shell
make server         # Start API server
```

### Method 3: Manual Installation
```bash
make deps           # Install system dependencies
make bootstrap      # Create venv and install deps
make install        # Install the package
```

### 4. Use CLI Shell
```bash
ssh pi@192.168.188.229 'cd /opt/rpi-rtc && python3 rtc_shell.py'
```

### 5. Start Web Server
```bash
# Access: http://192.168.188.229:8080
ssh pi@192.168.188.229 'cd /opt/rpi-rtc && python3 -m piRTC.api'
```

### 4. Python API
```python
from piRTC import RTCManager
rtc = RTCManager()
print(rtc.read_time())  # {'hour': 16, 'minute': 42, 'second': 0}
```

## Hardware Wiring

### DS3231 RTC
```
VDD -> 3.3V (Pin 1)   SCL -> SCL (Pin 5)
GND -> GND  (Pin 6)   SDA -> SDA (Pin 3)
```

### WatchDog
```
VDD  -> 3.3V   (Pin 1)    SCL  -> SCL     (Pin 5)
GND  -> GND    (Pin 6)    SDA  -> SDA     (Pin 3)
FEED -> GPIO 4 (Pin 7)
```

## Testing Status

✅ RTC maintains time after restart  
✅ System time sync working  
✅ I2C: 0x68 (RTC), 0x67 (WatchDog)  
✅ Temperature: 26-29°C  
✅ Web API on port 8080  

**Last Test:** March 15, 2026, 17:08 GMT  
**RPi IP:** 192.168.188.229

## License

Apache License 2.0 - see [LICENSE](LICENSE) for details.

## Author

Created by **Tom Sapletta** - [tom@sapletta.com](mailto:tom@sapletta.com)
