From 7dd97c564d295a47cf4c797d87818877a2512f82 Mon Sep 17 00:00:00 2001 From: geremy cohen Date: Fri, 19 Dec 2014 21:52:47 -0800 Subject: LED on pin 12 off/on via PN --- python/examples/pnLED.py | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 python/examples/pnLED.py (limited to 'python/examples/pnLED.py') diff --git a/python/examples/pnLED.py b/python/examples/pnLED.py new file mode 100644 index 0000000..0da8f25 --- /dev/null +++ b/python/examples/pnLED.py @@ -0,0 +1,41 @@ +from Pubnub import Pubnub +import RPi.GPIO as GPIO ## Import GPIO library + +GPIO.setmode(GPIO.BOARD) ## Use board pin numbering +GPIO.setup(12, GPIO.OUT) ## Setup GPIO Pin 7 to OUT +GPIO.output(12,True) ## Turn on GPIO pin 7 + +pubnub = Pubnub(publish_key="demo-36", subscribe_key="demo-36", ssl_on=False) + +# Listen for Messages + +channel = 'rpi_1' + +def callback(message, channel): + print(message) + + if (message['command'] == "led_off"): + GPIO.output(12,False) + elif (message['command'] == "led_on"): + GPIO.output(12,True) + + + +def error(message): + print("ERROR : " + str(message)) + + +def connect(message): + print("CONNECTED") + + +def reconnect(message): + print("RECONNECTED") + + +def disconnect(message): + print("DISCONNECTED") + + +pubnub.subscribe(channel, callback=callback, error=callback, + connect=connect, reconnect=reconnect, disconnect=disconnect) -- cgit v1.2.3