jdz/door.py
2024-07-05 09:05:28 -06:00

32 lines
630 B
Python

#!/usr/bin/python
# -*- coding:utf-8 -*-
import time, os
import paho.mqtt.client as mqtt
import RPi.GPIO as GPIO
# MQTT Broker settings
mqttBroker ="65.108.199.212"
myhost = os.uname()[1]
client = mqtt.Client(myhost)
client.connect(mqttBroker, 1883)
# Set up GPIO mode (BCM numbering)
GPIO.setmode(GPIO.BCM)
# Define pin numbers
PIN_17 = 17
PIN_18 = 18
# Set GPIO
GPIO.setup(PIN_17, GPIO.IN)
GPIO.setup(PIN_18, GPIO.OUT)
while True:
if GPIO.input(PIN_17) == GPIO.HIGH:
print("Puerta abierta")
GPIO.output(PIN_18, GPIO.HIGH) # Luz Roja encendida
else:
GPIO.output(PIN_18, GPIO.LOW)