diff --git a/sensor.py b/sensor.py index 02995c5..6912e4f 100644 --- a/sensor.py +++ b/sensor.py @@ -21,7 +21,7 @@ def on_motion_detected(channel): print("Motion Detected!") client.publish(MQTT_TOPIC, "Motion Detected") - + # Add event detection on the PIR pin GPIO.add_event_detect(PIR_PIN, GPIO.RISING, callback=on_motion_detected) @@ -30,4 +30,10 @@ def on_motion_detected(channel): time.sleep(2) # to stabilize sensor print("Ready") + # Keep the script running + while True: + time.sleep(1) +except KeyboardInterrupt: + print("Quit") + GPIO.cleanup() \ No newline at end of file