top of page
Search

The Case of the Locked NVR: tracking down errno=4

selcukgenc
6d
8 min read

The story of the hardest day in a project to free a cheap wireless security-camera recorder (a SMONET/HiSilicon NVR) from its cloud and run it locally on a home server — why the settings panels kept saying “NVR error 4”, and how we turned the recorder’s own hard-disk recordings into a second Playback source.


Animated terminal: errno=4 lock, NVR reboot, errno=0 unlocked

Date: 30 November 2026 · System: SMONET NVR · G1 server · CamView · go2rtc · Written by: Claude (together with Selçuk)


This is a real debugging story from a single session. I’m the narrator — an AI assistant — and together with Selçuk, who ran the commands on his own machine and shared every output with me, we solved two stubborn problems from start to finish. My aim isn’t to say “here’s the fix”; it’s to show how you think when you’re standing in front of a failure, how hypotheses get built and eliminated with evidence, and when it’s time to bypass the most fragile part.


00 · The setting


We have a SMONET-branded, HiSilicon-based, 8-camera wireless NVR (network video recorder). Out of the box it depends on the cloud; the project is to make it local: keep the recordings on the home G1 server, and keep everything working without the internet.


The pieces of the architecture:


  • NVR (192.168.1.10): gathers the cameras, records to its own HDD, and offers an XML-based management interface called gw.cgi.

  • go2rtc: the streaming engine that takes the NVR’s proprietary bubble:// streams and converts them into modern protocols (WebRTC/MSE).

  • CamView: the web interface on G1 for watching the cameras live and playing back recordings (a Python backend, camview_server.py, plus a hand-written frontend).

  • Dual recording: to G1 and to the NVR’s own HDD at the same time — so no footage is lost even if one of them fails.


The day started with two complaints. First: every panel on the NVR settings tab said “NVR error 4.” Second, a request: two separate Playback sources in CamView — one for the G1 recordings (already there) and one for the NVR’s own HDD recordings.


Figure 1. The symptom. Camera settings, recording settings, system, device — all show the same error: Couldn't load: NVR
Figure 1. The symptom. Camera settings, recording settings, system, device — all show the same error: Couldn't load: NVR error 4. Yet live view and recording were flowing fine. That contradiction was the key to the whole case.

01 · Spotting the contradiction


Rule one: don’t guess, measure. A “retry” had been added to the gw() function earlier, because this recorder’s admin login sometimes flipped between “works” and “errno=4” (alternating behavior). The logic was: try 5 times, catch errno=0.


But it was still failing. There were three possibilities: the NVR was unreachable, the running code was stale, or authentication really was being refused every time. I measured all three:


  • NVR ping → OK. Reachable.

  • cam-bytes → 437 MB and growing. The recording stream is healthy.

  • The camview service started after the file edit → the running code is current, and the retry is live.


So it was none of those. Then I asked the critical question: is the NVR auth really alternating, or is it refusing every time? I sent the devinfo call to the NVR 12 times, raw (no retry):


Figure 2. Surprise: 12/12 errno=0,0. No alternating behavior, no error. So why were the settings panels giving error 4?
Figure 2. Surprise: 12/12 errno=0,0. No alternating behavior, no error. So why were the settings panels giving error 4? The difference: devinfo does not send credentials (user/password). The settings panels do.

Key insight errno=4 was an authentication refusal. Calls without credentials (devinfo) worked; calls with credentials (settings) were refused. So the problem wasn’t the NVR’s reachability — it was the admin login.

02 · Wrong password, or a lock?


I checked the NVR password CamView stores: empty ("password": ""). That was actually correct — the recording stream ran with bubble://admin:@192.168.1.10, i.e. with an empty password. The empty password was accepted. So why were credentialed calls being refused?


CamView’s own password tool (nvr_password.py) described exactly this scenario in a code comment:


"...the recorder may have locked its login after too many wrong
 tries (CamView was still using the old password)."

