diff --git a/Raspberry/Module_4G/processusEnvoi4G.py b/Raspberry/Module_4G/processusEnvoi4G.py index 8accb44cca20a3c611dce1628759a13cddd70ed5..717a6024be1a3b5484be0528aace8cf641e4e181 100755 --- a/Raspberry/Module_4G/processusEnvoi4G.py +++ b/Raspberry/Module_4G/processusEnvoi4G.py @@ -1,4 +1,5 @@ # A executer avec SUDO +# Gestion de wvdial deplacee dans rapatriement.py # PYTHON 3.5+ import subprocess @@ -10,13 +11,14 @@ import os.path from datetime import datetime import psutil -def check_pid(pid): - # Verifie l'existence d'un pid - if psutil.pid_exists(pid): - p = psutil.Process(pid) - if p.status() != psutil.STATUS_ZOMBIE: - return True - return False + +#def check_pid(pid): +# # Verifie l'existence d'un pid +# if psutil.pid_exists(pid): +# p = psutil.Process(pid) +# if p.status() != psutil.STATUS_ZOMBIE: +# return True +# return False # Verifie qu'il n'y a pas d'autres processus d'envoi en verifiant le fichier lock @@ -42,15 +44,15 @@ f = None try: - pid = subprocess.Popen(["wvdial"]) + #pid = subprocess.Popen(["wvdial"]) - print("============ WVDIAL LANCE ==============") - print("PID = ",pid.pid) + #print("============ WVDIAL LANCE ==============") + #print("PID = ",pid.pid) - time.sleep(10) + #time.sleep(10) - print("============ CORRECTION ROUTE ==============") - subprocess.Popen(["route", "add", "default", "dev", "ppp0"]) # Corrige la 4G au demarrage du raspberry + #print("============ CORRECTION ROUTE ==============") + #subprocess.Popen(["route", "add", "default", "dev", "ppp0"]) # Corrige la 4G au demarrage du raspberry print("============ CONNEXION ==============") @@ -77,8 +79,8 @@ except KeyboardInterrupt : print("============= LIBERATION =============") os.remove(".lockprocess") - print("============ WVDIAL ARRET ==============") - subprocess.Popen(["kill", "-1", pid.pid]) + #print("============ WVDIAL ARRET ==============") + #subprocess.Popen(["kill", "-1", str(pid.pid)]) except Exception as ex: @@ -88,8 +90,8 @@ except Exception as ex: print("============= LIBERATION =============") os.remove(".lockprocess") - print("============ WVDIAL ARRET ==============") - subprocess.Popen(["kill", "-1", pid.pid]) + #print("============ WVDIAL ARRET ==============") + #subprocess.Popen(["kill", "-1", str(pid.pid)]) print("================ FIN =================") @@ -99,9 +101,9 @@ if f is not None: log.close() -if check_pid(pid.pid): - print("============ WVDIAL ARRET ==============") - subprocess.Popen(["kill", "-1", str(pid.pid)]) +#if check_pid(pid.pid): + #print("============ WVDIAL ARRET ==============") + #subprocess.Popen(["kill", "-1", str(pid.pid)]) time.sleep(1) if os.path.isfile("./.lockprocess"): diff --git a/Raspberry/Module_4G/rapatriement.py b/Raspberry/Module_4G/rapatriement.py new file mode 100644 index 0000000000000000000000000000000000000000..a02373606726aa83735f07355ddad49d41085835 --- /dev/null +++ b/Raspberry/Module_4G/rapatriement.py @@ -0,0 +1,61 @@ +# A EXECUTER AVEC SUDO +# Python 3.5+ + +import os +import subprocess +import shutil +import time +import psutil +import sys + +def check_pid(pid): + # Verifie l'existence d'un pid + if psutil.pid_exists(pid): + p = psutil.Process(pid) + if p.status() != psutil.STATUS_ZOMBIE: + return True + return False + + +FOLDER = "data/" +TRAITEES = "traitees/" +DIR = os.listdir(FOLDER) +pid = -1 + +# Parcours les fichiers et les envois au serveur PC +while True: + try : + pid = subprocess.Popen(["wvdial"]) + print("============= WVDIAL LANCEE =============") + print("PID = ", pid.pid) + + time.sleep(10) + + print("============= CORRECTION ROUTE =============") + subprocess.Popen(["route", "add", "default", "dev", "ppp0"]) + + for f in DIR : + if os.access(FOLDER+f, os.W_OK) and os.access(FOLDER+f, os.R_OK): + print(FOLDER+f) + process = subprocess.Popen(["python3", "processusEnvoi4G.py", FOLDER+f]) + process.wait() + print("Fin process") + + shutil.move(FOLDER+f, TRAITEES+f) + + print("Dossier data vide -- FIN") + except KeyboardInterrupt: + print("============= WVDIAL ARRET =============") + subprocess.Popen(["kill", "-1", str(pid.pid)]) + sys.exit(0) + except Exception as ex: + print(ex) + print("============= WVDIAL ARRET =============") + subprocess.Popen(["kill", "-1", str(pid.pid)]) + + if check_pid(pid.pid): + print("============= WVDIAL ARRET =============") + subprocess.Popen(["kill", "-1", str(pid.pid)]) + + + time.sleep(21600) # Envoi toutes les 6 heures