Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import paho.mqtt.publish as publish
- import time
- import RPi.GPIO as GPIO
- # QUI SOTTO INSERIRE L'INDIRIZZO IP DEL VOSTRO SERVER MQTT
- #
- host_mqtt="192.168.xxx.xxx"
- GPIO.setmode(GPIO.BCM)
- GPIO.setwarnings(False)
- pulsante = 21 # PULSANTE
- tempo_pressione = 1.3
- GPIO.setup(pulsante, GPIO.IN, pull_up_down=GPIO.PUD_UP)
- print("pulsante avviato")
- while True:
- if (GPIO.input(pulsante)==0):
- publish.single("pulsante_12v", ("on"), hostname= host_mqtt)
- print("premuto")
- while (GPIO.input(pulsante)==0):
- time.sleep (0.3)
- publish.single("pulsante_12v", ("off"), hostname= host_mqtt)
- print("lasciato")
- time.sleep(0.2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement