Skip to content

Instantly share code, notes, and snippets.

@shyampurk
Last active October 18, 2017 19:33
Show Gist options
  • Save shyampurk/7fbda54395b7a01d0d9c to your computer and use it in GitHub Desktop.
Save shyampurk/7fbda54395b7a01d0d9c to your computer and use it in GitHub Desktop.
pubnub_iot_tech_uc_1
$('#toggle').click(function(e){
pubmsg = { "req" : "toggle" };
pubnub.publish(
{
channel : 'gpio-raspberry-control' ,
message : pubmsg
}
);
});
pubnub.subscribe({
channel: 'gpio-raspberry-control',
message: function(m){
console.log(m)
if('resp' in m) {
if('on' == m['resp']){
$('#led').removeClass('dim');
$('#led').addClass('glow');
} else {
$('#led').removeClass('glow');
$('#led').addClass('dim');
}
}
}
});
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(pubnubChannelName, respmsg)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment