Skip to content

Instantly share code, notes, and snippets.

@girliemac
Last active October 17, 2017 22:14
Show Gist options
  • Save girliemac/1ac1d6354bbca31438da to your computer and use it in GitHub Desktop.
Save girliemac/1ac1d6354bbca31438da to your computer and use it in GitHub Desktop.
import sys
from pubnub import Pubnub
pubnub = Pubnub(publish_key='<your-pub-key>', subscribe_key='<your-sub-key>')
channel = 'hello-pi'
data = {
'username': 'Your name',
'message': 'Hello World from Pi!'
}
def callback(m):
print(m)
pubnub.publish(channel, data, callback=callback, error=callback)
import RPi.GPIO as GPIO
import time
GPIO.setmode (GPIO.BCM)
LIGHT = 4
GPIO.setup(LIGHT,GPIO.OUT)
while True:
GPIO.output(LIGHT,True)
time.sleep(0.5)
GPIO.output(LIGHT,False)
time.sleep(0.5)
var channel = 'disco';
var p = PUBNUB.init({
subscribe_key: 'your-sub-key',
publish_key: 'your-pub-key'
});
<script src="http://cdn.pubnub.com/pubnub-3.7.1.min.js"></script>
<button>Disco on!</button>
document.querySelector('button').addEventListener('click', function() {
p.publish({
channel : channel,
message : {led: 1} // trigger
});
}, false);
from pubnub import Pubnub
...
pubnub.subscribe(channels='disco', callback=_callback, error=_error)
def _callback(m, channel):
if m['led'] == 1:
for i in range(6):
GPIO.output(LED_PIN,True)
time.sleep(0.5)
GPIO.output(LED_PIN,False)
time.sleep(0.5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment