Skip to content

Commit d368327

Browse files
committed
NVS
Store passwords in nvs
1 parent a6fe686 commit d368327

File tree

5 files changed

+45
-38
lines changed

5 files changed

+45
-38
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
Application for ESP32 / ESP32S3 with OV2640 / OV5640 camera to record JPEGs to SD card as AVI files and playback to browser as an MJPEG stream. The AVI format allows recordings to replay at correct frame rate on media players. If a microphone is installed then a WAV file is also created and stored in the AVI file.
55
The application supports:
6+
* [RTSP Server](#rtsp) stream Video, Audio and Subtitles
67
* [Motion detection by camera](#motion-detection-by-camera) or PIR / radar sensor
78
* Time lapse recording
89
* [Audio Recording](#audio-recording) from I2S or PDM microphones
@@ -29,7 +30,7 @@ To suggest an improvement or enhancement use Discussions.***
2930

3031
Changes up to version 10.5.4:
3132
* Stream to [NVR](#stream-to-nvr) using integration to RTSPServer library contributed by [@rjsachse](https://github.com/rjsachse).
32-
* RTSP server now has multiple client support as well as user/pass authentication
33+
* RTSP server now has multiple client support as well as user/pass authentication.
3334
* Frame resolution selection mismatch corrected due to [#10801](https://github.com/espressif/arduino-esp32/issues/10801) in arduino core v3.1.0
3435
* SD card 4 bit mode configurable (see `utilsFS.cpp`)
3536
* Shared I2C fixed following code changes in Arduino core v3.1.1
@@ -454,7 +455,7 @@ Streaming performance depends on quality of network connection, but can be incre
454455

455456
#### RTSP
456457

457-
This requires an additional library to be installed - see [RTSPServer](https://github.com/rjsachse/ESP32-RTSPServer) library for details. Must be version 1.3.0 or above
458+
This requires an additional library to be installed - see [RTSPServer](https://github.com/rjsachse/ESP32-RTSPServer) library for details. Must be version 1.3.1 or above
458459

459460
To integrate library with this app, set `#define INCLUDE_RTSP` to `true`.
460461

appGlobals.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -491,8 +491,8 @@ extern uint16_t rtpSubtitlesPort;
491491
extern char RTP_ip[];
492492
extern uint8_t rtspMaxClients;
493493
extern uint8_t rtpTTL;
494-
extern char rtspUser[];
495-
extern char rtspPassword[];
494+
extern char RTSP_Name[];
495+
extern char RTSP_Pass[];
496496

497497
// task handling
498498
extern TaskHandle_t battHandle;

appSpecific.cpp

Lines changed: 12 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -228,23 +228,6 @@ bool updateAppStatus(const char* variable, const char* value, bool fromUser) {
228228
else if (!strcmp(variable, "uartTxdPin")) uartTxdPin = intVal;
229229
else if (!strcmp(variable, "uartRxdPin")) uartRxdPin = intVal;
230230
#endif
231-
232-
#if INCLUDE_RTSP
233-
234-
else if (!strcmp(variable, "rtsp00User")) strncpy(rtspUser, value, MAX_IP_LEN-1);
235-
else if (!strcmp(variable, "rtsp01Pass")) strncpy(rtspPassword, value, MAX_IP_LEN-1);
236-
else if (!strcmp(variable, "rtsp02Video")) rtspVideo = streamVid = (bool)intVal;
237-
else if (!strcmp(variable, "rtsp03Audio")) rtspAudio = streamAud = (bool)intVal;
238-
else if (!strcmp(variable, "rtsp04Subtitles")) rtspSubtitles = streamSrt = (bool)intVal;
239-
else if (!strcmp(variable, "rtsp05Port")) rtspPort = intVal;
240-
else if (!strcmp(variable, "rtsp06VideoPort")) rtpVideoPort = intVal;
241-
else if (!strcmp(variable, "rtsp07AudioPort")) rtpAudioPort = intVal;
242-
else if (!strcmp(variable, "rtsp08SubtitlesPort")) rtpSubtitlesPort = intVal;
243-
else if (!strcmp(variable, "rtsp09Ip")) strncpy(RTP_ip, value, MAX_IP_LEN-1);
244-
else if (!strcmp(variable, "rtsp10MaxC")) rtspMaxClients = intVal;
245-
else if (!strcmp(variable, "rtsp11TTL")) rtpTTL = intVal;
246-
#endif
247-
248231
#ifndef AUXILIARY
249232
// camera settings
250233
else if (!strcmp(variable, "xclkMhz")) xclkMhz = intVal;
@@ -995,16 +978,16 @@ relayMode~0~3~S:Manual:Night~How relay activated
995978
relaySwitch~0~3~C~Switch relay off / on
996979
I2Csda~-1~3~N~I2C SDA pin if unshared
997980
I2Cscl~-1~3~N~I2C SCL pin if unshared
998-
rtsp00User~~8~T~RTSP Auth Username
999-
rtsp01Pass~~8~T~RTSP Auth Password
1000-
rtsp02Video~1~8~C~Enable RTSP Video
1001-
rtsp03Audio~0~8~C~Enable RTSP Audio
1002-
rtsp04Subtitles~1~8~C~Enable RTSP Subtitles
1003-
rtsp05Port~554~8~N~RTSP ServerPort
1004-
rtsp06VideoPort~5430~8~N~RTSP Video Port
1005-
rtsp07AudioPort~5432~8~N~RTSP Audio Port
1006-
rtsp08SubtitlesPort~5434~8~N~RTSP Subtitles Port
1007-
rtsp09Ip~239.255.0.1~8~T~RTSP Multicast IP
1008-
rtsp10MaxC~3~8~N~RTSP Multicast Max Connections
1009-
rtsp11TTL~1~8~N~RTSP Multicast Time-to-Live
981+
RTSP_Name~~8~T~RTSP Auth Username
982+
RTSP_Pass~~8~T~RTSP Auth Password
983+
rtsp00Video~1~8~C~Enable RTSP Video
984+
rtsp01Audio~0~8~C~Enable RTSP Audio
985+
rtsp02Subtitles~1~8~C~Enable RTSP Subtitles
986+
rtsp03Port~554~8~N~RTSP ServerPort
987+
rtsp04VideoPort~5430~8~N~RTSP Video Port
988+
rtsp05AudioPort~5432~8~N~RTSP Audio Port
989+
rtsp06SubtitlesPort~5434~8~N~RTSP Subtitles Port
990+
rtsp07Ip~239.255.0.1~8~T~RTSP Multicast IP
991+
rtsp08MaxC~3~8~N~RTSP Multicast Max Connections
992+
rtsp09TTL~1~8~N~RTSP Multicast Time-to-Live
1010993
)~";

prefs.cpp

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,9 @@ static bool savePrefs(bool retain = true) {
191191
#endif
192192
#if INCLUDE_MQTT
193193
prefs.putString("mqtt_user_Pass", mqtt_user_Pass);
194+
#endif
195+
#if INCLUDE_RTSP
196+
prefs.putString("RTSP_Pass", RTSP_Pass);
194197
#endif
195198
prefs.end();
196199
LOG_INF("Saved preferences");
@@ -221,6 +224,9 @@ static bool loadPrefs() {
221224
#endif
222225
#if INCLUDE_MQTT
223226
prefs.getString("mqtt_user_Pass", mqtt_user_Pass, MAX_PWD_LEN);
227+
#endif
228+
#if INCLUDE_RTSP
229+
prefs.getString("RTSP_Pass", RTSP_Pass, MAX_PWD_LEN);
224230
#endif
225231
prefs.end();
226232
return true;
@@ -314,7 +320,20 @@ void updateStatus(const char* variable, const char* _value, bool fromUser) {
314320
else if (!strcmp(variable, "mqtt_user_Pass") && value[0] != '*') strncpy(mqtt_user_Pass, value, MAX_PWD_LEN-1);
315321
else if (!strcmp(variable, "mqtt_topic_prefix")) strncpy(mqtt_topic_prefix, value, (FILE_NAME_LEN/2)-1);
316322
#endif
317-
323+
#if INCLUDE_RTSP
324+
else if (!strcmp(variable, "RTSP_Name")) strncpy(RTSP_Name, value, MAX_HOST_LEN-1);
325+
else if (!strcmp(variable, "RTSP_Pass") && value[0] != '*')strncpy(RTSP_Pass, value, MAX_PWD_LEN-1);
326+
else if (!strcmp(variable, "rtsp00Video")) rtspVideo = streamVid = (bool)intVal;
327+
else if (!strcmp(variable, "rtsp01Audio")) rtspAudio = streamAud = (bool)intVal;
328+
else if (!strcmp(variable, "rtsp02Subtitles")) rtspSubtitles = streamSrt = (bool)intVal;
329+
else if (!strcmp(variable, "rtsp03Port")) rtspPort = intVal;
330+
else if (!strcmp(variable, "rtsp04VideoPort")) rtpVideoPort = intVal;
331+
else if (!strcmp(variable, "rtsp05AudioPort")) rtpAudioPort = intVal;
332+
else if (!strcmp(variable, "rtsp06SubtitlesPort")) rtpSubtitlesPort = intVal;
333+
else if (!strcmp(variable, "rtsp07Ip")) strncpy(RTP_ip, value, MAX_IP_LEN-1);
334+
else if (!strcmp(variable, "rtsp08MaxC")) rtspMaxClients = intVal;
335+
else if (!strcmp(variable, "rtsp09TTL")) rtpTTL = intVal;
336+
#endif
318337
// Other settings
319338
else if (!strcmp(variable, "clockUTC")) syncToBrowser((uint32_t)intVal);
320339
else if (!strcmp(variable, "timezone")) strncpy(timezone, value, FILE_NAME_LEN-1);
@@ -410,6 +429,9 @@ void buildJsonString(uint8_t filter) {
410429
#endif
411430
#if INCLUDE_MQTT
412431
p += sprintf(p, "\"mqtt_user_Pass\":\"%.*s\",", strlen(mqtt_user_Pass), FILLSTAR);
432+
#endif
433+
#if INCLUDE_RTSP
434+
p += sprintf(p, "\"RTSP_Pass\":\"%.*s\",", strlen(RTSP_Pass), FILLSTAR);
413435
#endif
414436
}
415437
} else {

rtsp.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,9 @@ uint16_t rtpSubtitlesPort;
4141
char RTP_ip[MAX_IP_LEN];
4242
uint8_t rtspMaxClients;
4343
uint8_t rtpTTL;
44-
char rtspUser[MAX_IP_LEN] = "";
45-
char rtspPassword[MAX_IP_LEN] = "";
44+
char RTSP_Name[MAX_HOST_LEN-1] = "";
45+
char RTSP_Pass[MAX_PWD_LEN-1] = "";
46+
bool useAuth;
4647

4748
IPAddress rtpIp;
4849
char transportStr[30]; // Adjust the size as needed
@@ -129,7 +130,7 @@ static void startRTSPSubtitles(void* arg) {
129130
}
130131

131132
void prepRTSP() {
132-
rtspServer.setCredentials(rtspUser, rtspPassword); // Set RTSP authentication
133+
useAuth = rtspServer.setCredentials(RTSP_Name, RTSP_Pass); // Set RTSP authentication
133134
RTSPServer::TransportType transport = determineTransportType();
134135
rtpIp.fromString(RTP_ip);
135136
rtspServer.transport = transport;
@@ -147,7 +148,7 @@ void prepRTSP() {
147148
if (transport != RTSPServer::NONE) {
148149
if (rtspServer.init()) {
149150
LOG_INF("RTSP server started successfully with transport%s", transportStr);
150-
strlen(rtspUser) ?
151+
useAuth ?
151152
LOG_INF("Connect to: rtsp://<username>:<password>@%s:%d (credentials not shown for security reasons)", WiFi.localIP().toString().c_str(), rtspServer.rtspPort) :
152153
LOG_INF("Connect to: rtsp://%s:%d", WiFi.localIP().toString().c_str(), rtspServer.rtspPort);
153154

0 commit comments

Comments
 (0)