RPI qui reste allumé

Puis le script principal est celui ci:

import os
import time
import requests
import urllib.parse

import board
import busio
import adafruit_ds3231

from datetime import datetime, timedelta
from math import *

from picamera2 import Picamera2
from ina219 import INA219, DeviceRangeError

import logging
import logging.handlers

import subprocess

fileLog = '/home/pi/script/log.txt'

logger = logging.getLogger('mylogger')
logger.setLevel(logging.DEBUG)
handler = logging.handlers.RotatingFileHandler(fileLog, maxBytes=100000000, backupCount=1)

stream = logging.StreamHandler()
stream.setLevel(logging.DEBUG)

logger.addHandler(stream)
logger.addHandler(handler)

i2c = busio.I2C(board.SCL, board.SDA)
rtc = adafruit_ds3231.DS3231(i2c)

rtc.alarm1_interrupt = True
rtc.alarm1_status = False
rtc.alarm2_interrupt = True
rtc.alarm2_status = False

now_ds3231 = rtc.datetime
cmd = f"sudo date -s '{now_ds3231.tm_year}-{now_ds3231.tm_mon:02d}-{now_ds3231.tm_mday:02d} {now_ds3231.tm_hour:02d}:{now_ds3231.tm_min:02d}:{now_ds3231.tm_sec:02d}'"
os.system(cmd)

with open('/boot/id_materiel.txt') as f:
    id_materiel = f.read().strip()
with open('/boot/portssh.txt') as f:
    portssh = f.read().strip()

# ------------ START UTILS ------------
# Log message (console & file)
def log(type, message):
    messageToWrite = datetime.today().strftime('%Y-%m-%d %H:%M:%S') + " - " + type + " - " + message
    logger.info(messageToWrite)

# Check if device has internet
def isInternetUp():
    try:
        check = subprocess.getoutput("sudo nmcli -f GENERAL.STATE con show gsm | awk '{print $2}'")
        if(check == "activated"):
            print("activated")
            return True
        else:
            print("not activated")
            return False
    except Exception as e:
        log("error", "no internet : " + str(e))
        return False

# Sync time with ntp
def syncTime():
    try:
        import ntplib
        client = ntplib.NTPClient()
        response = client.request('pool.ntp.org')
        os.system('date ' + time.strftime('%m%d%H%M%Y.%S',time.localtime(response.tx_time)))
        try:
            rtc.datetime = time.localtime(response.tx_time)
            log("INFO", "New date set into system & RTC : "+time.strftime('%y/%m/%d %u %H:%M:%S',time.localtime(response.tx_time)))
        except Exception as e:
            log("ERROR", "syncTime - Write RTC : "+str(e))
            return False
    except Exception as e:
        log("ERROR", "syncTime() : Can't sync with time server : " + str(e))

# Reset nmcli connection
def resetConnection():
    try:
        os.system("sudo nmcli con delete gsm")
        os.system("sudo nmcli con add con-name gsm connection.type gsm ifname ttyUSB0")
        os.system("sudo nmcli con modify gsm ipv6.method disabled")
        os.system("sudo nmcli con modify gsm connection.autoconnect yes")
        os.system("sudo nmcli con modify gsm gsm.apn orange")
        os.system("sudo nmcli con modify gsm gsm.username orange")
        os.system("sudo nmcli con modify gsm gsm.password orange")
    except Exception as e:
        log("ERROR", "resetConnection() : Can't reset connection : " + str(e))

# Encode decimal to BCD
def dec2bcd(dec):
    return int(int(dec)/10)*16 + int(dec)%10

def bcd2dec(bcd):
    return(10 * (bcd >> 4) + (bcd & 0x0F))

# Get value from UPS and return it
def getUPS():
    ina = INA219(shunt_ohms=0.1, address=0x45)
    ina.configure()

    try:
        v = ina.voltage()
        i = ina.current()
        p = ina.power()

        message = '&current={0:0.1f}&power={1:0.01f}&voltage={2:0.01f}'.format(i, p/1000, v)
        return message
    except DeviceRangeError as e:
        log("ERROR", "getUPS() : "+str(e))

    return False

def writeWitty(date):
    try:
        alarm1_struct = time.localtime(time.mktime(date.timetuple()))
        alarm2_struct = time.localtime(time.mktime((2024, 1, 1, 8, 0, 0, 1, 1, 0)))
        rtc.alarm1 = (alarm1_struct, "monthly")
        rtc.alarm2 = (alarm2_struct, "daily")
        log("INFO", "Next startup scheduled at "+date.strftime('%Y-%m-%d %H:%M:%S'))
        return True
    except Exception as e:
        log("ERROR", "schedueNextStartup - Write RTC : "+str(e))
        return False

