Skip to content

Instantly share code, notes, and snippets.

@jsquyres
Created November 10, 2014 02:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jsquyres/feb45fe7b34ffe0a034d to your computer and use it in GitHub Desktop.
Save jsquyres/feb45fe7b34ffe0a034d to your computer and use it in GitHub Desktop.
Trivial "status.js" to simply read output from a green bean and print it to stdout
var greenBean = require("green-bean");
function logme(msg, value) {
var currentTime = new Date();
var hours = currentTime.getHours();
var minutes = currentTime.getMinutes();
var seconds = currentTime.getSeconds();
var month = currentTime.getMonth() + 1;
var mday = currentTime.getDate();
var year = currentTime.getFullYear();
if (hours < 10) {
hours = "0" + hours;
}
if (minutes < 10) {
minutes = "0" + minutes;
}
if (seconds < 10) {
seconds = "0" + seconds;
}
if (month < 10) {
month = "0" + month;
}
if (mday < 10) {
mday = "0" + mday;
}
var ctime = year + "-" + month + "-" + mday + " " +
hours + ":" + minutes + ":" + seconds + " ";
console.log(ctime, msg, value);
}
greenBean.connect("laundry", function(laundry) {
laundry.machineStatus.subscribe(function (value) {
logme("machine status changed:", value);
});
laundry.machineSubCycle.subscribe(function (value) {
logme("machine sub-cycle changed:", value);
});
laundry.endOfCycle.subscribe(function (value) {
logme("end of cycle changed:", value);
});
laundry.cycleCount.subscribe(function (value) {
logme("cycle count changed:", value);
});
laundry.dryerServiceErrorCodes.subscribe(function (value) {
logme("dryer service error codes changed:", value);
});
laundry.maximumWaterTemperature.subscribe(function (value) {
logme("maximum water temperature changed:", value);
});
laundry.timeRemainingInSeconds.subscribe(function (value) {
logme("time remaining (seconds) changed:", value);
});
laundry.tankStatus.subscribe(function (value) {
logme("tank status changed:", value);
});
laundry.tankSelected.subscribe(function (value) {
logme("selected tank changed:", value);
});
laundry.cycleSelected.subscribe(function (value) {
logme("selected cycle changed:", value);
});
laundry.operatingMode.subscribe(function (value) {
logme("operating mode changed:", value);
});
laundry.delayTimeRemainingInMinutes.subscribe(function (value) {
logme("delay time remaining (minutes) changed:", value);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment