-
-
Save domadev812/29c19cfa4022a6bc4a436e1f0a6b673e to your computer and use it in GitHub Desktop.
Code samples for IoT 101 with Raspberry Pi Blog: http://www.pubnub.com/blog/internet-of-things-101-getting-started-w-raspberry-pi/
This file contains 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
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) |
This file contains 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
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) |
This file contains 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
var channel = 'disco'; | |
pubnub = new PubNub({ | |
publishKey : 'demo', | |
subscribeKey : 'demo' | |
}) |
This file contains 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
<script src="https://cdn.pubnub.com/sdk/javascript/pubnub.4.17.0.js"></script> |
This file contains 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
<button>Disco on!</button> |
This file contains 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
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); |
This file contains 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
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'], | |
}); |
This file contains 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
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