17 Nov 2017, 10:16

@lackyluuk

Hi bro, I tested my script and it works fine, I can do several RESET, exit,re-enter the game and do it again.

could you please try this:

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"

def retroarch(nwcommand):
	try:
		s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
	except socket.error:
		print 'Failed to create socket'
		sys.exit()
	s.sendto(nwcommand, (IPADDR, PORTNUM))


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

def netcmd(channel):
	retroarch(nwcommand)
    
GPIO.add_event_detect(3, GPIO.BOTH, callback=netcmd, bouncetime=500)

while True:
    time.sleep(0.2)