Outils pour utilisateurs

Outils du site


projets:esp32-cam_timelaps_code

Différences

Ci-dessous, les différences entre deux révisions de la page.

Lien vers cette vue comparative

Prochaine révision
Révision précédente
Prochaine révisionLes deux révisions suivantes
projets:esp32-cam_timelaps_code [2020/05/31 15:15] – créée gepetoprojets:esp32-cam_timelaps_code [2020/06/03 14:49] gepeto
Ligne 1: Ligne 1:
-<code> 
 /* /*
   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 <dummy.h> #include <dummy.h>
Ligne 72: Ligne 71:
 char horaire[80]  = {0};// heures d'enregistrement char horaire[80]  = {0};// heures d'enregistrement
 char conf_horaire[]  = "6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21";// heures d'enregistrement char conf_horaire[]  = "6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21";// heures d'enregistrement
-#define TIMEZONE "GMT0BST,M3.5.0/01,M10.5.0/02            // your timezone   this is GMT +#define TIMEZONE "CET-1CEST-2,M3.5.0/02:00:00,M10.5.0/03:00:00" // de https://remotemonitoringsystems.ca/time-zone-abbreviations.php
 // startup defaults for first recordin // startup defaults for first recordin
 // here are the recording options from the "retart web page" // here are the recording options from the "retart web page"
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("test horaire"));   Serial.println(F("test horaire"));
   int heure = 0 ;   int heure = 0 ;
Ligne 304: Ligne 306:
       }       }
     }     }
-    strftime(strftime_buf, sizeof(strftime_buf), "%M", &timeinfo);+    //strftime(strftime_buf, sizeof(strftime_buf), "%M", &timeinfo);
     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);    // little red led on back of chip   pinMode(33, OUTPUT);    // little red led on back of chip
   digitalWrite(33, LOW);           // turn on the red LED on the back of chip   digitalWrite(33, LOW);           // turn on the red LED on the back of chip
-  init_wifi(); 
-  if (internet_connected == 2) { 
-    Serial.print(F("Passage en Point d acces...")); 
-    WiFi.disconnect(); 
-    delay(500); 
-    WiFi.mode(WIFI_AP); 
-    delay(500); 
-    WiFi.softAP(ssid_ap, pass_ap, canal_wifi, invisible, max_connexion); 
-    delay(1000); 
-    Serial.print(F("ouverture paswd de ")); 
-    Serial.print(ssid_ap); 
-    Serial.print(F(" ")); 
-    Serial.println(pass_ap); 
-    internet_connected = 3; 
-    delay(1000); 
-    Serial.print(F("AP IP ")); 
-    Serial.println(WiFi.softAPIP()); 
-  } 
-  if (internet_connected < 3) { 
-    sprintf(localip, "%s", WiFi.localIP().toString().c_str()); 
-    Serial.println("mDNS"); 
-    //uint64_t chipid = ESP.getEfuseMac(); 
-    //char mdnsname[12] = {0}; 
-    //sprintf(mdnsname, "ESPCAM-%04X", (uint16_t)(chipid >> 32)); 
-    if (!MDNS.begin(devname)) { 
-      Serial.println("Error setting up MDNS responder!"); 
-    } else { 
-      Serial.printf("mDNS responder started '%s'\n", devname); 
-    } 
-  }  else { 
-    sprintf(localip, "%s", WiFi.softAPIP().toString().c_str()); 
-  } 
   if (!psramFound()) {   if (!psramFound()) {
     Serial.println("paraFound wrong - major fail");     Serial.println("paraFound wrong - major fail");
     //major_fail();     //major_fail();
   }   }
 +  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.printDiag(Serial); 
- 
   WiFi.begin(ssid, pass);   WiFi.begin(ssid, pass);
   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("tentative FreeWifi"));+      Serial.println(F("tentative FreeWifi")); // juste pour ntp
       WiFi.begin("FreeWifi");       WiFi.begin("FreeWifi");
-      WiFi.printDiag(Serial); +      delay(2000); 
-      internet_connected = 2;+      if (WiFi.SSID() == (String)"FreeWifi") { 
 +        Serial.println(F("oui")); 
 +        internet_connected = 2; 
 +      }
       delay(1000);       delay(1000);
-    } else if (connAttempts > 11) { // AP +    } else if (connAttempts > 13) { // laisse tomber, passage AP 
-      return (false);+      internet_connected = 3; 
 +      ntp_ok = false;
     }     }
     connAttempts++;     connAttempts++;
   }   }
   if (internet_connected == 0) internet_connected = 1;   if (internet_connected == 0) internet_connected = 1;
-  Serial.println(F("Internet connected")); +  if (internet_connected < 3) { 
-  WiFi.printDiag(Serial); +    Serial.println(WiFi.SSID()); 
-  char pool[] = "pool.ntp.org"; +    Serial.println(internet_connected); 
-  if ( internet_connected == 2) sprintf(pool, "%s", WiFi.gatewayIP().toString().c_str()); +    char pool[16] = ""; 
-  configTime(0, 0, pool); +    if ( internet_connected == 2) 
-  setenv("TZ", TIMEZONE, 1);  // mountain time zone from #define at top +      sprintf(pool, "%s", WiFi.gatewayIP().toString().c_str()); 
-  tzset(); +    } else { 
- +      sprintf(pool, "pool.ntp.org"); 
-  time_t now ; +    } 
-  timeinfo = { 0 }; +    Serial.print(F("Waiting for system time to be set ")); 
-  int retry = 0; +    Serial.print(pool); 
-  const int retry_count = 10+    configTime(0, 0, pool); 
-  delay(1000); +    setenv("TZ", TIMEZONE, 1);  // Paris time zone from #define at top 
-  time(&now); +    tzset(); 
-  localtime_r(&now, &timeinfo); +    time_t now ; 
-  while (timeinfo.tm_year < (2016 - 1900) && ++retry < retry_count) { +    timeinfo = { 0 }; 
-    Serial.printf("Waiting for system time to be set... (%d/%d) -- %d\n", retry, retry_count, timeinfo.tm_year);+    int retry = 0; 
 +    const int retry_count = 10;
     delay(1000);     delay(1000);
     time(&now);     time(&now);
     localtime_r(&now, &timeinfo);     localtime_r(&now, &timeinfo);
-    ntp_ok = true; +    Serial.println(ctime(&now)); 
-  }+    while (!time(nullptr) && ++retry < retry_count) { 
 +      Serial.printf("... (%d/%d) -- %d\n", retry, retry_count, timeinfo.tm_year); 
 +      delay(1000); 
 +      time(&now); 
 +      localtime_r(&now, &timeinfo); 
 +      ntp_ok = true; 
 +      Serial.println(ctime(&now)); 
 +      sprintf(localip, "%s", WiFi.localIP().toString().c_str()); 
 +    } 
 +    ntp_ok = true; // on force
  
-  Serial.println(ctime(&now)); +  
-  if (internet_connected < 3{ +  if (internet_connected >= 2) { 
-    sprintf(localip"%s"WiFi.localIP().toString().c_str()); +    Serial.print(F("\nPassage en Point d acces...")); 
-   else {+    WiFi.disconnect(); 
 +    delay(500); 
 +    WiFi.mode(WIFI_AP); 
 +    delay(1000); 
 +    WiFi.softAP(ssid_appass_apcanal_wifi, invisible, max_connexion); 
 +    delay(1000); 
 +    Serial.print(F("ouverture paswd de ")); 
 +    Serial.print(ssid_ap)
 +    Serial.print(F(" ")); 
 +    Serial.println(pass_ap); 
 +    internet_connected = 3; 
 +    delay(1000);
     sprintf(localip, "%s", WiFi.softAPIP().toString().c_str());     sprintf(localip, "%s", WiFi.softAPIP().toString().c_str());
 +    Serial.println(WiFi.softAPIP());
 +    Serial.println(WiFi.localIP());
 +    if (!MDNS.begin(devname)) {
 +      Serial.println(F("Error setting up MDNS responder!"));
 +    } else {
 +      Serial.printf("mDNS responder started '%s'\n", devname);
 +    }
   }   }
-  ntp_ok = true; 
   Serial.println(localip);   Serial.println(localip);
   return true;   return true;
Ligne 997: Ligne 998:
   }   }
 } }
 +void nofichiersave(fs::FS & fs, const char * nomfic) { 
 +  File ficnofic = fs.open(nomfic, FILE_WRITE); 
 +  if (!ficnofic) { 
 +    Serial.println(F("Failed to open /nofic.jsn for writing")); 
 +  } 
 +  DynamicJsonDocument json(32); 
 +  json["nofichier" = numero_fichier; 
 +  serializeJson(json, ficnofic); 
 +
 +int nofichierread(fs::FS & fs, const char * nomfic) { 
 +  File ficnofic = fs.open(nomfic, FILE_READ); 
 +  if (!ficnofic) { 
 +    Serial.println(F("Failed to open /nofic.jsn for reading")); 
 +  } 
 +  DynamicJsonDocument json(32); 
 +  DeserializationError error = deserializeJson(json, ficnofic); 
 +  if (error) { 
 +    Serial.println(F("err lecture json /nofic.jon")); 
 +    ficnofic.println(); 
 +    return (numero_fichier); 
 +  } 
 +  numero_fichier = json["nofichier"]; 
 +}
 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 // //
Ligne 1011: Ligne 1034:
     strftime(strftime_buf, sizeof(strftime_buf), "%F_%H.%M.%S", &timeinfo);     strftime(strftime_buf, sizeof(strftime_buf), "%F_%H.%M.%S", &timeinfo);
   } else {   } else {
-    nofile = fopen("/sdcard/nofile.txt", "w"); +    nofichierread(SD_MMC, "/nofic.jsn");
-    if (nofile != NULL)  { +
-      Serial.printf("File open: %s\n", "/sdcard/nofile.txt"); +
-      if (fread(&numero_fichier, sizeof(int), 1, nofile) != 1) { +
-        numero_fichier++; +
-      } else { +
-        numero_fichier = 1; +
-      } +
-    } else  { +
-      //sprintf(nofile, "%d", numero_fichier); // init a 1 +
-      size_t dc_err = fwrite(&numero_fichier, sizeof(int), 1, nofile); +
-    }+
     sprintf(strftime_buf, "%d", numero_fichier);     sprintf(strftime_buf, "%d", numero_fichier);
   }   }
 +
   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) {
-    nofile = fopen("/sdcard/nofile.txt", "w")+    numero_fichier++
-    if (nofile != NULL)  { +    nofichiersave(SD_MMC, "/nofic.jsn"); 
-      Serial.printf("File open: %s\n", "/sdcard/nofile.txt"); +    sprintf(strftime_buf, "%d", numero_fichier);
-      if (fread(&numero_fichiersizeof(int), 1, nofile) != 1) { +
-        numero_fichier++; +
-      } else { +
-        numero_fichier = 1; +
-      } +
-      Serial.printf("numero_fichier %d\n", numero_fichier ); +
-      size_t dc_err = fwrite(&numero_fichier, sizeof(int), 1, nofile); +
-      fclose(nofile); +
-    } else  { +
-      Serial.printf("pb ecriture numero_fichier %d\n", numero_fichier ); +
-    }+
   }   }
 } }
Ligne 1355: Ligne 1357:
       init_wifi();       init_wifi();
     }     }
-    if (internet_connected == 2) { 
-      Serial.print(F("Passage en Point d acces...")); 
-      WiFi.disconnect(); 
-      delay(500); 
-      WiFi.mode(WIFI_AP); 
-      delay(1000); 
-      WiFi.softAP(ssid_ap, pass_ap, canal_wifi, invisible, max_connexion); 
-      delay(1000); 
-      Serial.print(F("ouverture paswd de ")); 
-      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("Error setting up MDNS responder!")); 
-      } else { 
-        Serial.printf("mDNS responder started '%s'\n", devname); 
-      } 
-    } 
-    if (internet_connected < 3) { 
-      sprintf(localip, "%s", WiFi.localIP().toString().c_str()); 
-    } else { 
-      sprintf(localip, "%s", WiFi.softAPIP().toString().c_str()); 
-    } 
-    Serial.println(localip); 
   }   }
   Test_horaires();   Test_horaires();
Ligne 1834: Ligne 1808:
 } }
 /// ///
-/// SDCARD +/// SDCARD
 /// ///
 bool loadFromSdCard(fs::FS & fs, String path) { bool loadFromSdCard(fs::FS & fs, String path) {
Ligne 1974: Ligne 1948:
 //// ////
 void startCameraServer() { void startCameraServer() {
-  +
   //server.on("/", index_handler);   //server.on("/", index_handler);
   server.on("/capture",    capture_handler);   server.on("/capture",    capture_handler);
Ligne 1988: Ligne 1962:
   Serial.println(F("Camera http started"));   Serial.println(F("Camera http started"));
 } }
-</code> 
projets/esp32-cam_timelaps_code.txt · Dernière modification : 2024/02/09 16:56 de 127.0.0.1