Last active
October 18, 2017 19:33
-
-
Save shyampurk/7fbda54395b7a01d0d9c to your computer and use it in GitHub Desktop.
pubnub_iot_tech_uc_1
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
$('#toggle').click(function(e){ | |
pubmsg = { "req" : "toggle" }; | |
pubnub.publish( | |
{ | |
channel : 'gpio-raspberry-control' , | |
message : pubmsg | |
} | |
); | |
}); |
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
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'); | |
} | |
} | |
} | |
}); |
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
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