Skip to content

Instantly share code, notes, and snippets.

@domadev812
Forked from shyampurk/pubnub-js-publish
Last active November 15, 2017 21:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save domadev812/1da7990bf7b10c145b75a7c82668b23b to your computer and use it in GitHub Desktop.
Save domadev812/1da7990bf7b10c145b75a7c82668b23b to your computer and use it in GitHub Desktop.
pubnub_iot_tech_uc_1
$('#toggle').click(function(e){
pubmsg = { "req" : "toggle" };
var publishConfig = {
channel : 'gpio-raspberry-control',
message : pubmsg
}
pubnub.publish(publishConfig, function(status, response) {
console.log(status, response);
})
});
pubnub.addListener({
status: function(statusEvent) {
if (statusEvent.category === "PNConnectedCategory") {
publishSampleMessage();
}
},
message: function(message) {
if('resp' in message) {
if('on' == message['resp']){
$('#led').removeClass('dim');
$('#led').addClass('glow');
} else {
$('#led').removeClass('glow');
$('#led').addClass('dim');
}
}
},
presence: function(presenceEvent) {
// handle presence
}
})
console.log("Subscribing..");
pubnub.subscribe({
channels: ['gpio-raspberry-control']
});
glow = False
#PubNub Channel Subscribe Callback
def gpioCallback(msg,channel):
global glow
respstring = ''
command = msg
print "Command is : " + str(command)
if('req' in command):
if(command['req'] == 'toggle'):
if(glow):
glow = False;
respstring = 'off'
else:
glow = True
respstring = 'on'
GPIO.output(16, glow)
respmsg = {"resp" : respstring }
pubnub.publish().channel("pubnubChannelName").message(respmsg).async(my_publish_callback)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment