Skip to content
Snippets Groups Projects
Commit 2bbe7b7a authored by marieschroeder's avatar marieschroeder
Browse files

Implementing Deepsleep + counter (as long as we have no timestep for naming picture files)

parent e8c36f04
No related branches found
No related tags found
3 merge requests!39Merge Develop into Main,!19development into master,!17Inital Host, initial Client
...@@ -61,6 +61,14 @@ over-the-air updates for the camera at one point. ...@@ -61,6 +61,14 @@ over-the-air updates for the camera at one point.
// LED control // LED control
#define LEDpin 4 #define LEDpin 4
// Deep Sleep Settings
#define uS_TO_S_FACTOR 1000000 /* Conversion factor for micro seconds to seconds */
#define TIME_TO_SLEEP 10 /* Time ESP32 will go to sleep (in seconds) */
// Counting files on sd card for saving in the name of each image
int fileCountOnSD = 0; // for counting files
// string for saving the time // string for saving the time
char time_string[20]; char time_string[20];
...@@ -237,21 +245,55 @@ void takeNewPhoto(String path) ...@@ -237,21 +245,55 @@ void takeNewPhoto(String path)
esp_camera_fb_return(fb); esp_camera_fb_return(fb);
} }
void readRTC() // Count files on SD card to give a meaningful count
{ void listDir(fs::FS &fs, const char * dirname, uint8_t levels){
// This is used for a picture timestamp (name of the image) Serial.printf("Listing directory: %s\n", dirname);
rtc.begin();
DateTime now = rtc.now(); File root = fs.open(dirname);
sprintf(time_string, "%04d-%02d-%02dT%02d-%02d-%02d", now.year(), now.month(), now.day(), now.hour(), now.minute(), if(!root){
now.second()); Serial.println("Failed to open directory");
Serial.println(time_string); return;
}
if(!root.isDirectory()){
Serial.println("Not a directory");
return;
}
File file = root.openNextFile();
while(file){
fileCountOnSD += 1;
//Serial.print(" FILE: ");
//Serial.print(file.name());
//Serial.print(" SIZE: ");
//Serial.println(file.size());
file = root.openNextFile();
}
Serial.println("File Count on SD: ");
Serial.println(fileCountOnSD);
} }
void readRTC()
{
// This is used for a picture timestamp (name of the image)
if (! rtc.begin()) {
Serial.println("Couldnt find RTC!");
} else {
Serial.println("Setting the time");
}
DateTime now = rtc.now();
sprintf(time_string, "%04d-%02d-%02dT%02d-%02d-%02d", now.year(), now.month(), now.day(), now.hour(), now.minute(),
now.second());
Serial.println(time_string);
}
Sht85 sht85Sensor; Sht85 sht85Sensor;
void setup() void setup()
{ { // control of the LED pin
// control of the LED pin
pinMode(LEDpin, OUTPUT); pinMode(LEDpin, OUTPUT);
// Disable brownout detector // Disable brownout detector
WRITE_PERI_REG(RTC_CNTL_BROWN_OUT_REG, 0); WRITE_PERI_REG(RTC_CNTL_BROWN_OUT_REG, 0);
...@@ -259,19 +301,24 @@ void setup() ...@@ -259,19 +301,24 @@ void setup()
// Start Serial // Start Serial
Serial.begin(115200); Serial.begin(115200);
Serial.println("Wake Up!");
delay(1000);
// Initialize the camera // Initialize the camera
Serial.print("Initializing the camera module..."); Serial.print("Initializing the camera module...");
camera_configESPCamera(); camera_configESPCamera();
Serial.println("Camera OK!"); Serial.println("Camera OK!");
espnow_setup(); espnow_setup();
sht85Sensor.setup(); sht85Sensor.setup();
}
void loop() // before in loop
{
// initiate I2C, read SHT+RTC, end I2C // initiate I2C, read SHT+RTC, end I2C
readRTC(); readRTC();
try { try {
// out_data_drs26 data= dr26.readData(); // out_data_drs26 data= dr26.readData();
// Serial.printf("data circumfrence"); // Serial.printf("data circumfrence");
...@@ -299,8 +346,12 @@ void loop() ...@@ -299,8 +346,12 @@ void loop()
Serial.print("Initializing the MicroSD card module... "); Serial.print("Initializing the MicroSD card module... ");
initMicroSDCard(); initMicroSDCard();
// Count files on SD card
listDir(SD_MMC, "/", 0);
// Path where new image will be saved in MicroSD card // Path where new image will be saved in MicroSD card
String path = "/" + String(time_string) + ".jpg"; String path = "/Picture_" + String(fileCountOnSD) + ".jpg";
Serial.printf("Picture file name: %s\n", path.c_str()); Serial.printf("Picture file name: %s\n", path.c_str());
// Take and save a picture // Take and save a picture
...@@ -311,4 +362,17 @@ void loop() ...@@ -311,4 +362,17 @@ void loop()
// Delay for specified period // Delay for specified period
delay(1000); delay(1000);
// Deep sleep
esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP * uS_TO_S_FACTOR);
Serial.println("Setup ESP32 to sleep for " + String(TIME_TO_SLEEP) + " Seconds");
Serial.println("Going to sleep now");
delay(1000);
Serial.flush();
gpio_hold_en((gpio_num_t)LEDpin);
esp_deep_sleep_start();
}
void loop()
{
} }
...@@ -19,8 +19,8 @@ ...@@ -19,8 +19,8 @@
// Pin definitions for I2C (SHT85, RTC) // Pin definitions for I2C (SHT85, RTC)
// This is different from the pins on the ESP32-C3-DevKit boards! // This is different from the pins on the ESP32-C3-DevKit boards!
#define SDA 12 #define SDA 13
#define SCL 13 #define SCL 12
struct out_data_sht85 { struct out_data_sht85 {
float temperature = 0.0; float temperature = 0.0;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment