Ci-dessous, les différences entre deux révisions de la page.
Prochaine révision | Révision précédente | ||
projets:esp32-cam_timelaps_code [2020/05/31 15:15] – créée gepeto | projets:esp32-cam_timelaps_code [2024/02/09 16:56] (Version actuelle) – modification externe 127.0.0.1 | ||
---|---|---|---|
Ligne 35: | Ligne 35: | ||
" | " | ||
" | " | ||
- | " | + | " |
" | " | ||
" | " | ||
Ligne 49: | Ligne 49: | ||
// edit these parameters for your needs | // edit these parameters for your needs | ||
- | static const char vernum[] = "v9Gepeto"; // modif AccesPoint and http filesystem | + | static const char vernum[] = "v10Gepeto"; // modif AccesPoint and http filesystem |
// plage horaire | // plage horaire | ||
#include < | #include < | ||
Ligne 72: | Ligne 72: | ||
char horaire[80] | char horaire[80] | ||
char conf_horaire[] | char conf_horaire[] | ||
- | #define TIMEZONE "GMT0BST,M3.5.0/01,M10.5.0/02" | + | #define TIMEZONE "CET-1CEST-2,M3.5.0/02:00:00,M10.5.0/03:00:00" // de https:// |
// 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 154: | 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 231: | Ligne 230: | ||
FILE *nofile = NULL; | FILE *nofile = NULL; | ||
FILE *configSD = NULL; | FILE *configSD = NULL; | ||
+ | FILE *ficnofic = NULL; | ||
#define AVIOFFSET 240 // AVI main header length | #define AVIOFFSET 240 // AVI main header length | ||
Ligne 281: | Ligne 281: | ||
void Test_horaires() { // cherche si heure maintenant contenue dans horaires | void Test_horaires() { // cherche si heure maintenant contenue dans horaires | ||
- | Serial.println(F(" | + | |
- | int heure = 0 ; | + | if ( timeinfo.tm_year < 110) { // date year deouis 1900 |
- | int taille_plages = strlen(horaire); | + | return; |
- | if (taille_plages > 3 ) { | + | } else { |
- | char buf[3] = " | + | |
- | for (int i = 0; i < taille_plages; | + | int heure = 0 ; |
- | buf[0] = horaire[i++]; | + | int taille_plages = strlen(horaire); |
- | if (horaire[i] != ',' | + | if (taille_plages > 3 ) { |
- | else buf[1] = ' | + | char buf[3] = " |
- | buf[2] = ' | + | for (int i = 0; i < taille_plages; |
- | heure = atoi(buf); | + | buf[0] = horaire[i++]; |
- | time(& | + | if (horaire[i] != ',' |
- | localtime_r(& | + | else buf[1] = ' |
- | // | + | buf[2] = ' |
- | | + | heure = atoi(buf); |
- | // | + | time(& |
- | if ((int)timeinfo.tm_hour | + | localtime_r(& |
- | // | + | // |
- | // | + | // |
- | heure = 99; | + | if ((int)timeinfo.tm_hour |
- | break; | + | // |
+ | // | ||
+ | heure = 99; | ||
+ | break; | ||
+ | } | ||
} | } | ||
- | } | + | |
- | strftime(strftime_buf, | + | if (reste > 3 && heure < 90) { |
- | | + | //end_avi(); |
- | if (reste > 3 && heure < 90) { | + | Serial.print(F(" |
- | end_avi(); | + | Serial.println(reste); |
- | Serial.print(F(" | + | esp_sleep_enable_timer_wakeup(1000000 * 60 * (uint64_t)reste); |
- | Serial.println(reste); | + | esp_deep_sleep_start(); |
- | esp_sleep_enable_timer_wakeup(1000000 * 60 * (uint64_t)reste); | + | delay(1000); |
- | esp_deep_sleep_start(); | + | } |
- | delay(1000); | + | } else Serial.println(F(" |
- | } | + | } |
- | } else Serial.println(F(" | + | |
} | } | ||
/// | /// | ||
Ligne 349: | Ligne 352: | ||
json[" | json[" | ||
json[" | json[" | ||
- | json["total_frames" | + | json["length" |
json[" | json[" | ||
json[" | json[" | ||
Ligne 358: | Ligne 361: | ||
fclose(configSD); | fclose(configSD); | ||
} | } | ||
+ | |||
bool loadSPIFFSConfigFile(void) | bool loadSPIFFSConfigFile(void) | ||
{ | { | ||
Ligne 367: | 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 408: | 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 424: | Ligne 428: | ||
configFile.close(); | configFile.close(); | ||
Serial.println(F(" | Serial.println(F(" | ||
+ | total_frames = xlength * 1000 / capture_interval; | ||
} | } | ||
Ligne 562: | Ligne 567: | ||
skipping = 0; | skipping = 0; | ||
Serial.println(" | Serial.println(" | ||
+ | delay(100); | ||
} | } | ||
Ligne 630: | 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); | ||
digitalWrite(33, | digitalWrite(33, | ||
- | init_wifi(); | ||
- | if (internet_connected == 2) { | ||
- | Serial.print(F(" | ||
- | WiFi.disconnect(); | ||
- | delay(500); | ||
- | WiFi.mode(WIFI_AP); | ||
- | delay(500); | ||
- | WiFi.softAP(ssid_ap, | ||
- | delay(1000); | ||
- | Serial.print(F(" | ||
- | Serial.print(ssid_ap); | ||
- | Serial.print(F(" | ||
- | Serial.println(pass_ap); | ||
- | internet_connected = 3; | ||
- | delay(1000); | ||
- | Serial.print(F(" | ||
- | Serial.println(WiFi.softAPIP()); | ||
- | } | ||
- | if (internet_connected < 3) { | ||
- | sprintf(localip, | ||
- | Serial.println(" | ||
- | //uint64_t chipid = ESP.getEfuseMac(); | ||
- | //char mdnsname[12] = {0}; | ||
- | // | ||
- | if (!MDNS.begin(devname)) { | ||
- | Serial.println(" | ||
- | } else { | ||
- | Serial.printf(" | ||
- | } | ||
- | } else { | ||
- | sprintf(localip, | ||
- | } | ||
if (!psramFound()) { | if (!psramFound()) { | ||
Serial.println(" | Serial.println(" | ||
// | // | ||
} | } | ||
+ | init_wifi(); | ||
Test_horaires(); | Test_horaires(); | ||
startCameraServer(); | startCameraServer(); | ||
Ligne 730: | Ligne 704: | ||
bool init_wifi() | bool init_wifi() | ||
{ | { | ||
- | WiFi.disconnect(true); | + | |
- | WiFi.mode(WIFI_STA); | + | |
- | WiFi.setHostname(devname); | + | WiFi.mode(WIFI_STA); |
- | // | + | WiFi.setHostname(devname); |
- | + | WiFi.begin(ssid, | |
- | | + | delay(1000); |
- | delay(1000); | + | while (WiFi.status() != WL_CONNECTED ) { |
- | while (WiFi.status() != WL_CONNECTED ) { | + | |
- | delay(500); | + | |
- | Serial.print(F(" | + | |
- | if (connAttempts == 10) { | + | |
- | Serial.println(F(" | + | |
- | WiFi.begin(" | + | |
- | WiFi.printDiag(Serial); | + | |
- | internet_connected = 2; | + | |
delay(1000); | delay(1000); | ||
- | | + | Serial.print(F(" |
- | | + | 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; | ||
- | Serial.println(F(" | + | |
- | | + | |
- | char pool[] = "pool.ntp.org"; | + | char pool[16] = ""; |
- | if ( internet_connected == 2) sprintf(pool, | + | if ( internet_connected == 2) { |
- | configTime(0, | + | |
- | setenv(" | + | } else { |
- | tzset(); | + | sprintf(pool, |
- | + | } | |
- | | + | Serial.print(F(" |
- | timeinfo = { 0 }; | + | Serial.print(pool); |
- | int retry = 0; | + | |
- | const int retry_count = 10; | + | setenv(" |
- | delay(1000); | + | tzset(); |
- | time(& | + | time_t now ; |
- | localtime_r(& | + | timeinfo = { 0 }; |
- | while (timeinfo.tm_year < (2016 - 1900) && ++retry < retry_count) { | + | int retry = 0; |
- | Serial.printf(" | + | const int retry_count = 10; |
- | delay(1000); | + | delay(2000); |
time(& | time(& | ||
localtime_r(& | localtime_r(& | ||
- | | + | |
- | } | + | |
+ | Serial.print(F(" | ||
- | | + | while (!time(nullptr) && ++retry < retry_count) { |
- | | + | Serial.printf(" |
+ | delay(1000); | ||
+ | time(& | ||
+ | localtime_r(& | ||
+ | | ||
+ | | ||
+ | } | ||
sprintf(localip, | sprintf(localip, | ||
- | } | + | } |
+ | if (internet_connected >= 2) { | ||
+ | Serial.print(F(" | ||
+ | WiFi.disconnect(); | ||
+ | delay(500); | ||
+ | WiFi.mode(WIFI_AP); | ||
+ | delay(1000); | ||
+ | WiFi.softAP(ssid_ap, | ||
+ | delay(1000); | ||
+ | Serial.print(F(" | ||
+ | Serial.print(ssid_ap); | ||
+ | Serial.print(F(" | ||
+ | Serial.println(pass_ap); | ||
+ | internet_connected = 3; | ||
+ | delay(1000); | ||
sprintf(localip, | sprintf(localip, | ||
+ | Serial.println(WiFi.softAPIP()); | ||
+ | Serial.println(WiFi.localIP()); | ||
+ | if (!MDNS.begin(devname)) { | ||
+ | Serial.println(F(" | ||
+ | } else { | ||
+ | Serial.printf(" | ||
+ | } | ||
} | } | ||
- | ntp_ok = true; | ||
Serial.println(localip); | Serial.println(localip); | ||
return true; | return true; | ||
Ligne 803: | 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 825: | 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 892: | 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 900: | 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 977: | 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 997: | Ligne 1003: | ||
} | } | ||
} | } | ||
+ | void nofichiersave(fs:: | ||
+ | File ficnofic = fs.open(nomfic, | ||
+ | if (!ficnofic) { | ||
+ | Serial.println(F(" | ||
+ | } | ||
+ | DynamicJsonDocument json(32); | ||
+ | json[" | ||
+ | serializeJson(json, | ||
+ | } | ||
+ | int nofichierread(fs:: | ||
+ | File ficnofic = fs.open(nomfic, | ||
+ | if (!ficnofic) { | ||
+ | Serial.println(F(" | ||
+ | } | ||
+ | DynamicJsonDocument json(32); | ||
+ | DeserializationError error = deserializeJson(json, | ||
+ | if (error) { | ||
+ | Serial.println(F(" | ||
+ | ficnofic.println(); | ||
+ | return (numero_fichier); | ||
+ | } | ||
+ | numero_fichier = json[" | ||
+ | } | ||
// | // | ||
// | // | ||
Ligne 1004: | 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(& | ||
strftime(strftime_buf, | strftime(strftime_buf, | ||
} else { | } else { | ||
- | | + | |
- | if (nofile != NULL) { | + | |
- | Serial.printf(" | + | |
- | if (fread(& | + | |
- | numero_fichier++; | + | |
- | } else { | + | |
- | numero_fichier = 1; | + | |
- | } | + | |
- | } else { | + | |
- | // | + | |
- | size_t dc_err = fwrite(& | + | |
- | } | + | |
sprintf(strftime_buf, | sprintf(strftime_buf, | ||
} | } | ||
+ | |||
char fname[100]; | char fname[100]; | ||
Ligne 1048: | Ligne 1066: | ||
// | // | ||
} else { | } else { | ||
- | Serial.println(" | + | Serial.println(" |
major_fail(); | major_fail(); | ||
} | } | ||
Ligne 1054: | Ligne 1072: | ||
// | // | ||
} else { | } else { | ||
- | Serial.println(" | + | Serial.println(F("err open file")); |
major_fail(); | major_fail(); | ||
} | } | ||
Ligne 1158: | 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 1207: | 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 1237: | 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 1271: | Ligne 1289: | ||
} else { | } else { | ||
- | Serial.println(F(" | + | Serial.println(F(" |
// | // | ||
} | } | ||
Ligne 1293: | Ligne 1311: | ||
// incremente le numero_fichier | // incremente le numero_fichier | ||
- | if ( ntp_ok == false) { | + | if ( (int)timeinfo.tm_year < 110) { |
- | nofile = fopen("/ | + | numero_fichier++; |
- | if (nofile != NULL) { | + | |
- | Serial.printf(" | + | |
- | if (fread(& | + | |
- | numero_fichier++; | + | |
- | } else { | + | |
- | numero_fichier = 1; | + | |
- | } | + | |
- | Serial.printf("numero_fichier %d\n", numero_fichier | + | |
- | | + | |
- | fclose(nofile); | + | |
- | } else { | + | |
- | Serial.printf("pb ecriture numero_fichier | + | |
- | } | + | |
} | } | ||
} | } | ||
Ligne 1355: | Ligne 1362: | ||
init_wifi(); | init_wifi(); | ||
} | } | ||
- | if (internet_connected == 2) { | ||
- | Serial.print(F(" | ||
- | WiFi.disconnect(); | ||
- | delay(500); | ||
- | WiFi.mode(WIFI_AP); | ||
- | delay(1000); | ||
- | WiFi.softAP(ssid_ap, | ||
- | delay(1000); | ||
- | Serial.print(F(" | ||
- | Serial.print(ssid_ap); | ||
- | Serial.print(F(" | ||
- | Serial.println(pass_ap); | ||
- | internet_connected = 3; | ||
- | delay(1000); | ||
- | Serial.println(WiFi.softAPIP()); | ||
- | Serial.println(WiFi.localIP()); | ||
- | if (!MDNS.begin(devname)) { | ||
- | Serial.println(F(" | ||
- | } else { | ||
- | Serial.printf(" | ||
- | } | ||
- | } | ||
- | if (internet_connected < 3) { | ||
- | sprintf(localip, | ||
- | } else { | ||
- | sprintf(localip, | ||
- | } | ||
- | Serial.println(localip); | ||
} | } | ||
Test_horaires(); | Test_horaires(); | ||
Ligne 1421: | Ligne 1400: | ||
Serial.printf(" | Serial.printf(" | ||
} else { | } else { | ||
- | Serial.println(F(" | + | Serial.println(F(" |
} | } | ||
fclose(file); | fclose(file); | ||
Ligne 1469: | Ligne 1448: | ||
Serial.printf(" | Serial.printf(" | ||
} else { | } else { | ||
- | Serial.println(F(" | + | Serial.println(F(" |
} | } | ||
fclose(file); | fclose(file); | ||
Ligne 1523: | 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 1682: | 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 1699: | Ligne 1680: | ||
recording = 0; | recording = 0; | ||
- | Serial.println(F(" | + | Serial.println(F(" |
do_stop(" | do_stop(" | ||
Ligne 1741: | 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 1775: | 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 1785: | Ligne 1766: | ||
while (file) { | while (file) { | ||
+ | delay(100); | ||
if (file.isDirectory()) { | if (file.isDirectory()) { | ||
output += "< | output += "< | ||
Ligne 1794: | Ligne 1776: | ||
output += "</ | output += "</ | ||
output += " | output += " | ||
- | Serial.println((String)file.name()); | + | |
if (levels) { | if (levels) { | ||
listDir(fs, file.name(), | listDir(fs, file.name(), | ||
Ligne 1809: | Ligne 1790: | ||
output += " | output += " | ||
output += file.size(); | output += file.size(); | ||
- | Serial.println((String)file.name()); | + | |
} | } | ||
file = root.openNextFile(); | file = root.openNextFile(); | ||
Ligne 1823: | Ligne 1803: | ||
output += "</ | output += "</ | ||
server.send(200, | server.send(200, | ||
- | Serial.println(F(" | + | |
return; | return; | ||
} | } | ||
Ligne 1829: | Ligne 1809: | ||
bool listDir_handler() { | bool listDir_handler() { | ||
listDir(SD_MMC, | listDir(SD_MMC, | ||
- | Serial.println(F(" | + | |
return true; | return true; | ||
} | } | ||
/// | /// | ||
- | /// SDCARD | + | /// SDCARD |
/// | /// | ||
bool loadFromSdCard(fs:: | bool loadFromSdCard(fs:: | ||
Ligne 1913: | 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 1922: | Ligne 1902: | ||
json[" | json[" | ||
json[" | json[" | ||
- | json["total_frames" | + | json["length" |
json[" | json[" | ||
json[" | json[" | ||
Ligne 1974: | Ligne 1954: | ||
//// | //// | ||
void startCameraServer() { | void startCameraServer() { | ||
- | | + | |
// | // | ||
server.on("/ | server.on("/ |