Control a Reolink NVR With an ESP32: API, Mute, Restore

An ESP32 can mute a Reolink NVR over its HTTPS API: login token, per-channel commands, self-signed certificates and a restore that survives a reboot.

Published
Reading time
9 min
Category
Builds
A man presses the button on a small wall switch, with dashed lines linking it to three security cameras, each marked with a crossed-out eye.

In short

An ESP32 logs in to the Reolink NVR's HTTPS API, gets a token and sends SetPushV20 and SetRecV20 commands per channel. Restore turns both back on, even after a reboot.

Yes, an ESP32 can control a Reolink NVR. It logs in to the NVR's HTTPS API at /api.cgi, receives a session token, and sends SetPushV20 and SetRecV20 commands to switch push notifications and recording off per channel. A second set of commands turns them back on.

You leave home, your own movement fills the NVR with alerts, and you'd rather not open the Reolink app every time. This post follows the real firmware of Gizmo Reolink Switch, a XIAO ESP32-S3 with a button, a buzzer and a 16x2 LCD. Every pin, number and message below comes from its open-source repository, and I flag what I could not verify at the end.

Open-source ESP32 + Reolink project
Gizmo Reolink Switch

An ESP32-powered quiet-exit switch that uses a button, buzzer, 16x2 I2C LCD, and WiFi connection to temporarily mute Reolink NVR notifications and recording.

  • Quiet-exit timer
  • 16x2 LCD interface
  • Direct Reolink API control
Check it out

A cartoon of a man crouching in a backyard, startled by a wall-mounted security camera

The Reolink HTTP API is a JSON interface served by the NVR itself. You send HTTPS POST requests to https://<nvr>/api.cgi?cmd=<Command>&token=<token>, and the body is always a JSON array of commands, even when there is only one. I found no official Reolink API page I could link, so the firmware source is my reference here, and everything below describes what that firmware sends and reads.

The firmware does not use Basic or Digest authentication. It sends a Login command with token=null in the URL and the user name and password in the JSON body. The reply contains a token name and a lease time in seconds, and the token goes in the &token= parameter of every later call.

CommandWhat it doesUsed by the firmware for
LoginReturns Token name and leaseTimeGetting a session token
GetChannelstatusLists channels with an online flagFinding the cameras to mute (online only)
SetPushV20Sets push notifications per channelMuting and restoring alerts
SetRecV20Sets recording per channelMuting and restoring recording

The firmware's request details are in reolink.cpp and reolink_protocol.cpp:

  • Token lease. If the reply has no leaseTime, the firmware assumes 3600 seconds. That default is my firmware's choice, not a documented Reolink value. It refreshes the token 60 seconds before the lease ends.
  • Expired session. Error code -6 means a missing or expired session. The firmware logs in again and retries the call once.
  • Batching. The mute is one POST with one SetPushV20 and one SetRecV20 entry per online channel, and the firmware reads the result of each entry.
  • Parameters. Each entry carries channel, enable and scheduleEnable, all set to 0 to mute and 1 to restore.
  • Limits. The HTTP timeout is 10 seconds, a reply over 16,384 bytes is refused, and the firmware tracks channels 0 to 31 (it reads at most 16 online channels).

I did not verify which NVR models and firmware versions accept these commands, so treat this as what the firmware does, not a promise about your NVR. Run a Login and a GetChannelstatus from your computer first, to see what yours answers.

What does the ESP32 code look like?

The firmware uses the Arduino framework on PlatformIO (framework = arduino, platform = espressif32 @ 8.0.0 in platformio.ini). It does not use esp_http_client: the HTTP side is the Arduino HTTPClient over a WiFiClientSecure, with ArduinoJson 7.2.2 for the bodies. If you are choosing a toolchain, see Arduino IDE vs PlatformIO for ESP32.

The core of a request is short. This is a trimmed version of what the firmware does, not a copy:

Trimmed from reolink.cpp
Trimmed from reolink.cpp
WiFiClientSecure secureClient;
HTTPClient http;

secureClient.setInsecure();  // accept the NVR's self-signed certificate
http.begin(secureClient, "https://192.168.1.10/api.cgi?cmd=Login&token=null");
http.setTimeout(10000);
http.addHeader("Content-Type", "application/json");
int status = http.POST(R"([{"cmd":"Login","action":0,"param":{"User":{"userName":"admin","password":"..."}}}])");
Ln 8, Col 1UTF-8cpp

Two details save memory. The firmware keeps one TLS connection open for all the requests of a mute or restore, so they share a single handshake, then closes it so no idle TLS session holds heap. If the NVR closed the kept connection meanwhile, the firmware reconnects and sends the same commands again, which is safe because setting a value to 0 or 1 twice changes nothing.

Why does HTTPS fail on a self-signed NVR certificate?