def readWritty(date):
    try:
        dateAlarm = rtc.alarm1[0]
        dateAlarm1 = datetime(dateAlarm.tm_year, dateAlarm.tm_mon, dateAlarm.tm_mday, dateAlarm.tm_hour, dateAlarm.tm_min, dateAlarm.tm_sec)
        if(dateAlarm1.strftime('%d %H:%M:%S') != date.strftime('%d %H:%M:%S')):
            log("WARNING", "Ecriture Witty : Date different : "+dateAlarm1.strftime('%d %H:%M:%S')+" au lieu de "+date.strftime('%d %H:%M:%S'))
            return False
        return True
    except Exception as e:
        log("ERROR", "scheduleNextStartup - Read RTC : "+str(e))
        return False

def initSshReverse():
    try:
        log("INFO", "Init SSH reverse")
        # Run shell command in background
        os.system("autossh -M 0 -o \"ServerAliveInterval 30\" -o \"ServerAliveCountMax 3\" -N -f -o StrictHostKeyChecking=accept-new -i /home/pi/.ssh/id_rsa -R "+portssh+":127.0.0.1:22 -p PORTSSH USER@IPSERVER")
    except Exception as e:
        log("ERROR", "initSshReverse : "+str(e))
# ------------ END UTILS ------------


def scheduleNextStartup():
    if internetUp:
        # Ping interface and get info from it
        try:
            dataUPS = getUPS()
            if dataUPS:
                response = requests.get('URLAPI'+ id_materiel + dataUPS)
            else:
                response = requests.get('URLAPI'+ id_materiel)

            # throw an error for status code 4xx or 5xx
            if not response.ok:
                response.raise_for_status()

            data = response.json()
            with open('/home/pi/script/heure_debut.txt', 'w') as f, open('/home/pi/script/heure_fin.txt', 'w') as f2, open('/home/pi/script/interval.txt', 'w') as f3, open('/home/pi/script/nb_photo_rotate.txt', 'w') as f4:
                f.write(str(data['heureDebut']))
                f2.write(str(data['heureFin']))
                f3.write(str(data['intervalle']))
                f4.write(str(data['nbPictureRotate']))
        except Exception as e:
            log("ERROR", "scheduleNextStartup - Get API & Write files : "+str(e))

    with open('/home/pi/script/heure_debut.txt') as f, open('/home/pi/script/heure_fin.txt') as f2, open('/home/pi/script/interval.txt') as f3, open('/home/pi/script/nb_photo_rotate.txt') as f4:
        heureDebut = f.read().strip()
        heureFin = f2.read().strip()
        interval = f3.read().strip()

    dateNow = datetime.now()
    dateNext = dateNow + timedelta(minutes=int(interval))

    if(dateNow.strftime('%H:%M') >= heureFin):
        dateNext = dateNow + timedelta(days=1)
        dateNext = dateNext.replace(hour=int(heureDebut.split(":")[0]), minute=int(heureDebut.split(":")[1]), second=0, microsecond=0)
    elif(dateNow.strftime('%H:%M') < heureDebut):
        dateNext = dateNow
        dateNext = dateNext.replace(hour=int(heureDebut.split(":")[0]), minute=int(heureDebut.split(":")[1]), second=0, microsecond=0)
    else:
        dateDebut = dateNow.replace(hour=int(heureDebut.split(":")[0]), minute=int(heureDebut.split(":")[1]), second=0, microsecond=0)
        dateDiff = dateNow - dateDebut
        nbIteration = ceil(dateDiff.total_seconds()/(int(interval)*60))
        dateNext = dateDebut + timedelta(minutes=int(interval)*nbIteration)

    if(dateNext.strftime('%H:%M') > heureFin):
        dateNext = dateNext + timedelta(days=1)
        dateNext = dateNext.replace(hour=int(heureDebut.split(":")[0]), minute=int(heureDebut.split(":")[1]), second=0, microsecond=0)

    if(dateNext.strftime('%w') == "6"):
        dateNext = dateNext + timedelta(days=2)
        dateNext = dateNext.replace(hour=int(heureDebut.split(":")[0]), minute=int(heureDebut.split(":")[1]), second=0, microsecond=0)
    if(dateNext.strftime('%w') == "0"):
        dateNext = dateNext + timedelta(days=1)
        dateNext = dateNext.replace(hour=int(heureDebut.split(":")[0]), minute=int(heureDebut.split(":")[1]), second=0, microsecond=0)

    while True:
        if(writeWitty(dateNext)):
            if(readWritty(dateNext)):
                break
        else:
            break

def takeNewPicture():
    picam2 = Picamera2()
    try:
        StringTimeNow = datetime.today().strftime('%Y-%m-%d_%H-%M-%S')
        camera_config = picam2.create_still_configuration(main={"size": (4056, 3040)}, lores={"size": (640, 480)}, display="lores")
        picam2.configure(camera_config)
        picam2.start()
        time.sleep(2)
        picam2.capture_file("/home/pi/photos/"+StringTimeNow+".jpg")
    except Exception as e:
        log("ERROR", "takeNewPicture : "+str(e))
    picam2.stop()

