initial commit

This commit is contained in:
ray
2026-07-12 10:17:17 -04:00
commit dab5a4ebc6
1424 changed files with 330463 additions and 0 deletions
@@ -0,0 +1,93 @@
# Brother MFC → Paperless-ngx Scan Pipeline
Network scanner → Paperless consume folder, no drivers, no printer web admin password required.
## Prerequisites
- Brother MFC with network (WiFi or Ethernet) on same LAN as server
- `sane-airscan` installed (`sudo apt install sane-airscan sane-utils`)
- Paperless-ngx running with a consume folder mounted
## Setup (once)
### 1. Verify scanner discovery
```bash
scanimage -L
# Should show:
# device `airscan:e0:Brother MFC-J5855DW' is a eSCL Brother MFC-J5855DW ip=192.168.50.219
```
No Brother drivers needed — `sane-airscan` uses the driverless eSCL/AirScan protocol.
### 2. Ensure write access to consume folder
```bash
sudo setfacl -m u:$USER:rwx /path/to/paperless/consume
```
### 3. Install scan script at `/usr/local/bin/scan-to-paperless`
```bash
#!/bin/bash
# scan-to-paperless — scan from Brother MFC → Paperless consume folder
# Usage: scan-to-paperless [name] [--flatbed] [--gray] [--150dpi]
set -e
DEVICE="airscan:e0:Brother MFC-J5855DW"
CONSUME="/mnt/seagate8tb/paperless/consume"
MODE="Color"
RES="300"
SOURCE="ADF"
NAME=""
while [[ $# -gt 0 ]]; do
case "$1" in
--flatbed) SOURCE="Flatbed" ;;
--gray) MODE="Gray" ;;
--150dpi) RES="150" ;;
*) NAME="${1}_" ;;
esac
shift
done
SCAN_OPTS="--mode $MODE --resolution $RES"
if [ "$SOURCE" = "ADF" ]; then
SCAN_OPTS="$SCAN_OPTS --source ADF --batch-count=1"
fi
TIMESTAMP=$(date +%Y%m%d_%H%M%S)
FILENAME="${NAME}scan_${TIMESTAMP}.pdf"
OUTFILE="$CONSUME/$FILENAME"
echo "📄 Scanning ($SOURCE, $MODE, ${RES}dpi) → $FILENAME"
scanimage --device "$DEVICE" $SCAN_OPTS --format pdf -o "$OUTFILE"
SIZE=$(du -h "$OUTFILE" | cut -f1)
echo "✅ Done — $SIZE saved to Paperless"
```
## Daily usage
```bash
scan-to-paperless # ADF, color 300dpi
scan-to-paperless invoice # names it invoice_scan_20260614_172310.pdf
scan-to-paperless --flatbed # use flatbed (photos, fragile docs)
scan-to-paperless --gray --150dpi # B&W, low res (small file)
```
## Flow
```
scan-to-paperless
→ Brother scans via eSCL (AirScan over HTTP)
→ PDF saved to /mnt/seagate8tb/paperless/consume/
→ Paperless auto-ingests, OCRs, classifies, tags
```
## Alternative approaches that failed
- **Scan-to-FTP via Brother web interface**: Requires printer admin password. Defaults (`initpass`, `access`, `brother`) don't work on modern Brother MFCs (unique per-device password on sticker).
- **Scan-to-SMB via Brother**: Also requires web admin to create the profile. Samba share was set up but could not be configured on the printer side without the web password.
- **Brother brscan4 driver**: Proprietary `.deb` behind an EULA wall that requires browser cookie; `sane-airscan` driverless approach is simpler and works immediately.
@@ -0,0 +1,92 @@
# IoT Device Onboarding to Home Assistant
Pattern for adding new WiFi IoT devices (smart plugs, switches, sensors) to the local network and Home Assistant.
## Phase 1: Get Device on WiFi
### Stock Firmware (eWeLink / Tuya)
1. Device broadcasts a setup AP when first powered or reset (e.g., `ITEAD-XXXX` or `SmartLife-XXXX`)
2. Connect phone to that AP, use the **eWeLink** or **Smart Life** app to configure WiFi
3. After WiFi config, the AP disappears and device joins the home network
### Tasmota / ESPHome (already flashed)
1. Device broadcasts its own AP (e.g., `tasmota-XXXX-XXXX` or `esphome-XXXX`)
2. Connect phone to the AP, browse to `http://192.168.4.1` to configure WiFi
3. After save, device reboots onto the home network
## Phase 2: Find the IP Address
Devices often get DHCP-assigned IPs that aren't immediately obvious.
**Method A — Router DHCP table:**
Browse to router admin (ASUS: `http://192.168.50.1`), check Client List for the new device.
**Method B — App device info:**
In eWeLink app: tap device → ⚙️ Settings → Network Info / Device IP.
In Tasmota web UI: Information → Network.
**Method C — ARP scan for new IPs:**
```python
# Compare current ARP table against known IPs to find new devices
import subprocess
arp_output = subprocess.run(['cat', '/proc/net/arp'], capture_output=True, text=True).stdout
new_ips = [line.split()[0] for line in arp_output.split('\n')[1:] if line.strip()
and line.split()[0] not in known_ips]
```
**Method D — MAC vendor lookup:**
Identify unknown devices by MAC OUI:
```bash
curl -s "https://api.macvendors.com/XX:XX:XX" # first 3 octets only
# Sonoff/ITEAD common prefixes: 68:C6:3A, EC:FA:BC, C8:2B:96, DC:4F:22, 84:F3:EB
```
**Method E — Port scan for IoT signatures:**
```bash
# Sonoff LAN API port (Tasmota HTTP on :80, eWeLink LAN on :8081)
curl -s -m2 "http://DEVICE_IP:8081/"
# Tasmota status endpoint
curl -s -m2 "http://DEVICE_IP/cm?cmnd=Status%200"
```
## Phase 3: Enable Local Control
### Stock Sonoff (eWeLink)
1. In eWeLink app: ⚙️ Settings → **LAN Control** → ON
2. This enables the local TCP API on port 8081
3. Now HA's **Sonoff LAN** integration can auto-discover it
#### Troubleshooting LAN Mode
**Symptom: port 8081 accepts TCP but never responds.** The device completes the TCP handshake (SYN-ACK) but no application-layer data is returned — HTTP, WebSocket, and raw protocol requests all time out silently. This means the LAN API service process on the device is hung or was never started, even though the port shows as listening.
**Fix:** Power-cycle the device. Unplug for 10 seconds and plug back in. After reboot, verify:
```bash
# TCP must succeed
nc -zv -w3 DEVICE_IP 8081
# Must return JSON (not timeout)
curl -s --max-time 3 http://DEVICE_IP:8081/zeroconf/info
```
If `zeroconf/info` returns a JSON payload with `deviceid`, `model`, `sw_version` etc., LAN mode is working correctly.
### Tasmota
- Already local. Set MQTT or use the HTTP API directly.
- Default web UI at `http://DEVICE_IP/`
## Phase 4: Add to Home Assistant
1. **Sonoff LAN** integration: Settings → Devices & Services → Add Integration → Sonoff LAN → auto-discovers
2. **Tasmota** integration: Settings → Add Integration → Tasmota (auto-discovers via MQTT or HTTP)
3. **ESPHome**: Add via ESPHome dashboard or manual YAML
Manual MQTT discovery also works for all three.
## Sonoff S31-Specific Notes
- **Model**: S31 Lite (WiFi smart plug with power monitoring)
- **Flash method**: tuya-convert (OTA) or serial (TX/RX/GND/3.3V — requires opening case)
- **Stock LAN API port**: 8081 (TCP)
- **Tasmota template**: `{"NAME":"Sonoff S31","GPIO":[0,0,0,0,0,0,0,0,0,0,0,0,0,0],"FLAG":0,"BASE":18}`
- **Power monitoring**: HLW8012 chip — reports voltage, current, power, energy