0

i m using PIR sensor to find out intruder is present or not. if intruder is present it will go to sleep for 1 min now i have to reset sleep time, for this i m using thread but it shows assertion error, help me out, below is my code.

from threading import Thread, Event
import time

import RPi.GPIO as GPIO


class MyThread(Thread):
    def __ini(self, timeout=60):
        self.intruder_spotted = Event()
        self.timeout = timeout

        self.daemon = True

    def run(self):
        while True:
            if self.intruder_spotted.wait(self.timeout):
                self.intruder_spotted.clear()
                print("Intruder")
            else:
                print("No intruder")



t = MyThread(60)

GPIO.setmode(GPIO.BCM)
GPIO.setup(18,GPIO.IN)

try:
    t.start()
    while True:
        i=GPIO.input(18)
        if i==1:
            t.intruder_spotted.set()

        time.sleep(1)

except KeyboardInterrupt:
    GPIO.cleanup()
    exit(0)
aneeket
  • 126
  • 3
  • 12
  • See https://stackoverflow.com/a/660974/4902099 – hcheung Jun 09 '18 at 11:25
  • 3
    You shoulld edit nto your question the full text of the error message because at the moment no-one apart from you knows which line has the error or the full detail of the error itself. See https://www.stackoverflow.com/mcve. Also, did you mean to have method `__ini()`? This won’t get called. The correct name is `__init__()` And you probably intend to call `__super__()` to ensure the thread is fully initialised. – DisappointedByUnaccountableMod Jun 09 '18 at 12:35

1 Answers1

2

need Update the int of the class my Thread. It's __init__ not __ini. And the call to the parent init with super

class MyThread(Thread): 
    def__init__(self, timeout=60):
    super(MyThread, self).__init__()
    self.intruder_spotted = Event()
    self.timeout = timeout
    self.daemon = True
aneeket
  • 126
  • 3
  • 12