def handleUploadRotate():
    with open('/home/pi/script/nb_photo_rotate.txt') as f:
        nbFileRotate = int(f.read().strip())
    dir_path = r'/home/pi/photos/'
    nbFile = len([entry for entry in os.listdir(dir_path) if os.path.isfile(os.path.join(dir_path, entry)) and entry.endswith('.jpg')])
    try: 
        if nbFile >= nbFileRotate:
            filesName =[entry for entry in os.listdir(dir_path) if os.path.isfile(os.path.join(dir_path, entry)) and entry.endswith('.jpg')]

            files = []
            for fileName in filesName:
                files.append(('pictures[]', (fileName, open(dir_path+fileName, 'rb'), 'image/jpeg')))

            if files:
                response = requests.post('URLAPI', data={'camera': id_materiel}, files=files)

                if ((response.status_code == 200) and (response.json()['success'] == True)):
                    log("INFO", "handleUploadRotate - Upload success")
                    for fileName in filesName:
                        os.remove(dir_path+fileName)
                    log("INFO", "handleUploadRotate - Files removed")
                else:
                    message = 'nbfiles:'+nbFile+',statuscode:'+response.status_code
                    response = requests.get('URLAPI'+ id_materiel +'&message'+ urllib.parse.quote(message))
                    log("ERROR", "handleUploadRotate - API answer bad : "+response.json())
            else:
                log("ERROR", "No file in handleUploadRotate")
    except Exception as e:
        log("ERROR", "handleUploadRotate : "+str(e))

def handleShutdown():
    if(os.path.exists("/home/pi/shutdown.txt")):
        os.system("sudo shutdown -h now")
    else:
        print("No shutdown file, skip shutdown")



# ------------ START SCRIPT ------------
try:
    attempts = 0
    attemptsModem = 0
    internetUp = False
    #internetUp = True

    os.system("sudo nmcli con delete gsm")
    os.system("sudo modprobe usbserial vendor=0x3566 product=0x2001; sudo usb_modeswitch -v 3566 -p 2001 -X; sudo modprobe option;")

    #check and wait for modem to be registered
    checkModem = subprocess.getoutput("sudo mmcli -m 0 | grep '  state' | awk '{print $3}'")

    while attemptsModem < 50 and checkModem != "registered":
    #while attemptsModem < 2 and checkModem != "registered":
        log("INFO", "Modem not registered, retry in 2 seconds")
        time.sleep(2)
        checkModem = subprocess.getoutput("sudo mmcli -m 0 | grep '  state' | awk '{print $3}'")
        attemptsModem += 1

Voyez vous un moyen d’améliorer le code ou la raison pour laquelle le système plante mais de manière aléatoire? merci de votre aide,

Bonjour,

C’est super pour la mise en forme. Par contre j’ai l’impression que le second script n’est toujours pas complet. Il y a plusieurs fonctions qui ne sont appelées nulle part. Et la directive try: n’a pas de except !

Du coup je ne vois nulle part quoi que ce soit qui détermine un plantage du script.

Par contre il y a un fichier de log /home/pi/script/log.txt que contient-il ?

A+

Bonjour,
Qu’est ce qui te fait dire que le script n’est pas complet?
Sur quelle partie?

je demande le fichier log demandé, merci

Voici le fichier log.text : 

Il a planté le 29/02/2024 à 12h01 : 

