Kerminy HackerSpace

Outils du site


ressources:photo_ftp

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
ressources:photo_ftp [2023/08/30 11:47] – créée jeffressources:photo_ftp [2024/02/08 17:20] (Version actuelle) – modification externe 127.0.0.1
Ligne 1: Ligne 1:
 ====== ESPCAM ====== ====== ESPCAM ======
-un code qui fonctionne ( pas de pb de saturation...) pour prendre à intervalle régulier(frequence) une photo jpg et la poser par ftp sur le serveur.\ +un code qui fonctionne ( pas de pb de saturation...) pour prendre à intervalle régulier(frequence) une photo jpg et la poser par ftp sur le serveur. 
-un script place la photo sur le site web+ 
 +un script place la photo sur le site web en utilisant la  fonction watch (yum install inotify-tools) 
 <code c> <code c>
 #!/bin/bash #!/bin/bash
Ligne 7: Ligne 9:
 cd /var/lib/nethserver/ftp/espcam cd /var/lib/nethserver/ftp/espcam
 mkdir -p archives mkdir -p archives
 +mv *.jpg archives
 while watch -g -n 10 -d ls -l *.jpg 2>&1 >/dev/null while watch -g -n 10 -d ls -l *.jpg 2>&1 >/dev/null
 do do
Ligne 15: Ligne 18:
 exit 0 exit 0
 </code> </code>
 +avec un test horaire 
 +<code c> 
 +#!/bin/bash 
 +cd /var/lib/nethserver/ftp/espcam 
 +mkdir -p archives 
 +mv *.jpg archives 
 +while true 
 +        do 
 +        currenttime=$(date +%H:%M) 
 +        if [[ "$currenttime" < "21:00" ]] || [[ "$currenttime" < "07:30" ]]; then 
 +                while watch -g -n 10 -d ls -l *.jpg 2>&1 >/dev/null 
 +                do 
 +                        cp *.jpg /var/lib/nethserver/vhost/c36066d722884c4/photo.jpg 
 +                        mv *.jpg archives 
 +                        sleep 10 
 +                done 
 +        else 
 +                sleep 60 
 +        fi 
 +done 
 +exit 0 
 +</code> 
 +et avec un lancement et archivage , script pour crontab qui tue les process et ses enfants ... 
 +<code c> 
 +#!/bin/bash 
 +pkill -P `pgrep ane_photo.sh` 
 +killall -9 ane_photo.sh 
 +currentdate=$(date +%F) 
 +cd /var/lib/nethserver/ftp/espcam/archives 
 +tar cvfz $(date +%F)_ane.tgz --remove-files *jpg 2>&1 > /dev/null 
 +/usr/local/bin/ane_photo.sh & 
 +exit 0 
 +</code>
 <code c> <code c>
 /* /*
    ESP32cam_ftp    ESP32cam_ftp
    Blog: http://www.gsampallo.com/blog/?p=686    Blog: http://www.gsampallo.com/blog/?p=686
-   modif gepeto@du-libre.org 2023+   Twitter: @gsampallo.com
 */ */
 #include "esp_camera.h" #include "esp_camera.h"
Ligne 27: Ligne 62:
 #include "driver/rtc_io.h" #include "driver/rtc_io.h"
 #include <WiFi.h> #include <WiFi.h>
-#include <WiFiClient.h>+//#include <WiFiClient.h> 
 +#include <WiFiMulti.h> 
 #include "ESP32_FTPClient.h" #include "ESP32_FTPClient.h"
  
Ligne 41: Ligne 78:
 #define PIN_LED       LED_BUILTIN #define PIN_LED       LED_BUILTIN
  
-char* ftp_server = "192.168.1.xxx"; +char* ftp_server = "192.168.1.12"; 
-char* ftp_user = "espcam";+char* ftp_user = "blabla";
 char* ftp_pass = "blabla"; char* ftp_pass = "blabla";
 char* ftp_path = "/photos"; // ne me sert pas char* ftp_path = "/photos"; // ne me sert pas
- 
 int frequence = 1 ; // minutes int frequence = 1 ; // minutes
  
-const char* WIFI_SSID = "blabla"; +const char* WIFI_SSID = "ap1"; 
-const char* WIFI_PASS = "blabla";+const char* WIFI_PASS = "passap1"; 
 +const char* AP1  = "ap1"; 
 +const char* PASSAP1 = "passap1"; 
 +const char* AP2  = "ap2"; 
 +const char* PASSAP2 = "passap2";
  
 WiFiUDP ntpUDP; WiFiUDP ntpUDP;
Ligne 79: Ligne 119:
 #define BUFFSIZE 512 #define BUFFSIZE 512
 #define AVIOFFSET 240 // AVI main header length #define AVIOFFSET 240 // AVI main header length
 +
 +WiFiMulti wifiMulti;
  
 void setup() { void setup() {
Ligne 84: Ligne 126:
  
   Serial.begin(115200);   Serial.begin(115200);
 +  wifiMulti.addAP(AP1, PASSAP1);
 +  wifiMulti.addAP(AP2, PASSAP2);
  
-  WiFi.begin(WIFI_SSID, WIFI_PASS); +  if (wifiMulti.run() == WL_CONNECTED) { 
- +    Serial.println(""); 
-  Serial.println("Connecting Wifi..."); +    Serial.println("WiFi connected"); 
-  while (WiFi.status() != WL_CONNECTED) { +    Serial.println("IP address: "); 
-    delay(500); +    Serial.println(WiFi.localIP());
-    Serial.println("Connecting to WiFi.."); +
   }   }
-  Serial.println("IP address: "); 
  
-  Serial.println(WiFi.localIP()); 
-   
 #include "soc/soc.h"           // Disable brownout problems #include "soc/soc.h"           // Disable brownout problems
 #include "soc/rtc_cntl_reg.h"  // Disable brownout problems #include "soc/rtc_cntl_reg.h"  // Disable brownout problems
   WRITE_PERI_REG(RTC_CNTL_BROWN_OUT_REG, 0); //disable brownout detector   WRITE_PERI_REG(RTC_CNTL_BROWN_OUT_REG, 0); //disable brownout detector
  
-  initCamera();  +  initCamera();
   sensor_t * s = esp_camera_sensor_get();   sensor_t * s = esp_camera_sensor_get();
   s->set_brightness(s, 0);     // -2 to 2   s->set_brightness(s, 0);     // -2 to 2
Ligne 136: Ligne 175:
  
 void loop() { void loop() {
 +  if (wifiMulti.run() != WL_CONNECTED) {
 +    Serial.println("WiFi not connected!");
 +    delay(10000);
 +    Serial.println("RESET!");
 +    ESP.restart();
 +  }
   timeClient.update();   timeClient.update();
   delay(5000);   delay(5000);
Ligne 229: Ligne 274:
   esp_camera_fb_return(fb);   esp_camera_fb_return(fb);
 } }
- 
 </code> </code>
ressources/photo_ftp.1693388850.txt.gz · Dernière modification : 2024/02/08 17:20 (modification externe)