# Python light switch model #raspberry PI GPIO test. Very fun, very crude. #import the library that allows us to access the GPIO pins #alias it to GPIO to make things simpler import RPi.GPIO as GPIO import socket #Use the BCM pin numbering scheme GPIO.setmode(GPIO.BCM) # Since a few apps may try to set the GPIO pins, want to turn warning off GPIO.setwarnings(False) # pin 23 controls one relay (for the motion lights) #pin 24 controls the relay for the outside door lights # set them both High to turn relay, and hence the lights, on GPIO.setup(23, GPIO.OUT) GPIO.output(23, GPIO.HIGH) GPIO.setup(24, GPIO.OUT) GPIO.output(24, GPIO.HIGH) # now need to let the slave Pi know to turn it's relay on # we will do it with a basic socket connect on port 1237 (we picked at random) s = socket.socket() # Create a socket object port = 1237 # Reserve a port for your service. # 192.168.0.101 is the address we have given our Slave Pi on this light project s.connect(('192.168.0.101', port)) s.close() # we simply make a connection, the far side sees it, turns the lights on # then we close the connection