2024-02-28 20:01:02 - INFO - Next startup scheduled at 2024-02-29 08:00:00
2024-02-28 20:01:11 - INFO - handleUploadRotate - Upload success
2024-02-28 20:01:11 - INFO - handleUploadRotate - Files removed
2024-02-29 08:00:19 - INFO - Modem not registered, retry in 2 seconds
2024-02-29 08:00:21 - INFO - Modem not registered, retry in 2 seconds
2024-02-29 08:00:23 - INFO - Modem not registered, retry in 2 seconds
2024-02-29 08:00:25 - INFO - Modem not registered, retry in 2 seconds
2024-02-29 08:00:28 - INFO - Modem not registered, retry in 2 seconds
2024-02-29 08:00:30 - INFO - Modem not registered, retry in 2 seconds
2024-02-29 08:00:32 - INFO - Modem not registered, retry in 2 seconds
2024-02-29 08:00:34 - INFO - Modem not registered, retry in 2 seconds
2024-02-29 08:00:36 - INFO - Modem not registered, retry in 2 seconds
2024-02-29 08:00:38 - INFO - Modem not registered, retry in 2 seconds
2024-02-29 08:00:40 - INFO - Modem not registered, retry in 2 seconds
2024-02-29 08:00:42 - INFO - Modem not registered, retry in 2 seconds
2024-02-29 08:00:44 - INFO - Modem not registered, retry in 2 seconds
2024-02-29 08:00:47 - INFO - Modem not registered, retry in 2 seconds
2024-02-29 08:00:49 - INFO - Internet not up, retry in 5 seconds
2024-02-29 08:01:00 - INFO - Device have internet
2024-02-29 08:01:06 - INFO - New date set into system & RTC : 24/02/29 4 08:01:06
2024-02-29 08:01:06 - INFO - Init SSH reverse
2024-02-29 08:01:06 - INFO - Next startup scheduled at 2024-02-29 08:30:00
2024-02-29 08:30:19 - INFO - Modem not registered, retry in 2 seconds
2024-02-29 08:30:21 - INFO - Modem not registered, retry in 2 seconds
2024-02-29 08:30:23 - INFO - Modem not registered, retry in 2 seconds
2024-02-29 08:30:25 - INFO - Modem not registered, retry in 2 seconds
2024-02-29 08:30:27 - INFO - Modem not registered, retry in 2 seconds
2024-02-29 08:30:30 - INFO - Modem not registered, retry in 2 seconds
2024-02-29 08:30:32 - INFO - Modem not registered, retry in 2 seconds
2024-02-29 08:30:34 - INFO - Modem not registered, retry in 2 seconds
2024-02-29 08:30:36 - INFO - Modem not registered, retry in 2 seconds
2024-02-29 08:30:38 - INFO - Modem not registered, retry in 2 seconds
2024-02-29 08:30:40 - INFO - Modem not registered, retry in 2 seconds
2024-02-29 08:30:42 - INFO - Modem not registered, retry in 2 seconds
2024-02-29 08:30:44 - INFO - Modem not registered, retry in 2 seconds
2024-02-29 08:30:46 - INFO - Modem not registered, retry in 2 seconds
2024-02-29 08:30:49 - INFO - Internet not up, retry in 5 seconds
2024-02-29 08:31:00 - INFO - Device have internet
2024-02-29 08:31:06 - INFO - New date set into system & RTC : 24/02/29 4 08:31:06
2024-02-29 08:31:06 - INFO - Init SSH reverse
2024-02-29 08:31:06 - INFO - Next startup scheduled at 2024-02-29 09:00:00
2024-02-29 09:00:21 - INFO - Modem not registered, retry in 2 seconds
2024-02-29 09:00:23 - INFO - Modem not registered, retry in 2 seconds
2024-02-29 09:00:25 - INFO - Modem not registered, retry in 2 seconds
2024-02-29 09:00:27 - INFO - Modem not registered, retry in 2 seconds
2024-02-29 09:00:29 - INFO - Modem not registered, retry in 2 seconds
2024-02-29 09:00:32 - INFO - Modem not registered, retry in 2 seconds
2024-02-29 09:00:34 - INFO - Modem not registered, retry in 2 seconds
2024-02-29 09:00:36 - INFO - Modem not registered, retry in 2 seconds
2024-02-29 09:00:38 - INFO - Modem not registered, retry in 2 seconds
2024-02-29 09:00:40 - INFO - Modem not registered, retry in 2 seconds
2024-02-29 09:00:42 - INFO - Modem not registered, retry in 2 seconds
2024-02-29 09:00:44 - INFO - Modem not registered, retry in 2 seconds
2024-02-29 09:00:46 - INFO - Modem not registered, retry in 2 seconds
2024-02-29 09:00:49 - INFO - Modem not registered, retry in 2 seconds
2024-02-29 09:00:51 - INFO - Internet not up, retry in 5 seconds
2024-02-29 09:01:02 - INFO - Device have internet
2024-02-29 09:01:02 - INFO - New date set into system & RTC : 24/02/29 4 09:01:02
2024-02-29 09:01:02 - INFO - Init SSH reverse
2024-02-29 09:01:02 - INFO - Next startup scheduled at 2024-02-29 09:30:00
2024-02-29 09:01:09 - INFO - handleUploadRotate - Upload success
2024-02-29 09:01:09 - INFO - handleUploadRotate - Files removed
2024-02-29 09:30:20 - INFO - Modem not registered, retry in 2 seconds
2024-02-29 09:30:22 - INFO - Modem not registered, retry in 2 seconds
2024-02-29 09:30:24 - INFO - Modem not registered, retry in 2 seconds
2024-02-29 09:30:27 - INFO - Modem not registered, retry in 2 seconds
2024-02-29 09:30:29 - INFO - Modem not registered, retry in 2 seconds
2024-02-29 09:30:31 - INFO - Modem not registered, retry in 2 seconds
2024-02-29 09:30:33 - INFO - Modem not registered, retry in 2 seconds
2024-02-29 09:30:35 - INFO - Modem not registered, retry in 2 seconds
2024-02-29 09:30:37 - INFO - Modem not registered, retry in 2 seconds
2024-02-29 09:30:39 - INFO - Modem not registered, retry in 2 seconds
2024-02-29 09:30:41 - INFO - Modem not registered, retry in 2 seconds
2024-02-29 09:30:43 - INFO - Modem not registered, retry in 2 seconds
2024-02-29 09:30:45 - INFO - Modem not registered, retry in 2 seconds
2024-02-29 09:30:48 - INFO - Modem not registered, retry in 2 seconds
2024-02-29 09:30:50 - INFO - Internet not up, retry in 5 seconds
2024-02-29 09:31:01 - INFO - Device have internet
2024-02-29 09:31:02 - INFO - New date set into system & RTC : 24/02/29 4 09:31:02
2024-02-29 09:31:02 - INFO - Init SSH reverse
2024-02-29 09:31:02 - INFO - Next startup scheduled at 2024-02-29 10:00:00
2024-02-29 10:00:20 - INFO - Modem not registered, retry in 2 seconds
2024-02-29 10:00:22 - INFO - Modem not registered, retry in 2 seconds
2024-02-29 10:00:24 - INFO - Modem not registered, retry in 2 seconds
2024-02-29 10:00:26 - INFO - Modem not registered, retry in 2 seconds
2024-02-29 10:00:28 - INFO - Modem not registered, retry in 2 seconds
2024-02-29 10:00:31 - INFO - Modem not registered, retry in 2 seconds
2024-02-29 10:00:33 - INFO - Modem not registered, retry in 2 seconds
2024-02-29 10:00:35 - INFO - Modem not registered, retry in 2 seconds
2024-02-29 10:00:37 - INFO - Modem not registered, retry in 2 seconds
2024-02-29 10:00:39 - INFO - Modem not registered, retry in 2 seconds
2024-02-29 10:00:41 - INFO - Modem not registered, retry in 2 seconds
2024-02-29 10:00:43 - INFO - Modem not registered, retry in 2 seconds
2024-02-29 10:00:45 - INFO - Modem not registered, retry in 2 seconds
2024-02-29 10:00:47 - INFO - Modem not registered, retry in 2 seconds
2024-02-29 10:00:50 - INFO - Internet not up, retry in 5 seconds
2024-02-29 10:01:01 - INFO - Device have internet
2024-02-29 10:01:02 - INFO - New date set into system & RTC : 24/02/29 4 10:01:02
2024-02-29 10:01:02 - INFO - Init SSH reverse
2024-02-29 10:01:02 - INFO - Next startup scheduled at 2024-02-29 10:30:00
2024-02-29 10:30:20 - INFO - Modem not registered, retry in 2 seconds
2024-02-29 10:30:22 - INFO - Modem not registered, retry in 2 seconds
2024-02-29 10:30:24 - INFO - Modem not registered, retry in 2 seconds
2024-02-29 10:30:26 - INFO - Modem not registered, retry in 2 seconds
2024-02-29 10:30:28 - INFO - Modem not registered, retry in 2 seconds
2024-02-29 10:30:31 - INFO - Modem not registered, retry in 2 seconds
2024-02-29 10:30:33 - INFO - Modem not registered, retry in 2 seconds
2024-02-29 10:30:35 - INFO - Modem not registered, retry in 2 seconds
2024-02-29 10:30:37 - INFO - Modem not registered, retry in 2 seconds
2024-02-29 10:30:39 - INFO - Modem not registered, retry in 2 seconds
2024-02-29 10:30:41 - INFO - Modem not registered, retry in 2 seconds
2024-02-29 10:30:43 - INFO - Modem not registered, retry in 2 seconds
2024-02-29 10:30:45 - INFO - Modem not registered, retry in 2 seconds
2024-02-29 10:30:47 - INFO - Modem not registered, retry in 2 seconds
2024-02-29 10:30:50 - INFO - Internet not up, retry in 5 seconds
2024-02-29 10:31:01 - INFO - Device have internet
2024-02-29 10:31:02 - INFO - New date set into system & RTC : 24/02/29 4 10:31:02
2024-02-29 10:31:02 - INFO - Init SSH reverse
2024-02-29 10:31:02 - INFO - Next startup scheduled at 2024-02-29 11:00:00
2024-02-29 10:31:10 - INFO - handleUploadRotate - Upload success
2024-02-29 10:31:10 - INFO - handleUploadRotate - Files removed
2024-02-29 11:00:21 - INFO - Modem not registered, retry in 2 seconds
2024-02-29 11:00:23 - INFO - Modem not registered, retry in 2 seconds
2024-02-29 11:00:25 - INFO - Modem not registered, retry in 2 seconds
2024-02-29 11:00:27 - INFO - Modem not registered, retry in 2 seconds
2024-02-29 11:00:30 - INFO - Modem not registered, retry in 2 seconds
2024-02-29 11:00:32 - INFO - Modem not registered, retry in 2 seconds
2024-02-29 11:00:34 - INFO - Modem not registered, retry in 2 seconds
2024-02-29 11:00:36 - INFO - Modem not registered, retry in 2 seconds
2024-02-29 11:00:38 - INFO - Modem not registered, retry in 2 seconds
2024-02-29 11:00:40 - INFO - Modem not registered, retry in 2 seconds
2024-02-29 11:00:42 - INFO - Modem not registered, retry in 2 seconds
2024-02-29 11:00:44 - INFO - Modem not registered, retry in 2 seconds
2024-02-29 11:00:46 - INFO - Modem not registered, retry in 2 seconds
2024-02-29 11:00:49 - INFO - Modem not registered, retry in 2 seconds
2024-02-29 11:00:51 - INFO - Internet not up, retry in 5 seconds
2024-02-29 11:01:02 - INFO - Device have internet
2024-02-29 11:01:08 - INFO - New date set into system & RTC : 24/02/29 4 11:01:08
2024-02-29 11:01:08 - INFO - Init SSH reverse
2024-02-29 11:01:08 - INFO - Next startup scheduled at 2024-02-29 11:30:00
2024-02-29 11:30:20 - INFO - Modem not registered, retry in 2 seconds
2024-02-29 11:30:22 - INFO - Modem not registered, retry in 2 seconds
2024-02-29 11:30:24 - INFO - Modem not registered, retry in 2 seconds
2024-02-29 11:30:26 - INFO - Modem not registered, retry in 2 seconds
2024-02-29 11:30:28 - INFO - Modem not registered, retry in 2 seconds
2024-02-29 11:30:31 - INFO - Modem not registered, retry in 2 seconds
2024-02-29 11:30:33 - INFO - Modem not registered, retry in 2 seconds
2024-02-29 11:30:35 - INFO - Modem not registered, retry in 2 seconds
2024-02-29 11:30:37 - INFO - Modem not registered, retry in 2 seconds
2024-02-29 11:30:39 - INFO - Modem not registered, retry in 2 seconds
2024-02-29 11:30:41 - INFO - Modem not registered, retry in 2 seconds
2024-02-29 11:30:43 - INFO - Modem not registered, retry in 2 seconds
2024-02-29 11:30:45 - INFO - Modem not registered, retry in 2 seconds
2024-02-29 11:30:47 - INFO - Modem not registered, retry in 2 seconds
2024-02-29 11:30:50 - INFO - Internet not up, retry in 5 seconds
2024-02-29 11:31:01 - INFO - Device have internet
2024-02-29 11:31:02 - INFO - New date set into system & RTC : 24/02/29 4 11:31:02
2024-02-29 11:31:02 - INFO - Init SSH reverse
2024-02-29 11:31:02 - INFO - Next startup scheduled at 2024-02-29 12:00:00
2024-02-29 12:00:20 - INFO - Modem not registered, retry in 2 seconds
2024-02-29 12:00:22 - INFO - Modem not registered, retry in 2 seconds
2024-02-29 12:00:24 - INFO - Modem not registered, retry in 2 seconds
2024-02-29 12:00:26 - INFO - Modem not registered, retry in 2 seconds
2024-02-29 12:00:28 - INFO - Modem not registered, retry in 2 seconds
2024-02-29 12:00:31 - INFO - Modem not registered, retry in 2 seconds
2024-02-29 12:00:33 - INFO - Modem not registered, retry in 2 seconds
2024-02-29 12:00:35 - INFO - Modem not registered, retry in 2 seconds
2024-02-29 12:00:37 - INFO - Modem not registered, retry in 2 seconds
2024-02-29 12:00:39 - INFO - Modem not registered, retry in 2 seconds
2024-02-29 12:00:41 - INFO - Modem not registered, retry in 2 seconds
2024-02-29 12:00:43 - INFO - Modem not registered, retry in 2 seconds
2024-02-29 12:00:45 - INFO - Modem not registered, retry in 2 seconds
2024-02-29 12:00:48 - INFO - Modem not registered, retry in 2 seconds
2024-02-29 12:00:50 - INFO - Internet not up, retry in 5 seconds
2024-02-29 12:01:01 - INFO - Device have internet
2024-02-29 12:01:03 - INFO - New date set into system & RTC : 24/02/29 4 12:01:03
2024-02-29 12:01:03 - INFO - Init SSH reverse
2024-02-29 12:01:03 - INFO - Next startup scheduled at 2024-02-29 12:30:00
2024-02-29 12:01:09 - INFO - handleUploadRotate - Upload success
2024-02-29 12:01:09 - INFO - handleUploadRotate - Files removed
                                                                                                                                                                                                                                                                                                                                        2024-03-04 08:12:31 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 08:12:33 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 08:12:36 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 08:12:38 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 08:12:40 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 08:12:42 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 08:12:44 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 08:12:46 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 08:12:48 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 08:12:50 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 08:12:52 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 08:12:55 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 08:12:57 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 08:12:59 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 08:13:01 - INFO - Internet not up, retry in 5 seconds
