Skip to content

Instantly share code, notes, and snippets.

@domadev812
Forked from girliemac/01.py
Last active November 15, 2017 21:05
Show Gist options
  • Save domadev812/29c19cfa4022a6bc4a436e1f0a6b673e to your computer and use it in GitHub Desktop.
Save domadev812/29c19cfa4022a6bc4a436e1f0a6b673e to your computer and use it in GitHub Desktop.
import sys
from pubnub.callbacks import SubscribeCallback
from pubnub.pnconfiguration import PNConfiguration
from pubnub.pubnub import PubNub
pnconfig = PNConfiguration()
pnconfig.subscribe_key = "my_subkey"
pnconfig.publish_key = "my_pubkey"
pnconfig.ssl = False
pubnub = PubNub(pnconfig)
channel = 'hello-pi'
data = {
'username': 'Your name',
'message': 'Hello World from Pi!'
}
def publish_callback(result, status):
pass
# Handle PNPublishResult and PNStatus
pubnub.publish().channel(channel).message(['hello', 'there']).async(publish_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';
pubnub = new PubNub({
publishKey : 'demo',
subscribeKey : 'demo'
})
<script src="https://cdn.pubnub.com/sdk/javascript/pubnub.4.17.0.js"></script>
<button>Disco on!</button>
document.querySelector('button').addEventListener('click', function() {
var publishConfig = {
channel : "hello_world",
message : "Hello from PubNub Docs!"
}
pubnub.publish(publishConfig, function(status, response) {
console.log(status, response);
})
}, false);
from pubnub.pubnub import PubNub
...
pubnub.addListener({
status: function(statusEvent) {
},
message: function(message) {
console.log("New Message!!", message);
},
presence: function(presenceEvent) {
// handle presence
}
})
pubnub.subscribe({
channels: ['my_channel'],
});
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