A self-signed certificate is one the device signed for itself, so no public certificate authority vouches for it. The firmware's own comment says Reolink NVRs commonly use one, and the ESP32's TLS client rejects such a certificate unless you tell it otherwise. The Gizmo Reolink Switch firmware calls secureClient.setInsecure(), which the Arduino-ESP32 header describes as "Don't validate the chain, just accept whatever is given. VERY INSECURE!".

The tradeoff, option by option:

OptionEncryptedServer identity checkedCost
setInsecure()YesNoNone, but someone on your LAN could impersonate the NVR (what Gizmo Reolink Switch does)
setCACert() with the NVR's own certificateYesYesYou paste the certificate in, and update it when the NVR renews it
A certificate you control, from your own CAYesYesYou run the CA and install the certificate on the NVR

Skipping verification still encrypts the traffic, so a passive sniffer on your Wi-Fi sees nothing useful. It does not stop an active man-in-the-middle, who could present their own certificate and collect the NVR password. On a home LAN I find that acceptable for a device that only toggles two settings. On a network you do not trust, pin the certificate with setCACert().

The session token also travels in the URL query string, as the firmware builds it, so treat it like a password for the length of its lease. I did not check whether the NVR logs request URLs.

What do mute and restore really do?

Mute turns off push notifications and recording on every online channel. Restore turns both back on. That's all, and the second half matters: restore does not read the NVR's previous state and put it back. It sets notifications and recording to enabled on the channels the switch muted. If you had switched recording off on a channel on purpose, it comes back on after the first quiet exit.

Two rows of boxes: mute (login, channel status, save to flash, enable 0) and restore (enable 1, clear flash, retry every 60 seconds)

I chose "undo only what you changed" over a full snapshot, which would need to read every setting back and store it. The cost is the limit above, and the README says it too. The benefit is a small, testable state: two bitmasks, one for notifications and one for recording, with one bit per channel.

The order is the point:

  1. Long press. The firmware logs in (or reuses a valid token) and calls GetChannelstatus to find the online channels.
  2. Save first. It writes the muted channels to flash (NVS) before sending any mute command, so an interrupted request can still be undone.
  3. Mute. One batched POST sets enable to 0 for each channel's push and recording settings. Settings the NVR refuses are dropped from the saved list, because they never changed.
  4. Countdown. The timer starts only once the mute finished, so the network calls don't eat into it.
  5. Restore. On timer end or cancel, the firmware sends enable 1 for the saved settings and forgets only the ones the NVR confirmed.

The mask logic has native tests, so you can run it without a board: pio test -e native in microcontroller/.

What happens after a reboot or a power cut while muted?

The firmware restores the cameras right after it boots. The muted masks live in NVS, the ESP32's key-value flash storage, and setup() checks them: if any channel is still muted, it flags an immediate restore, and the loop runs it as soon as the Wi-Fi is up. The countdown is not saved, so a reboot ends the quiet mode early instead of leaving the cameras silent. I think that is the right failure: a camera that records too much is better than one that silently records nothing.

Other failures follow the same rule, keep the mask until the NVR confirms:

SituationWhat the firmware doesLCD shows
Wi-Fi is down at restore timeKeeps the mask, retries every 60 sWi-Fi Offline / Will retry
NVR unreachable or command refusedKeeps the mask, retries every 60 sRestore Failed / Will retry
A muted camera is offlineRestores the online ones, keeps the rest pendingCam Offline! / Will retry
NVR refuses some mute commandsDrops them from the mask, keeps the countdownPartly Muted! / Some cams failed
NVR refuses the login (wrong password)Pauses logins for 10 minutesNVR Login Err!, then Login Paused / Check password
Restore still pending, timer idleWaits for a retry, or a button hold retries nowAlerts Still OFF / Hold to retry

Holding the button while Alerts Still OFF is on screen retries immediately. The factory reset (BOOT button held for 10 seconds) and the NVR login change are both refused while cameras are muted, because the saved login is what restores them.

Which parts and pins does the build use?

The board is a Seeed Studio XIAO ESP32-S3 with its FPC antenna connected: the XIAO has no antenna on the board and will not join Wi-Fi without one. The pins come from config.cpp.

PartXIAO ESP32-S3 padGPIONotes
ButtonD01To GND, internal pull-up (INPUT_PULLUP)
BuzzerD12Driven HIGH and LOW, on for 50 ms or 800 ms
LCD SDAD4516x2 I2C LCD, backpack at 0x27
LCD SCLD56I2C clock
LCD and buzzer power5V and GND-As the README lists it: the board's 5 V pad

