UPS for ESP32 Microcontroller
If both batteries can be connected to the circuit simultaneously, you can consider using a power-OR topology. The simplest is two low-drop diodes, such as Schottky diodes with a suitable forward current (at least load current + safety factor) and sufficiently high reverse voltage (at least max battery voltage + safety factor; if reverse protection is an issue then at least twice max battery voltage + safety factor):







simulate this circuit &ndash; Schematic created using CircuitLab

Note shared ground/negative terminal.

This will allow current to be drawn from the battery with higher voltage, while preventing reverse (charging) current into the second battery. You can either just have the batteries connected to holders so that the user manually replaces them for charging, or you can use a pair of relays to realize this configuration.

There are more advanced versions of this configuration, where you replace the diodes with ICs that act as ideal diodes (perhaps with additional enhancements or features). In order to suggest one, we would need to know exact specifications.