2024-03-04 08:13:12 - INFO - Device have internet
2024-03-04 08:13:40 - INFO - New date set into system & RTC : 24/03/04 1 08:13:40
2024-03-04 08:13:40 - INFO - Init SSH reverse
2024-03-04 08:13:40 - INFO - Next startup scheduled at 2024-03-04 09:00:00
2024-03-04 09:00:20 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 09:00:22 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 09:00:24 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 09:00:26 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 09:00:29 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 09:00:31 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 09:00:33 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 09:00:35 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 09:00:37 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 09:00:39 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 09:00:41 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 09:00:43 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 09:00:45 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 09:00:47 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 09:00:50 - INFO - Internet not up, retry in 5 seconds
2024-03-04 09:01:01 - INFO - Device have internet
2024-03-04 09:01:02 - INFO - New date set into system & RTC : 24/03/04 1 09:01:02
2024-03-04 09:01:02 - INFO - Init SSH reverse
2024-03-04 09:01:02 - INFO - Next startup scheduled at 2024-03-04 10:00:00
2024-03-04 10:00:21 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 10:00:23 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 10:00:25 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 10:00:27 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 10:00:29 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 10:00:32 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 10:00:34 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 10:00:36 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 10:00:38 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 10:00:40 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 10:00:42 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 10:00:44 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 10:00:46 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 10:00:48 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 10:00:51 - INFO - Internet not up, retry in 5 seconds
2024-03-04 10:01:02 - INFO - Device have internet
2024-03-04 10:01:03 - INFO - New date set into system & RTC : 24/03/04 1 10:01:03
2024-03-04 10:01:03 - INFO - Init SSH reverse
2024-03-04 10:01:03 - INFO - Next startup scheduled at 2024-03-04 11:00:00
2024-03-04 10:01:11 - INFO - handleUploadRotate - Upload success
2024-03-04 10:01:11 - INFO - handleUploadRotate - Files removed
2024-03-04 11:00:21 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 11:00:23 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 11:00:25 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 11:00:27 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 11:00:29 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 11:00:31 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 11:00:34 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 11:00:36 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 11:00:38 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 11:00:40 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 11:00:42 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 11:00:44 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 11:00:46 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 11:00:48 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 11:00:51 - INFO - Internet not up, retry in 5 seconds
2024-03-04 11:01:02 - INFO - Device have internet
2024-03-04 11:01:07 - INFO - New date set into system & RTC : 24/03/04 1 11:01:07
2024-03-04 11:01:07 - INFO - Init SSH reverse
2024-03-04 11:01:07 - INFO - Next startup scheduled at 2024-03-04 12:00:00
2024-03-04 12:00:21 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 12:00:23 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 12:00:25 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 12:00:27 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 12:00:29 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 12:00:31 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 12:00:34 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 12:00:36 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 12:00:38 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 12:00:40 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 12:00:42 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 12:00:44 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 12:00:46 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 12:00:48 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 12:00:51 - INFO - Internet not up, retry in 5 seconds
2024-03-04 12:01:02 - INFO - Device have internet
2024-03-04 12:01:08 - INFO - New date set into system & RTC : 24/03/04 1 12:01:08
2024-03-04 12:01:08 - INFO - Init SSH reverse
2024-03-04 12:01:08 - INFO - Next startup scheduled at 2024-03-04 13:00:00
2024-03-04 13:00:20 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 13:00:22 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 13:00:24 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 13:00:26 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 13:00:29 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 13:00:31 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 13:00:33 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 13:00:35 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 13:00:37 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 13:00:39 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 13:00:41 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 13:00:43 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 13:00:45 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 13:00:48 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 13:00:50 - INFO - Internet not up, retry in 5 seconds
2024-03-04 13:01:01 - INFO - Device have internet
2024-03-04 13:01:02 - INFO - New date set into system & RTC : 24/03/04 1 13:01:02
2024-03-04 13:01:02 - INFO - Init SSH reverse
2024-03-04 13:01:02 - INFO - Next startup scheduled at 2024-03-04 14:00:00
2024-03-04 13:01:11 - INFO - handleUploadRotate - Upload success
2024-03-04 13:01:11 - INFO - handleUploadRotate - Files removed
2024-03-04 14:00:21 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 14:00:23 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 14:00:25 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 14:00:27 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 14:00:29 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 14:00:32 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 14:00:34 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 14:00:36 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 14:00:38 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 14:00:40 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 14:00:42 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 14:00:44 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 14:00:46 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 14:00:48 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 14:00:51 - INFO - Internet not up, retry in 5 seconds
2024-03-04 14:01:02 - INFO - Device have internet
2024-03-04 14:01:03 - INFO - New date set into system & RTC : 24/03/04 1 14:01:03
2024-03-04 14:01:03 - INFO - Init SSH reverse
2024-03-04 14:01:03 - INFO - Next startup scheduled at 2024-03-04 15:00:00
2024-03-04 15:00:21 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 15:00:23 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 15:00:25 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 15:00:27 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 15:00:30 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 15:00:32 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 15:00:34 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 15:00:36 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 15:00:38 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 15:00:40 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 15:00:42 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 15:00:44 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 15:00:46 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 15:00:49 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 15:00:51 - INFO - Internet not up, retry in 5 seconds
2024-03-04 15:01:02 - INFO - Device have internet
2024-03-04 15:01:02 - INFO - New date set into system & RTC : 24/03/04 1 15:01:02
2024-03-04 15:01:02 - INFO - Init SSH reverse
2024-03-04 15:01:02 - INFO - Next startup scheduled at 2024-03-04 16:00:00
2024-03-04 16:00:21 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 16:00:23 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 16:00:25 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 16:00:27 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 16:00:30 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 16:00:32 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 16:00:34 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 16:00:36 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 16:00:38 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 16:00:40 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 16:00:42 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 16:00:44 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 16:00:46 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 16:00:49 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 16:00:51 - INFO - Internet not up, retry in 5 seconds
2024-03-04 16:01:02 - INFO - Device have internet
2024-03-04 16:01:04 - INFO - New date set into system & RTC : 24/03/04 1 16:01:04
2024-03-04 16:01:04 - INFO - Init SSH reverse
2024-03-04 16:01:04 - INFO - Next startup scheduled at 2024-03-04 17:00:00
2024-03-04 16:01:12 - INFO - handleUploadRotate - Upload success
2024-03-04 16:01:12 - INFO - handleUploadRotate - Files removed
2024-03-04 17:00:21 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 17:00:23 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 17:00:25 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 17:00:27 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 17:00:29 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 17:00:32 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 17:00:34 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 17:00:36 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 17:00:38 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 17:00:40 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 17:00:42 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 17:00:44 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 17:00:46 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 17:00:48 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 17:00:51 - INFO - Internet not up, retry in 5 seconds
2024-03-04 17:01:02 - INFO - Device have internet
2024-03-04 17:01:02 - INFO - New date set into system & RTC : 24/03/04 1 17:01:02
2024-03-04 17:01:02 - INFO - Init SSH reverse
2024-03-04 17:01:02 - INFO - Next startup scheduled at 2024-03-04 18:00:00
2024-03-04 18:00:20 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 18:00:22 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 18:00:24 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 18:00:26 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 18:00:29 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 18:00:31 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 18:00:33 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 18:00:35 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 18:00:37 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 18:00:39 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 18:00:41 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 18:00:43 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 18:00:45 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 18:00:47 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 18:00:50 - INFO - Internet not up, retry in 5 seconds
2024-03-04 18:01:01 - INFO - Device have internet
2024-03-04 18:01:02 - INFO - New date set into system & RTC : 24/03/04 1 18:01:02
2024-03-04 18:01:02 - INFO - Init SSH reverse
2024-03-04 18:01:02 - INFO - Next startup scheduled at 2024-03-04 19:00:00
2024-03-04 19:00:20 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 19:00:22 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 19:00:24 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 19:00:26 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 19:00:28 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 19:00:31 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 19:00:33 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 19:00:35 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 19:00:37 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 19:00:39 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 19:00:41 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 19:00:43 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 19:00:45 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 19:00:47 - INFO - Modem not registered, retry in 2 seconds
2024-03-04 19:00:50 - INFO - Internet not up, retry in 5 seconds
2024-03-04 19:01:01 - INFO - Device have internet
2024-03-04 19:01:02 - INFO - New date set into system & RTC : 24/03/04 1 19:01:02
2024-03-04 19:01:02 - INFO - Init SSH reverse
2024-03-04 19:01:02 - INFO - Next startup scheduled at 2024-03-04 20:00:00

