D-9 Web App JS
Add Starter JS
Add Custom JS
var alertSound = new Audio("notification.wav");
window.setInterval(checkMode, 500);
function checkMode() {
particle.getVariable({ deviceId: myDevice, name: "deviceMode", auth: myToken }).then(function(data) {
// add code to do something with value returned as: data.body.result
if (data.body.result == "armed") {
$("#system-mode").html("ARMED");
$("input[name=toggle]").prop("checked", true);
}
else if (data.body.result == "disarmed") {
$("#system-mode").html("DISARMED");
$("input[name=toggle]").prop("checked", false);
}
}, function(err) {
console.log("An error occurred: ", err);
});
}
function toggleMode() {
particle.callFunction({ deviceId: myDevice, name: "toggleMode", argument: "data", auth: myToken });
}
particle.getEventStream({ deviceId: myDevice, name: "motion", auth: myToken }).then(function(stream) {
stream.on('event', function(feed) {
// add code to do something when event notification received
// any text data received is stored as: feed.data
alertSound.play();
var dateTime = new Date();
dateTime = dateTime.toLocaleString();
$("#event-time").html(dateTime);
$("#motion-alert").show().delay(1500).fadeOut();
});
});Variable for Audio File
Set Interval to Call Function
Get Photon Variable
Call Photon Function
Listen for Event Notifications
Test Web App
