Ci-dessous, les différences entre deux révisions de la page.
Prochaine révision | Révision précédenteProchaine révisionLes deux révisions suivantes | ||
projets:esp32-cam_timelaps_code [2020/05/31 15:15] – créée gepeto | projets:esp32-cam_timelaps_code [2020/06/03 14:49] – gepeto | ||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
- | < | ||
/* | /* | ||
ESP32-CAM l'oeil clignotemps | ESP32-CAM l'oeil clignotemps | ||
Ligne 49: | Ligne 48: | ||
// 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[] = "v9cGepeto"; // modif AccesPoint and http filesystem |
// plage horaire | // plage horaire | ||
#include < | #include < | ||
Ligne 72: | Ligne 71: | ||
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 " | ||
Ligne 231: | Ligne 229: | ||
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 280: | ||
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; | ||
+ | } | ||
Serial.println(F(" | Serial.println(F(" | ||
int heure = 0 ; | int heure = 0 ; | ||
Ligne 304: | Ligne 306: | ||
} | } | ||
} | } | ||
- | strftime(strftime_buf, | + | |
int reste = 58 - (int)timeinfo.tm_min; | int reste = 58 - (int)timeinfo.tm_min; | ||
if (reste > 3 && heure < 90) { | if (reste > 3 && heure < 90) { | ||
Ligne 358: | Ligne 360: | ||
fclose(configSD); | fclose(configSD); | ||
} | } | ||
+ | |||
bool loadSPIFFSConfigFile(void) | bool loadSPIFFSConfigFile(void) | ||
{ | { | ||
Ligne 640: | Ligne 643: | ||
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 733: | Ligne 705: | ||
WiFi.mode(WIFI_STA); | WiFi.mode(WIFI_STA); | ||
WiFi.setHostname(devname); | WiFi.setHostname(devname); | ||
- | // | ||
- | |||
WiFi.begin(ssid, | WiFi.begin(ssid, | ||
delay(1000); | delay(1000); | ||
while (WiFi.status() != WL_CONNECTED ) { | while (WiFi.status() != WL_CONNECTED ) { | ||
- | delay(500); | + | delay(1000); |
Serial.print(F(" | Serial.print(F(" | ||
if (connAttempts == 10) { | if (connAttempts == 10) { | ||
- | Serial.println(F(" | + | Serial.println(F(" |
WiFi.begin(" | WiFi.begin(" | ||
- | WiFi.printDiag(Serial); | + | |
- | internet_connected = 2; | + | if (WiFi.SSID() == (String)" |
+ | | ||
+ | internet_connected = 2; | ||
+ | } | ||
delay(1000); | delay(1000); | ||
- | } else if (connAttempts > 11) { // AP | + | } else if (connAttempts > 13) { // laisse tomber, passage |
- | | + | |
+ | ntp_ok = false; | ||
} | } | ||
connAttempts++; | connAttempts++; | ||
} | } | ||
if (internet_connected == 0) internet_connected = 1; | if (internet_connected == 0) internet_connected = 1; | ||
- | Serial.println(F(" | + | |
- | WiFi.printDiag(Serial); | + | |
- | char pool[] = "pool.ntp.org"; | + | |
- | if ( internet_connected == 2) sprintf(pool, | + | char pool[16] = ""; |
- | configTime(0, | + | if ( internet_connected == 2) { |
- | setenv(" | + | |
- | tzset(); | + | } else { |
- | + | sprintf(pool, | |
- | | + | } |
- | timeinfo = { 0 }; | + | Serial.print(F(" |
- | int retry = 0; | + | Serial.print(pool); |
- | const int retry_count = 10; | + | |
- | delay(1000); | + | setenv(" |
- | time(& | + | tzset(); |
- | localtime_r(& | + | time_t now ; |
- | while (timeinfo.tm_year < (2016 - 1900) && ++retry < retry_count) { | + | timeinfo = { 0 }; |
- | Serial.printf(" | + | int retry = 0; |
+ | const int retry_count = 10; | ||
delay(1000); | delay(1000); | ||
time(& | time(& | ||
localtime_r(& | localtime_r(& | ||
- | ntp_ok = true; | + | |
- | } | + | while (!time(nullptr) && ++retry < retry_count) { |
+ | Serial.printf(" | ||
+ | delay(1000); | ||
+ | time(& | ||
+ | localtime_r(& | ||
+ | | ||
+ | | ||
+ | sprintf(localip, | ||
+ | | ||
+ | ntp_ok = true; // on force | ||
- | Serial.println(ctime(&now)); | + | |
- | | + | if (internet_connected >= 2) { |
- | | + | |
- | | + | |
+ | | ||
+ | WiFi.mode(WIFI_AP); | ||
+ | delay(1000); | ||
+ | WiFi.softAP(ssid_ap, pass_ap, canal_wifi, invisible, max_connexion); | ||
+ | delay(1000); | ||
+ | Serial.print(F(" | ||
+ | Serial.print(ssid_ap); | ||
+ | Serial.print(F(" ")); | ||
+ | | ||
+ | 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 997: | Ligne 998: | ||
} | } | ||
} | } | ||
+ | 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 1011: | Ligne 1034: | ||
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 1294: | Ligne 1307: | ||
// incremente le numero_fichier | // incremente le numero_fichier | ||
if ( ntp_ok == false) { | if ( ntp_ok == false) { | ||
- | | + | |
- | | + | |
- | Serial.printf(" | + | |
- | | + | |
- | numero_fichier++; | + | |
- | } else { | + | |
- | numero_fichier = 1; | + | |
- | } | + | |
- | Serial.printf("numero_fichier | + | |
- | size_t dc_err = fwrite(& | + | |
- | fclose(nofile); | + | |
- | } else { | + | |
- | Serial.printf(" | + | |
- | } | + | |
} | } | ||
} | } | ||
Ligne 1355: | Ligne 1357: | ||
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 1834: | Ligne 1808: | ||
} | } | ||
/// | /// | ||
- | /// SDCARD | + | /// SDCARD |
/// | /// | ||
bool loadFromSdCard(fs:: | bool loadFromSdCard(fs:: | ||
Ligne 1974: | Ligne 1948: | ||
//// | //// | ||
void startCameraServer() { | void startCameraServer() { | ||
- | | + | |
// | // | ||
server.on("/ | server.on("/ | ||
Ligne 1988: | Ligne 1962: | ||
Serial.println(F(" | Serial.println(F(" | ||
} | } | ||
- | </ |