Skript stürzt nach längerer Zeit ab

Wenn du dir nicht sicher bist, in welchem der anderen Foren du die Frage stellen sollst, dann bist du hier im Forum für allgemeine Fragen sicher richtig.
Antworten
staju011
User
Beiträge: 2
Registriert: Donnerstag 5. November 2020, 15:48

Hallo,

ich habe mir einen Skript gebaut, der eine Tür überwacht und sowohl eine Nachricht per Telegram und per UDP schickt.
Beim Testen des Programms klappt das ganze sehr gut. Nach etwas Zeit (ich weiß nicht wie lange) sendet es kein Nachrichten mehr.

Vielleicht habe ich einen riesen Bock gemacht, den ich nicht sehe!

Vielen Dank für eure Hilfe!

Code: Alles auswählen

#!/usr/bin/env python
# -*- encoding: utf-8 -*
import time
import socket
import sys
import telepot
import os
from telepot.loop import MessageLoop
import RPi.GPIO as GPIO


GPIO.setmode(GPIO.BCM)
MAGNET_GPIO = 17
# GPIO Modus zuweisen
GPIO.setup(MAGNET_GPIO, GPIO.IN, pull_up_down=GPIO.PUD_UP)


UDP_IP = "1.1.1.1.1" #Nur fürs Forum, sonst richtiger Wert
UDP_PORT = 50000
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)


#Voreinstellung Telegramm
bot = telepot.Bot('123456789xxxxxxxxxx')
chat_id = xxxxxxxx1111111xxxxx1111111

telemes=0
door_dummy=0


def action(msg):
        chat_id = msg['chat']['id']
        command = msg['text']
        global telemes
        if command == 'Test':
            bot.sendMessage (chat_id, str("Hallo, ich bin die Tür" ))
        if command == 'Neustart':
            bot.sendMessage (chat_id, str("Ich starte neu! Bis gleich!" ))
            time.sleep(1.0)
            os.system("sudo reboot -h now")
        if command == 'Feierabend':
            bot.sendMessage (chat_id, str("Machs gut!" ))
            time.sleep(1)
            os.system("sudo shutdown -h now")
        if command == 'Klingel an':
            bot.sendMessage (chat_id, str("Klingel ist an"))
            telemes=1
        if command == 'Klingel aus':
            bot.sendMessage (chat_id, str("Klingel ist aus"))
            telemes=0



MessageLoop(bot, action).run_as_thread()

while True:
    while True:
        if GPIO.input(MAGNET_GPIO) == 1 and telemes==1 and door_dummy==0:
            bot.sendMessage (chat_id, str("Türalarm!" ))
            sock.sendto('Dooralam', (UDP_IP, UDP_PORT))
            door_dummy=1
        if GPIO.input(MAGNET_GPIO) == 0 and telemes==1 and door_dummy==1 :
            door_dummy=0
Antworten