# NVR HiWatch DS-N316(D) Fix Progress

## Problem
All 9 XM cameras (53H20AF) cycle online/offline every ~20-30 seconds on NVR.
NVR IP: 192.168.1.123, FW: V4.76.015 build 250210
Network: 192.168.1.x (Знаменское, через Cudy router 100.70.54.204 Netbird)

## Camera List (Current - 9 channels)
1:192.168.1.101, 2:192.168.1.41, 3:192.168.1.58, 4:192.168.1.63, 5:192.168.1.10
6:192.168.1.69, 7:192.168.1.42, 8:192.168.1.57, 9:192.168.1.64

## ROOT CAUSE FOUND (2026-03-12)
UniFi Port 16 on a switch: **FE speed (100Mbps) + Critical status + Anomaly 70**
This is the uplink port to the Zyxel switch (non-UniFi).
A bad/degraded cable causes intermittent packet loss → RTSP sessions drop every ~20-30 sec → NVR cycling.
FIX: Replace the patch cable on Port 16 (between UniFi and Zyxel switch).

## Additional Findings
- Cameras are NOT physically rebooting (ping always UP throughout cycling)
- ONVIF GetStreamUri timeout: PT10S (very short)
- Camera AliveInterval: 21 seconds (DVR-IP keepalive)
- Sub stream RTSP: works (120KB/8s tested)
- Main stream RTSP: only 1 concurrent client allowed by camera
- RTSP from non-192.168.1.x subnet (e.g. 10.3.0.1): takes 18+ seconds to respond (reverse DNS timeout)

## Session 2 Fixes (2026-03-13)
### Applied (software):
- STP priorities: USL16PB(.220)=4096, USL16LPB(.66)=8192, (.213)=16384, (.96)=24576
- PortFast (stp_port_mode:true) on port 16 of switch .96 (where Zyxel connects)
- Main stream recording tracks 101-901: all enabled=true

### IP Conflict Resolved (critical!):
- 5 cameras had same IP 192.168.1.10 (ARP storm → ONVIF drops)
- Changed via DVR-IP SDK (xm_change_ip.py):
  - 00:12:12:82:da:3d → 192.168.1.170
  - 00:12:12:82:df:34 → 192.168.1.171
  - 00:12:12:a7:63:1c → 192.168.1.172
  - 00:12:12:73:09:1d → 192.168.1.173
  - 00:12:12:73:06:ab → still at .10 (on sw.66 port 6)
- NVR Ch5 (192.168.1.10) now unreachable (should be reconfigured or deleted)

### Switch/Camera Topology:
- NVR .123 = Hikvision, on switch .66 port 16 (GbE)
- Cameras on switch .66: port2=.173, port4=.63, port6=.170
- Cameras on switch .96: Zyxel on port 16 (FE 100Mbps), cameras via Zyxel
- Windows jump .135 on switch .66 port 14
- Cisco-Linksys .65 on switch .66 port 7 (DVR 192.168.1.65?)

### Physical Fix Required:
Replace patch cable on port 16 of switch 192.168.1.96 → Zyxel connection.
This is the ROOT CAUSE. All software fixes are secondary.

## NVR Recording Status
- All main stream tracks (101-901): enabled=true
- All sub stream tracks (201-901): enabled=true
- ActionRecordingMode: CMR (Continuous + Motion = 24/7 continuous recording)
- Schedule: All 7 days 24 hours covered

## Access
- SSH tunnels via: ssh -L PORT:TARGET_IP:TARGET_PORT root@100.70.54.204 -N -f
- UDMPRO SSH: root@100.70.100.155 (Netbird) or via jump: ssh -J root@100.70.54.204 root@10.3.0.175
- NVR ISAPI: http://127.0.0.1:18200 (via tunnel) admin/1qaz!QAZ (digest auth)

## What Was Tried & Failed
- Disabling sub-stream (VideoEnable=false) → still cycles
- Anonymous RTSP (Anonymity=true) → still cycles
- HIKVISION protocol → online=true but no video
- Custom Protocol with RTSP URL → NVR doesn't save RTSP URL fields, shows "Custom 1" with no streams
- streamType=main → NVR returns 400 (only "auto" supported)
- go2rtc on Cudy router (10.3.0.1) → cameras take 18s to respond (subnet issue)
- go2rtc on UDMPRO (192.168.1.1) → correct subnet, but firewall blocks port 8554 from LAN, SSH unstable

## Backup Plan (if cable fix doesn't work)
Run go2rtc on UDMPRO (192.168.1.1):
1. go2rtc binary: /data/go2rtc
2. Config: /data/go2rtc-config/go2rtc.yaml (all 9 cameras configured)
3. Need: add iptables rule for port 8554, create systemd service for persistence
4. NVR Custom Protocol: URLs would be rtsp://192.168.1.1:8554/camXX (but NVR doesn't save RTSP URLs in Custom Protocol!)
   - Alternative: HIKVISION protocol + manual video params

## Key Scripts
- /root/nvr_clean_test.py — full test: DVR-IP config + NVR add + monitor
- /root/xm_full_explore.py — explore camera settings via DVR-IP
- /root/xm_disable_substream.py — disable/enable sub-stream
- /root/xm_fix_rtsp.py — change RTSP anonymity settings
