Skip to content

Commit

Permalink
Delete file or folder from sd card
Browse files Browse the repository at this point in the history
  • Loading branch information
gemi254 committed Jun 25, 2020
1 parent 5c156f7 commit 696acea
Show file tree
Hide file tree
Showing 5 changed files with 380 additions and 15 deletions.
2 changes: 1 addition & 1 deletion ESP32-CAM_MJPEG2SD.ino
Original file line number Diff line number Diff line change
Expand Up @@ -124,5 +124,5 @@ void loop() {
delay(100000);
}

void deleteDayFolder() {}

void doUploadNAS() {}
4 changes: 2 additions & 2 deletions app_httpd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ size_t* getNextFrame();
void stopPlaying();
void controlLamp(bool lampVal);
void doUploadNAS();
void deleteDayFolder();
void deleteFolderOrFile(const char* val);
// status & control fields
extern float ambientTemp;
extern bool lampOn;
Expand Down Expand Up @@ -203,7 +203,7 @@ static esp_err_t cmd_handler(httpd_req_t *req){
else if(!strcmp(variable, "motion")) motionVal = val;
else if(!strcmp(variable, "lswitch")) nightSwitch = val;
else if(!strcmp(variable, "upload")) doUploadNAS();
else if(!strcmp(variable, "delete")) deleteDayFolder();
else if(!strcmp(variable, "delete")) deleteFolderOrFile(value);
else if(!strcmp(variable, "record")) doRecording = (val) ? true : false;
// enter <ip>/control?var=reset&val=1 on browser to force reset
else if(!strcmp(variable, "reset")) ESP.restart();
Expand Down
18 changes: 12 additions & 6 deletions camera_index.h
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ const char* index_ov2640_html = R"~(
}

.extras {
display: none;
display: block;
}

input[type=range]:active + output {
Expand Down Expand Up @@ -428,8 +428,8 @@ const char* index_ov2640_html = R"~(
</select>
</div>
<div class="extras"><br>
<button id="delete" style="float:right;" value="1">Delete Folder</button>
<button id="upload" style="float:right;" value="1">Upload Folder</button>
<button id="delete" style="float:right;" value="">Delete</button>
<!-- <button id="upload" style="float:right;" value="1">Upload Folder</button> -->
</div><br>
<div class="input-group" id="quality-group">
<label for="quality">Quality</label>
Expand Down Expand Up @@ -740,8 +740,13 @@ document.addEventListener('DOMContentLoaded', function (event) {
value = el.value
break
case 'button':
case 'submit':
value = '1'
case 'submit':
if(el.value!="1"){ //Delete folder or file
console.log(el.value);
value = el.value
}else{
value = '1'
}
break
default:
return
Expand Down Expand Up @@ -895,11 +900,12 @@ document.addEventListener('DOMContentLoaded', function (event) {
}

// folder / file option list
const sfile = document.getElementById('sfile')
const sfile = document.getElementById('sfile');
sfile.onchange = () => {
// build option list from json
var sid = $('#sfile');
var selection = sid.val();
document.getElementById('delete').value = selection; //Store file path for delete
sid.find('option:not(:first)').remove(); // remove all except first option
var listItems = '';
$.ajax({
Expand Down
65 changes: 59 additions & 6 deletions mjpeg2sd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@
*/

// user defined environmental setup
#define USE_PIR true // whether to use PIR for motion detection
#define USE_MOTION false // whether to use camera for motion detection (with motionDetect.cpp)
#define USE_PIR false // whether to use PIR for motion detection
#define USE_MOTION true // whether to use camera for motion detection (with motionDetect.cpp)
#define POST_MOTION_TIME 2 // number of secs after motion stopped to complete recording, in case movement restarts
#define CLUSTERSIZE 32768 // set this to match the SD card cluster size
#define MAX_FRAMES 20000 // maximum number of frames in video before auto close
#define ONELINE true // MMC 1 line mode
#define TIMEZONE "GMT0BST,M3.5.0/01,M10.5.0/02" // set to local timezone

//#define TIMEZONE "GMT0BST,M3.5.0/01,M10.5.0/02" // set to local timezone
#define TIMEZONE "EET-2EEST-3,M3.5.0/03:00:00,M10.5.0/04:00:00"

#include <SD_MMC.h>
#include <regex>
#include <sys/time.h>
Expand All @@ -23,7 +24,7 @@

// user parameters
bool debug = false;
bool doRecording = true; // whether to capture to SD or not
bool doRecording = false; // whether to capture to SD or not
uint8_t minSeconds = 5; // default min video length (includes POST_MOTION_TIME)
uint8_t nightSwitch = 20; // initial white level % for night/day switching
uint8_t motionVal = 7; // initial motion sensitivity setting
Expand Down Expand Up @@ -149,7 +150,14 @@ void getLocalNTP() {
} while (getEpoch() < 1000 && i++ < 5); // try up to 5 times
// set TIMEZONE as required
setenv("TZ", TIMEZONE, 1);
if (getEpoch() > 1000) showInfo("Got current time from NTP");
if (getEpoch() > 1000){

showInfo("Got current time from NTP");
time_t currEpoch = getEpoch();
strftime(partName, sizeof(partName), "%d/%m/%Y %H:%M:%S", localtime(&currEpoch));
Serial.println(partName);

}
else showError("Unable to sync with NTP");
}

Expand Down Expand Up @@ -211,6 +219,51 @@ void controlFrameTimer() {
timerAttachInterrupt(timer3, &frameISR, true);
}

void deleteFolderOrFile(const char * val) {
showInfo("Deleting : %s", val);
File f = SD_MMC.open(val);
if (!f){
showError("Failed to open %s", val);
return;
}
//Empty directory first
if (f.isDirectory()){
showInfo("Directory %s contents", val);
File file = f.openNextFile();
while(file){
if(file.isDirectory()){
Serial.print(" DIR : ");
Serial.println(file.name());
} else {
Serial.print(" FILE: ");
Serial.print(file.name());
Serial.print(" SIZE: ");
Serial.print(file.size());
if(SD_MMC.remove(file.name())){
Serial.println(" deleted.");
}else{
Serial.println(" FAILED.");
}
}
file = f.openNextFile();
}
f.close();
//Remove the dir
if(SD_MMC.rmdir(val)){
showInfo("Dir %s removed", val);
} else {
Serial.println("Remove dir failed");
}

}else{
//Remove the file
if(SD_MMC.remove(val)){
showInfo("File %s deleted", val);
} else {
Serial.println("Delete failed");
}
}
}
/**************** capture MJPEG ************************/

static bool openMjpeg() {
Expand Down
Loading

0 comments on commit 696acea

Please sign in to comment.