Ci-dessous, les différences entre deux révisions de la page.
Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédente | ||
projets:esp32-cam_timelaps_code [2020/06/03 14:49] – gepeto | projets:esp32-cam_timelaps_code [2024/02/09 16:56] (Version actuelle) – modification externe 127.0.0.1 | ||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
+ | < | ||
/* | /* | ||
ESP32-CAM l'oeil clignotemps | ESP32-CAM l'oeil clignotemps | ||
Ligne 34: | Ligne 35: | ||
" | " | ||
" | " | ||
- | " | + | " |
" | " | ||
" | " | ||
Ligne 48: | Ligne 49: | ||
// edit these parameters for your needs | // edit these parameters for your needs | ||
- | static const char vernum[] = "v9cGepeto"; // modif AccesPoint and http filesystem | + | static const char vernum[] = "v10Gepeto"; // modif AccesPoint and http filesystem |
// plage horaire | // plage horaire | ||
#include < | #include < | ||
Ligne 74: | Ligne 75: | ||
// startup defaults for first recordin | // startup defaults for first recordin | ||
// here are the recording options from the " | // here are the recording options from the " | ||
+ | // framesize=UXGA& | ||
// VGA 10 fps for 30 min, repeat, realtime | // VGA 10 fps for 30 min, repeat, realtime | ||
// VGA 2 fps, for 30 minutes repeat, 30x playback | // VGA 2 fps, for 30 minutes repeat, 30x playback | ||
Ligne 152: | Ligne 154: | ||
int file_number = 0; | int file_number = 0; | ||
int internet_connected = 0; // 0 non connecté , 1 mode sta , 2 freewifi, 3 mode AP | int internet_connected = 0; // 0 non connecté , 1 mode sta , 2 freewifi, 3 mode AP | ||
- | bool ntp_ok = false; | ||
struct tm timeinfo; | struct tm timeinfo; | ||
time_t now; | time_t now; | ||
Ligne 280: | Ligne 281: | ||
void Test_horaires() { // cherche si heure maintenant contenue dans horaires | void Test_horaires() { // cherche si heure maintenant contenue dans horaires | ||
- | if (internet_connected >= 3 || ntp_ok == false) { // pas internet = pas horaire | + | |
+ | | ||
return; | return; | ||
+ | } else { | ||
+ | Serial.println(F(" | ||
+ | int heure = 0 ; | ||
+ | int taille_plages = strlen(horaire); | ||
+ | if (taille_plages > 3 ) { | ||
+ | char buf[3] = " | ||
+ | for (int i = 0; i < taille_plages; | ||
+ | buf[0] = horaire[i++]; | ||
+ | if (horaire[i] != ',' | ||
+ | else buf[1] = ' | ||
+ | buf[2] = ' | ||
+ | heure = atoi(buf); | ||
+ | time(& | ||
+ | localtime_r(& | ||
+ | // | ||
+ | // | ||
+ | if ((int)timeinfo.tm_hour | ||
+ | // | ||
+ | // | ||
+ | heure = 99; | ||
+ | break; | ||
+ | } | ||
+ | } | ||
+ | int reste = 58 - (int)timeinfo.tm_min; | ||
+ | if (reste > 3 && heure < 90) { | ||
+ | // | ||
+ | Serial.print(F(" | ||
+ | Serial.println(reste); | ||
+ | esp_sleep_enable_timer_wakeup(1000000 * 60 * (uint64_t)reste); | ||
+ | esp_deep_sleep_start(); | ||
+ | delay(1000); | ||
+ | } | ||
+ | } else Serial.println(F(" | ||
} | } | ||
- | Serial.println(F(" | ||
- | int heure = 0 ; | ||
- | int taille_plages = strlen(horaire); | ||
- | if (taille_plages > 3 ) { | ||
- | char buf[3] = " | ||
- | for (int i = 0; i < taille_plages; | ||
- | buf[0] = horaire[i++]; | ||
- | if (horaire[i] != ',' | ||
- | else buf[1] = ' | ||
- | buf[2] = ' | ||
- | heure = atoi(buf); | ||
- | time(& | ||
- | localtime_r(& | ||
- | // | ||
- | // | ||
- | // | ||
- | if ((int)timeinfo.tm_hour | ||
- | // | ||
- | // | ||
- | heure = 99; | ||
- | break; | ||
- | } | ||
- | } | ||
- | // | ||
- | int reste = 58 - (int)timeinfo.tm_min; | ||
- | if (reste > 3 && heure < 90) { | ||
- | end_avi(); | ||
- | Serial.print(F(" | ||
- | Serial.println(reste); | ||
- | esp_sleep_enable_timer_wakeup(1000000 * 60 * (uint64_t)reste); | ||
- | esp_deep_sleep_start(); | ||
- | delay(1000); | ||
- | } | ||
- | } else Serial.println(F(" | ||
} | } | ||
/// | /// | ||
Ligne 351: | Ligne 352: | ||
json[" | json[" | ||
json[" | json[" | ||
- | json["total_frames" | + | json["length" |
json[" | json[" | ||
json[" | json[" | ||
Ligne 370: | Ligne 371: | ||
Serial.println(F(" | Serial.println(F(" | ||
if (readFileconfig() == true) { | if (readFileconfig() == true) { | ||
- | Serial.print(F(" | + | |
- | Serial.println(buf_config); | + | |
File configFile = SPIFFS.open("/ | File configFile = SPIFFS.open("/ | ||
configFile.print(buf_config); | configFile.print(buf_config); | ||
Ligne 411: | Ligne 412: | ||
if (json[" | if (json[" | ||
if (json[" | if (json[" | ||
- | if (json[" | + | if (json[" |
if (json[" | if (json[" | ||
else strlcpy (ssid , ssid_ap, sizeof(ssid)); | else strlcpy (ssid , ssid_ap, sizeof(ssid)); | ||
Ligne 427: | Ligne 428: | ||
configFile.close(); | configFile.close(); | ||
Serial.println(F(" | Serial.println(F(" | ||
+ | total_frames = xlength * 1000 / capture_interval; | ||
} | } | ||
Ligne 565: | Ligne 567: | ||
skipping = 0; | skipping = 0; | ||
Serial.println(" | Serial.println(" | ||
+ | delay(100); | ||
} | } | ||
Ligne 633: | Ligne 636: | ||
card_err = init_sdcard(); | card_err = init_sdcard(); | ||
if (card_err != true) { | if (card_err != true) { | ||
- | Serial.printf(" | + | Serial.printf(" |
major_fail(); | major_fail(); | ||
- | return; | ||
} | } | ||
loadSPIFFSConfigFile(); | loadSPIFFSConfigFile(); | ||
- | Serial.printf(" | + | |
pinMode(33, OUTPUT); | pinMode(33, OUTPUT); | ||
Ligne 702: | Ligne 704: | ||
bool init_wifi() | bool init_wifi() | ||
{ | { | ||
- | WiFi.disconnect(true); | + | |
- | WiFi.mode(WIFI_STA); | + | |
- | WiFi.setHostname(devname); | + | WiFi.mode(WIFI_STA); |
- | WiFi.begin(ssid, | + | WiFi.setHostname(devname); |
- | delay(1000); | + | WiFi.begin(ssid, |
- | while (WiFi.status() != WL_CONNECTED ) { | + | |
delay(1000); | delay(1000); | ||
- | | + | |
- | if (connAttempts == 10) { | + | |
- | Serial.println(F(" | + | |
- | | + | |
- | delay(2000); | + | |
- | if (WiFi.SSID() == (String)" | + | |
- | Serial.println(F(" | + | |
- | internet_connected = 2; | + | |
- | } | + | |
delay(1000); | delay(1000); | ||
- | | + | Serial.print(F(" |
- | internet_connected = 3; | + | if (connAttempts == 10) { |
- | | + | Serial.println(F(" |
+ | WiFi.begin(" | ||
+ | delay(2000); | ||
+ | if (WiFi.SSID() == (String)" | ||
+ | Serial.println(F(" | ||
+ | internet_connected = 2; | ||
+ | | ||
+ | delay(1000); | ||
+ | } | ||
+ | | ||
+ | internet_connected = 3; | ||
+ | break; | ||
+ | | ||
+ | connAttempts++; | ||
} | } | ||
- | connAttempts++; | ||
} | } | ||
if (internet_connected == 0) internet_connected = 1; | if (internet_connected == 0) internet_connected = 1; | ||
if (internet_connected < 3) { | if (internet_connected < 3) { | ||
Serial.println(WiFi.SSID()); | Serial.println(WiFi.SSID()); | ||
- | Serial.println(internet_connected); | ||
char pool[16] = ""; | char pool[16] = ""; | ||
if ( internet_connected == 2) { | if ( internet_connected == 2) { | ||
Ligne 735: | Ligne 739: | ||
sprintf(pool, | sprintf(pool, | ||
} | } | ||
- | Serial.print(F(" | + | Serial.print(F(" |
Serial.print(pool); | Serial.print(pool); | ||
configTime(0, | configTime(0, | ||
Ligne 744: | Ligne 748: | ||
int retry = 0; | int retry = 0; | ||
const int retry_count = 10; | const int retry_count = 10; | ||
- | delay(1000); | + | delay(2000); |
time(& | time(& | ||
localtime_r(& | localtime_r(& | ||
+ | Serial.print(F(" | ||
Serial.println(ctime(& | Serial.println(ctime(& | ||
+ | Serial.print(F(" | ||
+ | |||
while (!time(nullptr) && ++retry < retry_count) { | while (!time(nullptr) && ++retry < retry_count) { | ||
Serial.printf(" | Serial.printf(" | ||
Ligne 753: | Ligne 760: | ||
time(& | time(& | ||
localtime_r(& | localtime_r(& | ||
- | ntp_ok = true; | ||
Serial.println(ctime(& | Serial.println(ctime(& | ||
- | | + | |
} | } | ||
- | | + | |
} | } | ||
if (internet_connected >= 2) { | if (internet_connected >= 2) { | ||
Ligne 778: | Ligne 783: | ||
Serial.println(WiFi.localIP()); | Serial.println(WiFi.localIP()); | ||
if (!MDNS.begin(devname)) { | if (!MDNS.begin(devname)) { | ||
- | Serial.println(F(" | + | Serial.println(F(" |
} else { | } else { | ||
- | Serial.printf(" | + | Serial.printf(" |
} | } | ||
} | } | ||
Ligne 804: | Ligne 809: | ||
sdmmc_card_t *card; | sdmmc_card_t *card; | ||
- | Serial.println(F(" | + | |
ret = esp_vfs_fat_sdmmc_mount("/ | ret = esp_vfs_fat_sdmmc_mount("/ | ||
if (ret == ESP_OK) { | if (ret == ESP_OK) { | ||
- | Serial.println(F(" | + | Serial.println(F(" |
} else { | } else { | ||
- | Serial.printf(" | + | Serial.printf(" |
major_fail(); | major_fail(); | ||
return false; | return false; | ||
Ligne 826: | Ligne 831: | ||
File root = fs.open(dirname); | File root = fs.open(dirname); | ||
if (!root) { | if (!root) { | ||
- | Serial.println(F(" | + | Serial.println(F(" |
return; | return; | ||
} | } | ||
if (!root.isDirectory()) { | if (!root.isDirectory()) { | ||
- | Serial.println(F(" | + | Serial.println(F(" |
return; | return; | ||
} | } | ||
Ligne 893: | Ligne 898: | ||
digitalWrite(33, | digitalWrite(33, | ||
end_avi(); | end_avi(); | ||
- | Serial.println(F(" | + | Serial.println(F(" |
frames_so_far = total_frames; | frames_so_far = total_frames; | ||
newfile = 0; // file is closed | newfile = 0; // file is closed | ||
Ligne 901: | Ligne 906: | ||
if (newfile == 1 && recording == 1) { // regular recording | if (newfile == 1 && recording == 1) { // regular recording | ||
if (frames_so_far >= total_frames) | if (frames_so_far >= total_frames) | ||
- | Serial.println(F(" | + | Serial.println(F(" |
digitalWrite(33, | digitalWrite(33, | ||
end_avi(); | end_avi(); | ||
Ligne 978: | Ligne 983: | ||
cam_err = esp_camera_init(& | cam_err = esp_camera_init(& | ||
if (cam_err != ESP_OK) { | if (cam_err != ESP_OK) { | ||
- | Serial.printf(" | + | Serial.printf(" |
major_fail(); | major_fail(); | ||
} | } | ||
Ligne 1001: | Ligne 1006: | ||
File ficnofic = fs.open(nomfic, | File ficnofic = fs.open(nomfic, | ||
if (!ficnofic) { | if (!ficnofic) { | ||
- | Serial.println(F(" | + | Serial.println(F(" |
} | } | ||
DynamicJsonDocument json(32); | DynamicJsonDocument json(32); | ||
Ligne 1010: | Ligne 1015: | ||
File ficnofic = fs.open(nomfic, | File ficnofic = fs.open(nomfic, | ||
if (!ficnofic) { | if (!ficnofic) { | ||
- | Serial.println(F(" | + | Serial.println(F(" |
} | } | ||
DynamicJsonDocument json(32); | DynamicJsonDocument json(32); | ||
DeserializationError error = deserializeJson(json, | DeserializationError error = deserializeJson(json, | ||
if (error) { | if (error) { | ||
- | Serial.println(F(" | + | Serial.println(F(" |
ficnofic.println(); | ficnofic.println(); | ||
return (numero_fichier); | return (numero_fichier); | ||
Ligne 1027: | Ligne 1032: | ||
static esp_err_t start_avi() { | static esp_err_t start_avi() { | ||
- | Serial.println(" | + | Serial.println(F(" |
config_camera(); | config_camera(); | ||
- | if ( ntp_ok == true) { | + | if ( (int)timeinfo.tm_year > 110 ) { |
time(& | time(& | ||
localtime_r(& | localtime_r(& | ||
Ligne 1061: | Ligne 1066: | ||
// | // | ||
} else { | } else { | ||
- | Serial.println(" | + | Serial.println(" |
major_fail(); | major_fail(); | ||
} | } | ||
Ligne 1067: | Ligne 1072: | ||
// | // | ||
} else { | } else { | ||
- | Serial.println(" | + | Serial.println(F("err open file")); |
major_fail(); | major_fail(); | ||
} | } | ||
Ligne 1171: | Ligne 1176: | ||
size_t err = fwrite(fb_q[fb_out]-> | size_t err = fwrite(fb_q[fb_out]-> | ||
if (err == 0 ) { | if (err == 0 ) { | ||
- | Serial.println(" | + | Serial.println(F("Err avi write")); |
major_fail(); | major_fail(); | ||
} | } | ||
Ligne 1220: | Ligne 1225: | ||
// | // | ||
current_end = ftell (avifile); | current_end = ftell (avifile); | ||
- | Serial.println(F(" | + | Serial.println(F(" |
elapsedms = millis() - startms; | elapsedms = millis() - startms; | ||
float fRealFPS = (1000.0f * (float)frame_cnt) / ((float)elapsedms) * xspeed; | float fRealFPS = (1000.0f * (float)frame_cnt) / ((float)elapsedms) * xspeed; | ||
Ligne 1250: | Ligne 1255: | ||
print_quartet(movi_size + frame_cnt * 8 + 4, avifile); | print_quartet(movi_size + frame_cnt * 8 + 4, avifile); | ||
- | Serial.println(F(" | + | Serial.println(F(" |
Serial.print(F(" | Serial.print(F(" | ||
Serial.print(elapsedms / 1000); | Serial.print(elapsedms / 1000); | ||
Ligne 1284: | Ligne 1289: | ||
} else { | } else { | ||
- | Serial.println(F(" | + | Serial.println(F(" |
// | // | ||
} | } | ||
Ligne 1306: | Ligne 1311: | ||
// incremente le numero_fichier | // incremente le numero_fichier | ||
- | if ( ntp_ok == false) { | + | if ( (int)timeinfo.tm_year < 110) { |
numero_fichier++; | numero_fichier++; | ||
nofichiersave(SD_MMC, | nofichiersave(SD_MMC, | ||
Ligne 1395: | Ligne 1400: | ||
Serial.printf(" | Serial.printf(" | ||
} else { | } else { | ||
- | Serial.println(F(" | + | Serial.println(F(" |
} | } | ||
fclose(file); | fclose(file); | ||
Ligne 1443: | Ligne 1448: | ||
Serial.printf(" | Serial.printf(" | ||
} else { | } else { | ||
- | Serial.println(F(" | + | Serial.println(F(" |
} | } | ||
fclose(file); | fclose(file); | ||
Ligne 1497: | Ligne 1502: | ||
} else { | } else { | ||
//recording = 1; | //recording = 1; | ||
- | Serial.println(F(" | + | Serial.println(F(" |
sensor_t * s = esp_camera_sensor_get(); | sensor_t * s = esp_camera_sensor_get(); | ||
Ligne 1656: | Ligne 1661: | ||
Gray = 1 ou 0<br> | Gray = 1 ou 0<br> | ||
- | Fichier sur la microSD / | + | |
- | ex: {" | + | |
< | < | ||
< | < | ||
+ | Fichier sur la microSD /config.jsn <br> | ||
+ | %s | ||
</ | </ | ||
</ | </ | ||
+ | //ex: {" | ||
- | sprintf(the_page, | + | sprintf(the_page, |
Serial.println(the_page); | Serial.println(the_page); | ||
} | } | ||
Ligne 1673: | Ligne 1680: | ||
recording = 0; | recording = 0; | ||
- | Serial.println(F(" | + | Serial.println(F(" |
do_stop(" | do_stop(" | ||
Ligne 1715: | Ligne 1722: | ||
< | < | ||
- | Fichier sur la microSD / | + | Fichier sur la microSD / |
cf list< | cf list< | ||
LED flash sur une frame, SOS flash si pas de microSD< | LED flash sur une frame, SOS flash si pas de microSD< | ||
Ligne 1749: | Ligne 1756: | ||
File root = fs.open(dirname); | File root = fs.open(dirname); | ||
if (!root) { | if (!root) { | ||
- | Serial.println(F(" | + | Serial.println(F(" |
return; | return; | ||
} | } | ||
if (!root.isDirectory()) { | if (!root.isDirectory()) { | ||
- | Serial.println(F(" | + | Serial.println(F(" |
return; | return; | ||
} | } | ||
Ligne 1759: | Ligne 1766: | ||
while (file) { | while (file) { | ||
+ | delay(100); | ||
if (file.isDirectory()) { | if (file.isDirectory()) { | ||
output += "< | output += "< | ||
Ligne 1768: | Ligne 1776: | ||
output += "</ | output += "</ | ||
output += " | output += " | ||
- | Serial.println((String)file.name()); | + | |
if (levels) { | if (levels) { | ||
listDir(fs, file.name(), | listDir(fs, file.name(), | ||
Ligne 1783: | Ligne 1790: | ||
output += " | output += " | ||
output += file.size(); | output += file.size(); | ||
- | Serial.println((String)file.name()); | + | |
} | } | ||
file = root.openNextFile(); | file = root.openNextFile(); | ||
Ligne 1797: | Ligne 1803: | ||
output += "</ | output += "</ | ||
server.send(200, | server.send(200, | ||
- | Serial.println(F(" | + | |
return; | return; | ||
} | } | ||
Ligne 1803: | Ligne 1809: | ||
bool listDir_handler() { | bool listDir_handler() { | ||
listDir(SD_MMC, | listDir(SD_MMC, | ||
- | Serial.println(F(" | + | |
return true; | return true; | ||
Ligne 1887: | Ligne 1893: | ||
bool saveSPIFFSConfigFile(void) | bool saveSPIFFSConfigFile(void) | ||
{ | { | ||
- | Serial.println(F(" | + | Serial.println(F(" |
recording = 0; | recording = 0; | ||
DynamicJsonDocument json(512); | DynamicJsonDocument json(512); | ||
Ligne 1896: | Ligne 1902: | ||
json[" | json[" | ||
json[" | json[" | ||
- | json["total_frames" | + | json["length" |
json[" | json[" | ||
json[" | json[" | ||
Ligne 1962: | Ligne 1968: | ||
Serial.println(F(" | Serial.println(F(" | ||
} | } | ||
+ | </ |