The LCD driver is the hd44780_I2Cexp class from duinoWitchery/hd44780 1.3.2, which finds the I2C backpack and its address by itself (the README lists it at 0x27, but the firmware never reads that constant). If your screen stays blank, the checklist in ESP32 I2C LCD 16x2 Not Working covers the address, the 5 V supply and the contrast. The buzzer is switched with plain digitalWrite, so use one that makes sound from a DC level (an active buzzer), not a passive one that needs a tone. The pin choice avoids D2 (GPIO3), a boot strapping pin, and the serial pads D6 and D7. For the board's other pins, see XIAO ESP32-S3 Pinout: Which Pins Are Safe to Use.

How do the button, buzzer and LCD work together?

One button does everything, with a debounce of 40 ms and a long press at 700 ms.

  • Short press while idle: add time. It adds 1 minute below 5 minutes, then 5 minutes at a time up to 60. The next press wraps to zero, so an overshoot can be fixed without starting the timer.
  • Long press while idle: start the quiet mode. The LCD says Hold to mute with Mute for <time>.
  • Short press while the timer runs: it changes nothing and shows Alerts OFF / Hold to cancel.
  • Long press while the timer runs: cancel and restore.

The buzzer gives a 50 ms beep for a selection, an 800 ms beep for a started quiet mode or a completed restore, and a double beep as a warning (partial mute, failed restore). It beeps once in each of the last two seconds of the countdown. Failed background retries stay silent, so a camera that is offline doesn't beep every minute.

Other LCD messages, in the order you meet them: Reolink Switch / Booting now..., Join Wi-Fi Setup, Set Up NVR: Open (with the switch's address), Checking NVR / Connecting..., NVR Linked / 3 cams online (the number is your count of online cameras), Quiet Mode ON / Muting cameras, Cameras Muted! / Exit safely!, Alerts OFF / 12:34 left (the format is the remaining time), and Time Is Up / Alerts restored!. While the firmware talks to the NVR it drops button presses on purpose, because a late press would act on the next screen.

How do you set up the Wi-Fi and the NVR login?

Nothing is compiled into the firmware. On the first boot the LCD shows Join Wi-Fi Setup and the switch opens an open hotspot called Gizmo-Reolink; your phone's captive portal opens the setup page. If that popup does not appear, see ESP32 Captive Portal Not Working? Fix the Wi-Fi Popup. Then the NVR page of the dashboard takes the address, user name and password, tests the login and counts the online cameras.

Three phone screenshots of the switch's web app: Switch status, NVR login and Wi-Fi setup

The login is saved in NVS on the board. The project does not turn on flash encryption (nothing in platformio.ini does), so someone with physical access and a USB cable could probably read it. The password is write-only: the dashboard never gets it back, and changing the NVR address or user name clears it, so it is only ever sent to the NVR it was typed for.

The dashboard cannot start, cancel or retry the quiet mode. This is on purpose: nobody on your Wi-Fi can mute your cameras without standing at the switch. The firmware ships as a prebuilt release you can flash from the project page, as explained in ESP Web Tools: Flash an ESP32 From Your Browser. For the other ways to give a board its Wi-Fi, see ESP32 Wi-Fi Provisioning: Captive Portal, BLE, Improv.

Numbers worth knowing

ValueSettingWhere it comes from
10 sHTTP timeout per requestREOLINK_HTTP_TIMEOUT_MS
60 sRestore retry interval, and token refresh marginREOLINK_RESTORE_RETRY_MS, TOKEN_REFRESH_MARGIN_SECONDS
10 minLogin pause after a refused loginREOLINK_LOGIN_PAUSE_MS
16,384 bytesLargest NVR reply acceptedREOLINK_MAX_REPLY_BYTES
60 minLongest quiet modeTIMER_MAX_DURATION_SECONDS
3600 sToken lease assumed when the reply has noneDEFAULT_TOKEN_LEASE_SECONDS

What does this build not do, and where next?

The switch restores alerts and recording to enabled, not to what they were. It talks to one NVR over the local network, with no certificate check. The repository does not say which NVR model or firmware version it was tested against, and I can't tell you which ones accept these commands, so run the connection check on the NVR page before you trust it with the front door.

If you want the full parts list and the flash button, open Gizmo Reolink Switch. For a case to put it in, start with 3D-Printed ESP32 Enclosure Design Rules That Fit, and for the bigger picture of how these builds fit together, read What is OpenGizmo?.

Frequently asked questions

Find quick answers to the most common questions about this topic.

Yes. An ESP32 on the same network can log in to the NVR's HTTPS API, receive a session token and send commands that switch push notifications and recording on or off per channel. I have not verified which NVR models and firmware accept these commands, so test your own NVR before building around it.

Published Updated

Ready to build your own gizmo?

Pick an open-source ESP32 project and follow its step-by-step guide, from the parts list and wiring to the firmware and the first boot.

Read also

Explore categories