- 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.
73 lines
2.3 KiB
Python
73 lines
2.3 KiB
Python
#!/usr/bin/env python3
|
|
# coding: utf-8
|
|
|
|
"""
|
|
Script d'automatisation pour la gestion du système timelapse
|
|
Ce script vérifie le statut du serveur et configure le système en conséquence.
|
|
"""
|
|
|
|
import os
|
|
import sys
|
|
import time
|
|
import logging
|
|
import subprocess
|
|
from timelapse.config import config
|
|
from timelapse.api_client import api_client
|
|
from timelapse.sensors import micro_controller
|
|
|
|
|
|
def main():
|
|
"""
|
|
Fonction principale d'automatisation
|
|
"""
|
|
logging.info("==================== AUTOMATISATION TIMELAPSE ====================")
|
|
|
|
try:
|
|
# Récupérer le statut de la caméra depuis l'API
|
|
camera_status = api_client.get_camera_status()
|
|
|
|
if camera_status is None:
|
|
logging.error("Impossible d'obtenir le statut de la caméra depuis l'API")
|
|
return
|
|
|
|
# Mettre à jour la configuration locale
|
|
api_client.update_camera_config(camera_status)
|
|
|
|
# Vérifier l'état de maintenance
|
|
if camera_status.get("maintenance", False):
|
|
logging.info("Caméra en mode maintenance, aucune action nécessaire")
|
|
return
|
|
|
|
# Vérifier si un arrêt de la procédure est demandé
|
|
if camera_status.get("stop_flag", False):
|
|
logging.info("Arrêt de la procédure en cours...")
|
|
|
|
# Supprimer le fichier de configuration s'il existe
|
|
config.delete_config_file()
|
|
|
|
# Confirmer l'arrêt
|
|
api_client.confirm_stop()
|
|
return
|
|
|
|
# Vérifier s'il y a une configuration à appliquer
|
|
if not camera_status.get("idle", True):
|
|
logging.info("Configuration active détectée")
|
|
|
|
# Obtenir les paramètres
|
|
interval = camera_status.get("interval", 3)
|
|
|
|
# Envoyer l'intervalle au microcontrôleur
|
|
logging.info(f"Envoi de l'intervalle au microcontrôleur: {interval}s")
|
|
micro_controller.send_interval(interval)
|
|
|
|
# Éteindre le système après configuration
|
|
logging.info("Configuration terminée, arrêt du système")
|
|
subprocess.run(["sudo", "shutdown", "now"])
|
|
|
|
except Exception as e:
|
|
logging.error(f"Erreur dans le script d'automatisation: {e}")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|