#! /usr/bin/env python # -*- coding: utf-8 -*- import RPi.GPIO as GPIO import time import socket sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) CONNECT_TO = ("10.0.0.4", 2000) def buttonEventHandler(value): if value is 0: GPIO.output(24, True) sock.sendall("button_press") print('Button Pressed...') else: GPIO.output(24, False) sock.sendall("button_release") print('Button Released...') def main(): print "Let's do this!" GPIO.setmode(GPIO.BCM) GPIO.setup(23, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.setup(24, GPIO.OUT) #GPIO.add_event_detect(23, GPIO.FALLING) #GPIO.add_event_callback(23, buttonEventHandler) try: sock.connect(CONNECT_TO) while True: GPIO.wait_for_edge(23, GPIO.BOTH, bouncetime=100) buttonEventHandler(GPIO.input(23)) except: GPIO.cleanup() sock.close() raise if __name__== "__main__": main()