Need your caffeine? See if there's a fresh brew ready using Lee's project:
http://www.brockclan.com/coffeeStatus.html
Lee's wife can turn on the sign remotely, using a private version with a button in place of the status indicator. (Unfortunately, just clicking the button will not manifest hot coffee.)
Untitled file
Warning: Embedding code files within the project story has been deprecated. To edit this file or add more files, go to the "Software" tab. To remove this file from the story, click on it to trigger the context menu, then click the trash can button (this won't delete it from the "Software" tab).
var api = pinoccioAPI();
//Usage:
//1. Put your main api.token in the approprate spot.
//2. Put the appropriate troopId, scoutId, pinType 'digital' or 'analog' an pinNum
//3. put the name of the command you wish your troop to run when the button is pushed.
// to make a toggle command in HQ: function toggle {d2=!d2;} //toggles pin d2 the pin.
api.token = "YourTokenHere";
var troopId = 2;
var scoutId = 1;
var pinType = 'digital';
var pinNum = 0;// d2=0, d3=1, d4=2 etc.
var command = "toggle";
// when a button is clicked run the funtcion tog()
$("button").click(function () {
tog();
})
// change the pin state in HQ and check to see if it is updated on this page!
// when the button is clicked the scout is given instructions to run the "toggle" command.
function tog() {
//toggle command on scout--- function toggle {d2=!d2;} //toggles pin "d2"
api.rest({
url: "/v1/" + troopId + "/" + scoutId + "/command",
data: {
command: command
}
}, function (error, result) {
// this is where you find out of the command was successful if(!error)
// and read the result. for commands that print results.
if (error) return $("#out").text('ERROR: ' + (error.message || error + ''));
// setting the led does not print a result.
$("#out").html("success!");
})
$("#out").text("sending command " + command + " to troop " + troopId + " and scout " + scoutId);
}
// make a sync stream so we know the real state of pin.
api.sync({stale: 1}).on('data', function (data) {
// is this is an event for the troop and scout im interested in?
// the sync returns a lot of data... you could choose nearly any variable to look at.
if (data.type == pinType && data.troop == troopId && data.scout == scoutId) {
// read the pin values for the particular scout.
var pins = data.value.state;
var status;
//The following checks the status on a pin
//in the "pinType" data.type / data.value.state. d2=0, d3=1, d4=2, etc
//then runs logical test and changes status based on pin state.
if (pins[pinNum] == 1) {
//change the status message
status = "AWESOME";
//or change the status image
document.getElementById("sign").src = "http://brockclan.com/on.jpg";
} else {
status = "BUMMER";
document.getElementById("sign").src = "http://brockclan.com/off.jpg";
}
// set text based on "stale" events are stale when they have occured before the last online time.
// its the last recorded value but it may not be the current state.
var text = status + "!";
if (data.stale) text = "last known" + status + "!";
$("#coffee").text(text);
$(signPic).slideToggle( "slow", function(){
});
}
}).on('error', function (error) {
$("#error").text('sync error. ' + (error.message || error + ''));
})
var api = pinoccioAPI();
//Usage:
//1. Put your main api.token in the approprate spot.
//2. Put the appropriate troopId, scoutId, pinType 'digital' or 'analog' an pinNum
//3. put the name of the command you wish your troop to run when the button is pushed.
// to make a toggle command in HQ: function toggle {d2=!d2;} //toggles pin d2 the pin.
api.token = "YourTokenHere";
var troopId = 2;
var scoutId = 1;
var pinType = 'digital';
var pinNum = 0;// d2=0, d3=1, d4=2 etc.
var command = "toggle";
// when a button is clicked run the funtcion tog()
$("button").click(function () {
tog();
})
// change the pin state in HQ and check to see if it is updated on this page!
// when the button is clicked the scout is given instructions to run the "toggle" command.
function tog() {
//toggle command on scout--- function toggle {d2=!d2;} //toggles pin "d2"
api.rest({
url: "/v1/" + troopId + "/" + scoutId + "/command",
data: {
command: command
}
}, function (error, result) {
// this is where you find out of the command was successful if(!error)
// and read the result. for commands that print results.
if (error) return $("#out").text('ERROR: ' + (error.message || error + ''));
// setting the led does not print a result.
$("#out").html("success!");
})
$("#out").text("sending command " + command + " to troop " + troopId + " and scout " + scoutId);
}
// make a sync stream so we know the real state of pin.
api.sync({stale: 1}).on('data', function (data) {
// is this is an event for the troop and scout im interested in?
// the sync returns a lot of data... you could choose nearly any variable to look at.
if (data.type == pinType && data.troop == troopId && data.scout == scoutId) {
// read the pin values for the particular scout.
var pins = data.value.state;
var status;
//The following checks the status on a pin
//in the "pinType" data.type / data.value.state. d2=0, d3=1, d4=2, etc
//then runs logical test and changes status based on pin state.
if (pins[pinNum] == 1) {
//change the status message
status = "AWESOME";
//or change the status image
document.getElementById("sign").src = "http://brockclan.com/on.jpg";
} else {
status = "BUMMER";
document.getElementById("sign").src = "http://brockclan.com/off.jpg";
}
// set text based on "stale" events are stale when they have occured before the last online time.
// its the last recorded value but it may not be the current state.
var text = status + "!";
if (data.stale) text = "last known" + status + "!";
$("#coffee").text(text);
$(signPic).slideToggle( "slow", function(){
});
}
}).on('error', function (error) {
$("#error").text('sync error. ' + (error.message || error + ''));
})
Lee Brock
Posted by
Alex Glow

Comments