Last active
August 29, 2015 14:13
-
-
Save rohinip/4ebf495ffbe3ac393b22 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
################## | |
#### pnLED.py #### | |
################## | |
from Pubnub import Pubnub | |
import RPi.GPIO as GPIO ## Import GPIO library | |
GPIO.setmode(GPIO.BOARD) ## Use board pin numbering | |
GPIO.setup(11, GPIO.OUT) ## Setup GPIO Pin 17 to OUT - Green | |
GPIO.setup(12, GPIO.OUT) ## Setup GPIO Pin 18 to OUT - Yellow | |
GPIO.setup(13, GPIO.OUT) ## Setup GPIO Pin 27 to OUT - Red | |
GPIO.output(11,False) ## Turn on GPIO pin 17 | |
GPIO.output(12,False) ## Turn on GPIO pin 18 | |
GPIO.output(13,False) ## Turn on GPIO pin 27 | |
# Enter your PubNub Publish Key and use the Market Order Demo Subscribe Key | |
pubnub = Pubnub(publish_key="YOUR PUB KEY", subscribe_key="sub-c-4377ab04-f100-11e3-bffd-02ee2ddab7fe", ssl_on=False) | |
# Listen for Messages on the Market Order Channel | |
channel = 'pubnub-market-orders' | |
def callback(message, channel): | |
print(message['order_quantity']) # Use the Order Quantity value as the LED trigger | |
# Reset LEDs to OFF | |
GPIO.output(11,False) | |
GPIO.output(12,False) | |
GPIO.output(13,False) | |
if (message['order_quantity'] >= 100) and (message['order_quantity'] < 200): | |
GPIO.output(11,True) # Turn on GREEN | |
elif (message['order_quantity'] >= 200) and (message['order_quantity'] < 400): | |
GPIO.output(12,True) # Turn on YELLOW | |
elif (message['order_quantity'] >= 400): | |
GPIO.output(13,True) # Turn on RED | |
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment