-
-
Save domadev812/1da7990bf7b10c145b75a7c82668b23b 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" }; | |
var publishConfig = { | |
channel : 'gpio-raspberry-control', | |
message : pubmsg | |
} | |
pubnub.publish(publishConfig, function(status, response) { | |
console.log(status, response); | |
}) | |
}); |
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.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'] | |
}); |
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().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