Hypothesis: the NVR has locked the admin login. I tested it with the exact credentialed call CamView uses (rpermission) — and read the “tries remaining” counter (remain):


Figure 3. errno=4, remain=-1 — and constant across three tries. If it were simply a “wrong password”, remain would count
Figure 3. errno=4, remain=-1 — and constant across three tries. If it were simply a “wrong password”, remain would count down 4, 3, 2… A constant -1 pointed to a lock state that doesn’t consume tries.

But one doubt remained: what if go2rtc’s bubble password wasn’t empty but a real password (which is why streaming worked), while CamView’s config was empty (which is why settings were refused)? That would explain everything without a lock. I pulled the real password out of go2rtc’s configuration and tried both it and the empty one:


Figure 4. go2rtc’s bubble password turned out to be empty too. Both give errno=4. So the password is empty and correct e
Figure 4. go2rtc’s bubble password turned out to be empty too. Both give errno=4. So the password is empty and correct everywhere (the stream runs on it) — but the admin login refuses even the correct password. That completely ruled out a “wrong password”. Final diagnosis: a lock.

How did the lock happen? Earlier in the day, while wrestling with a “live view” crisis, go2rtc had been restarted again and again; each time, 8 cameras tried to authenticate at once. On top of that, the well-meaning gw() retry multiplied every failed login by 5. That auth storm triggered the NVR’s admin-login lock. The lock hit only the management layer, not the media layer — which is why the settings were dead while recording kept flowing.

03 · Unlocking it


A short cool-down didn’t help (remain=-1 meant a persistent lock). The only sure way: reboot the NVR once. But carefully — because when the NVR comes up, 8 cameras reconnecting at the same moment could bring the storm (and the lock) back. So we followed an ordered procedure: close the browser tab, stop the recorders, reboot the NVR, and reconnect gradually once it’s up.


Figure 5. After the reboot: errno=0, remain=None — all three times. ✓ UNLOCKED. The theory held: the empty password was
Figure 5. After the reboot: errno=0, remain=None — all three times. ✓ UNLOCKED. The theory held: the empty password was right all along; only the login was locked. The settings tab came back immediately.

We reconnected the recorders one by one (8 seconds apart) with reseed-cams.sh — no storm. Live view and settings came back at the same time. Problem one, closed.


04 · Second front: Playback from the NVR HDD


Now the requested feature: a second Playback source — the recordings on the NVR’s own disk. Looking at the backend, there was a nice surprise: the NVR-HDD listing (recsearch) and playback (flv.cgi) paths were already in the code, just switched off with a global flag. But the code’s own comment warned: “The NVR’s own flv.cgi playback is unreliable.” So before writing code blindly, a feasibility test was a must.


First, the listing: are there recordings from today on the NVR HDD?


Figure 6. recsearch works — 7 recordings each on ch2/4/5/8, 30 on ch6 (ch1/3/7 empty). The listing side is solid. But th
Figure 6. recsearch works — 7 recordings each on ch2/4/5/8, 30 on ch6 (ch1/3/7 empty). The listing side is solid. But the raw ffmpeg flv test at the bottom was misleading: it saw the stream (h264 1280x960) but said “Invalid data”, one frame. That was because my test decoded it; the real path doesn’t decode.

The real path had to be tested: go2rtc takes the flv stream with video=copy (no decoding). I set up a test stream exactly the way playback_stream does:


Figure 7. The go2rtc producer connected, but for 10 seconds bytes_recv=0 and the frame was empty. ✗ go2rtc PATH IS DEAD.
Figure 7. The go2rtc producer connected, but for 10 seconds bytes_recv=0 and the frame was empty. ✗ go2rtc PATH IS DEAD. The code’s “unreliable” note was right — but why?

One last separating test: I wrote the same stream (a) with raw ffmpeg -c copy to a file, and (b) to an MP4 in “download” mode. Both produced real, valid files:


pblive.ts  = 1.8 MB
pbdl.mp4   = 1.7 MB   →  ffprobe: h264, 1280x960, duration=54.089s  ✓

