Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| f704f96a7f | |||
| 7321243f8b | |||
| da571929a8 | |||
|
|
b1728478f2 | ||
| 2070871341 | |||
|
|
14bbfc5588 | ||
|
|
08693f1397 |
49
Automate.py
49
Automate.py
@@ -63,7 +63,7 @@ class Server:
|
|||||||
self.dic["maintenance"] = camera_status["maintenance"]
|
self.dic["maintenance"] = camera_status["maintenance"]
|
||||||
self.dic["timelapse"] = camera_status["interval"]
|
self.dic["timelapse"] = camera_status["interval"]
|
||||||
self.dic["conf nb_images"] = camera_status["nb_images"]
|
self.dic["conf nb_images"] = camera_status["nb_images"]
|
||||||
self.dic["set_config"] = camera_status["idle"]
|
self.dic["set_config"] = not camera_status["idle"]
|
||||||
self.dic["stop current config"] = camera_status["stop_flag"]
|
self.dic["stop current config"] = camera_status["stop_flag"]
|
||||||
else:
|
else:
|
||||||
print("mauvais code")
|
print("mauvais code")
|
||||||
@@ -98,6 +98,24 @@ class Server:
|
|||||||
with open(self.filename, "w") as file:
|
with open(self.filename, "w") as file:
|
||||||
json.dump(dic, file)
|
json.dump(dic, file)
|
||||||
|
|
||||||
|
def has_pending_tasks(self):
|
||||||
|
"""Vérifie s'il y a des captures en attente de synchronisation."""
|
||||||
|
project_path = "//home//timelapse//Documents//Time_Lapse//PROJECT//"
|
||||||
|
offline_dir = os.path.join(project_path, "_offline")
|
||||||
|
|
||||||
|
# Si le répertoire offline existe et n'est pas vide, il y a des tâches en attente
|
||||||
|
if os.path.exists(offline_dir) and os.listdir(offline_dir):
|
||||||
|
return True
|
||||||
|
|
||||||
|
# Vérifier également les fichiers dans PROJECT qui pourraient être en attente d'envoi
|
||||||
|
if os.path.exists(project_path):
|
||||||
|
for item in os.listdir(project_path):
|
||||||
|
# Si c'est un dossier mais pas le dossier _offline
|
||||||
|
if os.path.isdir(os.path.join(project_path, item)) and item != "_offline":
|
||||||
|
return True
|
||||||
|
|
||||||
|
return False
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
MC = MicroControler()
|
MC = MicroControler()
|
||||||
server = Server()
|
server = Server()
|
||||||
@@ -132,17 +150,26 @@ if __name__ == "__main__":
|
|||||||
else:
|
else:
|
||||||
server.create_this_Json(datas)
|
server.create_this_Json(datas)
|
||||||
print("- New Config")
|
print("- New Config")
|
||||||
print("- Shut Down")
|
|
||||||
print("TimeLapse sent is : ", datas["timelapse"])
|
# Vérifier s'il y a des tâches en attente avant d'éteindre
|
||||||
|
print("- Vérification si des transferts d'images sont en cours...")
|
||||||
|
|
||||||
|
# Envoyer l'intervalle au microcontrôleur
|
||||||
|
print("TimeLapse sent is : ", datas["timelapse"])
|
||||||
MC.set_data_2_octets(datas["timelapse"])
|
MC.set_data_2_octets(datas["timelapse"])
|
||||||
|
|
||||||
|
# Attendre un moment pour s'assurer que les transferts se terminent
|
||||||
|
max_wait = 60 # Maximum 60 secondes d'attente
|
||||||
|
wait_interval = 5 # Vérifier toutes les 5 secondes
|
||||||
|
|
||||||
|
for i in range(0, max_wait, wait_interval):
|
||||||
|
if server.has_pending_tasks():
|
||||||
|
print(f"- Des images sont encore en cours de transfert, attente ({i}s)...")
|
||||||
|
time.sleep(wait_interval)
|
||||||
|
else:
|
||||||
|
print("- Aucun transfert en cours, extinction du système")
|
||||||
|
break
|
||||||
|
|
||||||
|
print("- Extinction du système")
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
os.system("sudo shutdown now")
|
os.system("sudo shutdown now")
|
||||||
|
|
||||||
"""
|
|
||||||
#MC.set_data_2_octets(1)
|
|
||||||
|
|
||||||
#MC .set_data_2_octets(datas["timelapse"])
|
|
||||||
#le mot de passe c'est motdepasse
|
|
||||||
#nmcli dev wifi "le mot de passe c'est motdepasse" password "motdepasse"
|
|
||||||
"""
|
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
{"set_config": false, "maintenance": false, "stop current config": false, "timelapse": 3, "conf nb_images": 1, "nb_images restantes": 1}
|
|
||||||
10
First_Try.py
10
First_Try.py
@@ -1,10 +0,0 @@
|
|||||||
import time
|
|
||||||
import picamera2 as pc
|
|
||||||
|
|
||||||
camera = pc.Picamera2()
|
|
||||||
try:
|
|
||||||
camera.strat_preview()
|
|
||||||
time.sleep(10)
|
|
||||||
camera.stop_preview()
|
|
||||||
finally:
|
|
||||||
camera.close()
|
|
||||||
@@ -54,10 +54,10 @@ class Send_data_stocked:
|
|||||||
'image': (image_path, open(image_path, 'rb'), 'image/jpeg')
|
'image': (image_path, open(image_path, 'rb'), 'image/jpeg')
|
||||||
}
|
}
|
||||||
try:
|
try:
|
||||||
#print(data)
|
print("Datas are : ",data)
|
||||||
#print(files)
|
#print(files)
|
||||||
response = requests.post(self.url, headers=self.headers, data=data, files=files)
|
response = requests.post(self.url, headers=self.headers, data=data, files=files)
|
||||||
print(response)
|
print("Answer from server is : ",response)
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
response_data = response.json()
|
response_data = response.json()
|
||||||
return response_data
|
return response_data
|
||||||
|
|||||||
@@ -61,13 +61,13 @@ class TimeLapse:
|
|||||||
|
|
||||||
def pick_Picture(self):
|
def pick_Picture(self):
|
||||||
cam = pc.Picamera2()
|
cam = pc.Picamera2()
|
||||||
conf = cam.create_preview_configuration(main={"size":(800, 600)})
|
conf = cam.create_still_configuration(main={"size": (800, 600)})
|
||||||
cam.configure(conf)
|
cam.configure(conf)
|
||||||
cam.start_preview(pc.Preview.QTGL)
|
|
||||||
cam.start()
|
cam.start()
|
||||||
time.sleep(0.1)
|
# Allow camera time to initialize
|
||||||
|
time.sleep(2)
|
||||||
timestamp = self.get_TimeStamp()
|
timestamp = self.get_TimeStamp()
|
||||||
path = self.project_path + timestamp + "//" + timestamp+".jpg"
|
path = self.project_path + timestamp + "//" + timestamp + ".jpg"
|
||||||
self.create_Folder()
|
self.create_Folder()
|
||||||
image = cam.capture_file(path)
|
image = cam.capture_file(path)
|
||||||
cam.close()
|
cam.close()
|
||||||
|
|||||||
@@ -60,13 +60,13 @@ class TimeLapse:
|
|||||||
|
|
||||||
def pick_Picture(self):
|
def pick_Picture(self):
|
||||||
cam = pc.Picamera2()
|
cam = pc.Picamera2()
|
||||||
conf = cam.create_preview_configuration(main={"size":(800, 600)})
|
conf = cam.create_still_configuration(main={"size": (800, 600)})
|
||||||
cam.configure(conf)
|
cam.configure(conf)
|
||||||
cam.start_preview(pc.Preview.QTGL)
|
|
||||||
cam.start()
|
cam.start()
|
||||||
time.sleep(0.1)
|
# Allow camera time to initialize
|
||||||
|
time.sleep(2)
|
||||||
timestamp = self.get_TimeStamp()
|
timestamp = self.get_TimeStamp()
|
||||||
path = self.project_path + timestamp + "//" + timestamp+".jpg"
|
path = self.project_path + timestamp + "//" + timestamp + ".jpg"
|
||||||
self.create_Folder()
|
self.create_Folder()
|
||||||
image = cam.capture_file(path)
|
image = cam.capture_file(path)
|
||||||
cam.close()
|
cam.close()
|
||||||
|
|||||||
@@ -1,14 +0,0 @@
|
|||||||
import requests
|
|
||||||
|
|
||||||
url_requete = "https://timelapse.kerboul.me/api/camera/status"
|
|
||||||
|
|
||||||
try:
|
|
||||||
response = requests.get(url_requete)
|
|
||||||
|
|
||||||
if response.status_code == 200:
|
|
||||||
camera_status = response.json()
|
|
||||||
print(camera_status)
|
|
||||||
else:
|
|
||||||
print("mauvais code")
|
|
||||||
except requests.exceptions.RequestException as e:
|
|
||||||
print("erreur API ou internet")
|
|
||||||
@@ -7,9 +7,16 @@ check_internet() {
|
|||||||
if check_internet; then
|
if check_internet; then
|
||||||
echo "Connecté à internet"
|
echo "Connecté à internet"
|
||||||
python Time_Lapse_Connection.py
|
python Time_Lapse_Connection.py
|
||||||
|
# Attendre un peu pour s'assurer que le processus de capture est terminé
|
||||||
|
sleep 5
|
||||||
python Send_data_stocked.py
|
python Send_data_stocked.py
|
||||||
|
# Attendre encore un peu pour s'assurer que l'envoi des données stockées est terminé
|
||||||
|
sleep 5
|
||||||
else
|
else
|
||||||
echo "pas connecté à internet"
|
echo "pas connecté à internet"
|
||||||
python Time_Lapse_NoConnection.py
|
python Time_Lapse_NoConnection.py
|
||||||
|
sleep 5
|
||||||
fi
|
fi
|
||||||
python Automate.py
|
|
||||||
|
# Exécuter l'automate à la fin, après les délais
|
||||||
|
python Automate.py
|
||||||
|
|||||||
23
timelapse-service.log
Normal file
23
timelapse-service.log
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
Erreur : Insufficient privileges.
|
||||||
|
Connecté à internet
|
||||||
|
[0:13:07.775780345] [3774] [1;32m INFO [1;37mCamera [1;34mcamera_manager.cpp:327 [0mlibcamera v0.4.0+53-29156679
|
||||||
|
[0:13:07.806936514] [3777] [1;33m WARN [1;37mRPiSdn [1;34msdn.cpp:40 [0mUsing legacy SDN tuning - please consider moving SDN inside rpi.denoise
|
||||||
|
[0:13:07.809437125] [3777] [1;32m INFO [1;37mRPI [1;34mvc4.cpp:447 [0mRegistered camera /base/soc/i2c0mux/i2c@1/ov5647@36 to Unicam device /dev/media1 and ISP device /dev/media3
|
||||||
|
[0:13:07.809535588] [3777] [1;32m INFO [1;37mRPI [1;34mpipeline_base.cpp:1121 [0mUsing configuration file '/usr/share/libcamera/pipeline/rpi/vc4/rpi_apps.yaml'
|
||||||
|
[0:13:07.816878221] [3774] [1;32m INFO [1;37mCamera [1;34mcamera.cpp:1202 [0mconfiguring streams: (0) 800x600-XBGR8888 (1) 1296x972-SGBRG10_CSI2P
|
||||||
|
[0:13:07.817365292] [3777] [1;32m INFO [1;37mRPI [1;34mvc4.cpp:622 [0mSensor: /base/soc/i2c0mux/i2c@1/ov5647@36 - Selected sensor format: 1296x972-SGBRG10_1X10 - Selected unicam format: 1296x972-pGAA
|
||||||
|
qt.qpa.xcb: could not connect to display
|
||||||
|
qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "" even though it was found.
|
||||||
|
This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.
|
||||||
|
|
||||||
|
Available platform plugins are: eglfs, linuxfb, minimal, minimalegl, offscreen, vnc, wayland-egl, wayland, wayland-xcomposite-egl, wayland-xcomposite-glx, xcb.
|
||||||
|
|
||||||
|
/home/timelapse/Documents/Time_Lapse/script.sh : ligne 14 : 3774 Abandon python Time_Lapse_Connection.py
|
||||||
|
Noms des dossiers : []
|
||||||
|
Here is the answer from the server : {'id': 1, 'interval': 5, 'nb_images': 10, 'maintenance': False, 'stop_flag': True, 'idle': False}
|
||||||
|
Here are the datas loaded : {'set_config': True, 'maintenance': False, 'stop current config': True, 'timelapse': 5, 'conf nb_images': 10, 'nb_images restantes': 1}
|
||||||
|
- No Maintenance
|
||||||
|
- Stopping current config
|
||||||
|
- New Config
|
||||||
|
- Shut Down
|
||||||
|
TimeLapse sent is : 5
|
||||||
Reference in New Issue
Block a user