- Removed obsolete script `script_SANSDEMARRAGE.sh`. - Added new `Camera.py` and `Connexion.py` files for camera handling and socket communication. - Implemented `First_Try.py` for initial camera preview testing. - Created `Humidity.py` for humidity sensor data acquisition. - Developed `Send_data_stocked.py` for managing and sending stored data. - Introduced `Time_Lapse_Connection.py` and `Time_Lapse_NoConnection.py` for connected and offline modes. - Added `get_from_server.py` for retrieving camera status from the server. - Updated `sync_offline_data.py` for synchronizing offline data. - Created `timelapse.service` for managing the timelapse service on Raspberry Pi. - Established package structure with `__init__.py` and `api_client.py` for API interactions. - Enhanced `capture.py` for managing image captures and data storage. - Configured `config.py` for centralized configuration management. - Developed `sensors.py` for handling environmental sensors and camera operations. - Implemented `timelapse_offline.py` and `timelapse_online.py` for capturing images in offline and online modes.
104 lines
2.7 KiB
Bash
Executable File
104 lines
2.7 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# Configuration
|
|
CONFIG_DIR="/home/timelapse/Documents/Time_Lapse/CONFIG"
|
|
LOG_FILE="/home/timelapse/Documents/Time_Lapse/timelapse.log"
|
|
BASE_DIR="/home/timelapse/Documents/Time_Lapse"
|
|
MAX_RETRIES=5
|
|
RETRY_DELAY=10
|
|
LOCK_FILE="/var/lock/timelapse.lock"
|
|
|
|
# Fonction de journalisation
|
|
log() {
|
|
echo "$(date '+%Y-%m-%d %H:%M:%S') - $1" | tee -a "$LOG_FILE"
|
|
}
|
|
|
|
# Vérifier si une autre instance est en cours d'exécution
|
|
if [ -f "$LOCK_FILE" ]; then
|
|
PID=$(cat "$LOCK_FILE")
|
|
if ps -p $PID > /dev/null; then
|
|
log "Une autre instance est déjà en cours d'exécution (PID: $PID). Arrêt."
|
|
exit 1
|
|
else
|
|
log "Fichier de verrouillage obsolète trouvé. Suppression."
|
|
rm -f "$LOCK_FILE"
|
|
fi
|
|
fi
|
|
|
|
# Créer le fichier de verrouillage
|
|
echo $$ > "$LOCK_FILE"
|
|
|
|
# Fonction de nettoyage à la sortie
|
|
cleanup() {
|
|
log "Nettoyage avant sortie"
|
|
rm -f "$LOCK_FILE"
|
|
exit $1
|
|
}
|
|
|
|
# Interception des signaux pour le nettoyage
|
|
trap 'cleanup 1' INT TERM
|
|
|
|
log "==============================================================="
|
|
log "Démarrage du système timelapse"
|
|
|
|
# Fonction pour se connecter au WiFi avec plusieurs tentatives
|
|
connect_wifi() {
|
|
local ssid="Redmi Note 12 Pro"
|
|
local password="kingcard"
|
|
local retries=0
|
|
|
|
while [ $retries -lt $MAX_RETRIES ]; do
|
|
log "Tentative de connexion WiFi ($((retries+1))/$MAX_RETRIES)"
|
|
nmcli dev wifi connect "$ssid" password "$password"
|
|
|
|
if check_internet; then
|
|
log "Connexion WiFi établie"
|
|
return 0
|
|
fi
|
|
|
|
retries=$((retries+1))
|
|
sleep $RETRY_DELAY
|
|
done
|
|
|
|
log "Échec de connexion WiFi après $MAX_RETRIES tentatives"
|
|
return 1
|
|
}
|
|
|
|
# Fonction pour vérifier la connexion internet
|
|
check_internet() {
|
|
ping -c 1 8.8.8.8 > /dev/null 2>&1
|
|
return $?
|
|
}
|
|
|
|
# S'assurer que le répertoire de configuration existe
|
|
mkdir -p "$CONFIG_DIR"
|
|
|
|
# Principal flux d'exécution
|
|
connect_wifi
|
|
|
|
# Vérifier si les chemins Python sont corrects
|
|
export PYTHONPATH="$BASE_DIR:$PYTHONPATH"
|
|
|
|
if check_internet; then
|
|
log "Connecté à internet"
|
|
|
|
# Vérifier si des données locales doivent être envoyées
|
|
log "Envoi des données stockées localement"
|
|
python3 "$BASE_DIR/sync_offline_data.py"
|
|
|
|
# Exécuter en mode connecté
|
|
log "Exécution du script en mode connecté"
|
|
python3 "$BASE_DIR/timelapse_online.py"
|
|
|
|
else
|
|
log "Pas connecté à internet"
|
|
log "Exécution du script en mode hors-ligne"
|
|
python3 "$BASE_DIR/timelapse_offline.py"
|
|
fi
|
|
|
|
# Exécuter le script d'automatisation dans tous les cas
|
|
log "Exécution du script d'automatisation"
|
|
python3 "$BASE_DIR/Automate.py"
|
|
|
|
log "Script terminé"
|
|
cleanup 0 |