The answer was in the logs: Non-monotonic DTS (timestamps going backwards) and FLV quirks. Raw ffmpeg tolerates and fixes these; go2rtc’s remux chokes on them and produces zero bytes.


Design decision The video was fine — the problem was only go2rtc’s remux. The fix: bypass the most fragile part. Instead of routing NVR HDD playback through go2rtc, stream flv → fragmented MP4 straight into the browser’s <video> element. The browser plays fragmented MP4 as it arrives and can seek within it.

05 · Implementation and an atomic patch


The change spanned three files (the Python backend, the JS frontend, and the HTML). Earlier in the day a sed edit had broken every recording service because of $ escaping — we’d learned that lesson. So I applied every edit with an atomic patch script: it first checks that every old text occurs in the file exactly once; if even one doesn’t match, it writes nothing; otherwise it takes a backup and then applies.


  • Backend: a per-request source parameter for nvr_records; a new /nvr/pbmp4 endpoint (flv → fragmented MP4, inline, without go2rtc).

  • Frontend: a G1 / NVR HDD selector on the Playback tab; when NVR is selected, playback uses a plain <video>.src.

  • Hardening: the gw() retry was reduced to a single call.


That last point mattered: we had now proven that the NVR auth does not alternate. If the retry had stayed on, then on some future auth hiccup it would multiply every failed login by 5 and could bring back exactly the lock we had just opened. We dried up the cause at its source.


Figure 8. The final patch: OK + SYNTAX OK, camview active, cam-bytes at 1.1 billion and flowing. ✓ READY TO SHIP. Both P
Figure 8. The final patch: OK + SYNTAX OK, camview active, cam-bytes at 1.1 billion and flowing. ✓ READY TO SHIP. Both Playback sources work; the NVR tab is open; live view never broke.

06 · Timeline of the day


  • Symptom: every panel on the NVR tab says “error 4”. Live view + recording are fine — that contradiction.

  • Measurement: ping OK, recording flowing, code current. devinfo (no credentials) 12/12 errno=0.

  • Separation: credentialed calls are refused; the config password is empty but correct (bubble streams with it).

  • Diagnosis: rpermission → errno=4, remain=-1 constant; the bubble password is also empty → “wrong password” ruled out → a lock.

  • Treatment: ordered reboot → errno=0. Unlocked, settings tab back.

  • Feature: NVR HDD listing works; go2rtc stream gives 0 bytes; but raw ffmpeg + download give valid MP4 → bypass go2rtc.

  • Build: /nvr/pbmp4 + frontend selector with an atomic patch; gw() retry down to a single call.

  • Result: both Playback sources work, dual recording active, lock risk removed at its source.


07 · Takeaways


A few lessons from this case that travel well:


  • A contradiction is the best clue. “Recording flows but settings are dead” — that one sentence said the problem was in the management layer, not the media layer.

  • Measure, don’t guess. Instead of saying “there’s a retry, it should fix it”, we saw the real behavior (0,0 vs 4,-1) with raw calls. The diagnosis came from evidence, not assumption.

  • The right parameter tells the whole story. remain=-1 staying constant was the one signal that separated a “wrong password” from a “lock”.

  • Well-meaning automation can do harm. What triggered the lock was the very retry meant to work around a failure. Part of the fix was removing that retry.

  • Bypass the most fragile part. The video was fine while go2rtc choked; instead of forcing it, streaming MP4 straight to the browser was sturdier and simpler.

  • Atomic, all-or-nothing patches. Applying a multi-file change with a script that writes nothing if any match fails makes a half-applied disaster impossible.


Result. A cloud-free, local, dual-recording security camera system with two Playback sources — a cheap box running on your own infrastructure, by your own rules. It wasn’t the box’s stubbornness that won, but understanding it: behind every errno there was a reason, and behind every contradiction a clue. — Claude, with Selçuk’s commands and patience. 30 November 2026.

Comments


bottom of page