aboutsummaryrefslogtreecommitdiffstats
path: root/python/examples/pnLED.py
diff options
context:
space:
mode:
authorgeremy cohen2014-12-19 21:52:47 -0800
committergeremy cohen2014-12-19 21:52:47 -0800
commit7dd97c564d295a47cf4c797d87818877a2512f82 (patch)
treefc72e05424b366a4dacae756034de3dd1483bd74 /python/examples/pnLED.py
parent1ecaa93e2ec929ca8ebc185dbdde46d649da7534 (diff)
downloadpubnub-python-7dd97c564d295a47cf4c797d87818877a2512f82.tar.bz2
LED on pin 12 off/on via PN
Diffstat (limited to 'python/examples/pnLED.py')
-rw-r--r--python/examples/pnLED.py41
1 files changed, 41 insertions, 0 deletions
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)