5 Aug 2016, 12:55

full python script with GPIO: (pin 5 and 6)

import RPi.GPIO as GPIO
import time
import socket
# addressing information of target
IPADDR = "127.0.0.1"
PORTNUM = 55355
 
# enter the data content of the UDP packet
COMMAND = "RESET"
 
# initialize a socket, think of it as a cable
# SOCK_DGRAM specifies that this is UDP
try:
    s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
except socket.error:
    print 'Failed to create socket'
    sys.exit()

GPIO.setmode(GPIO.BCM)
GPIO.setup(3, GPIO.IN, pull_up_down=GPIO.PUD_UP)

def exitEmulator(channel):
	s.sendto(COMMAND, (IPADDR, PORTNUM))
    
GPIO.add_event_detect(3, GPIO.FALLING, callback=exitEmulator, bouncetime=500)

while True:
    time.sleep(10)