On peut améliorer comment la connexion internet, la boucle est quand même importante à chaque connexion non?

Bonjour,

Dans le script il y a 13 fonctions de définies, hors 4 fonctions (isInternetUp, dec2bcd,
bcd2dec, handleShutdown, et surtout takeNewPicture) ne sont jamais appelées. Si take NewPicture n’est jamais appellé alors le script ne prend jamais de photos !
De plus dans la partie « # ------------ START SCRIPT ------------ » il y a un « try: » et il n’y a pas de « execpt: », toutefois mes compétences en Python ne permettent pas d’affirmer que c’est obligatoire, mais j’ai un doute.

Dans la log on voit bien un saut de 2024-02-29 12:01:09 à 2024-03-04 08:13:01, il n’y a pas d’information de plantage. Rien ne dit donc que ce soit le script qui plante, ni le contraire.
Si le script plante je ne pense pas qu’il soit en mesure de toute manière d’appeler la fonction « handleShutdown », car si il est planté, il n’aura les ressources pour l’appeler !

Si on est bien dans le cas d’un plantage du script, je recommande de mettre en place une sorte de watchdog externe. Pour cela, il faut écrire une fonction qui écrit périodiquement dans un fichier, et un autre programme qui vérifie si le fichier n’est pas mis à jour depuis un certain temps, alors provoquer un arrêt/relance soit du script, soit du PI. Voir avec le développeur pour modifier cela.

Pour l’optimisation de la connexion internet, je pense qu’il faut voir avec le développeur du script, car à mon niveau, je n’ai pas les compétences.

Sinon, pour avoir plus de détail, vous pouvez modifier votre script pour ajouter plus d’informations en log en ajoutant pleins de lignes « log(« DEBUG », « Texte du debug ») » précisant chaque étape réalisée. Ainsi la log sera beaucoup plus verbeuse, mais vous devriez voir mieux ce qui se passe.

A+