Create a gist now

Instantly share code, notes, and snippets.

const rpi433 = require('rpi-433');
// Instantiate rpi433 lib with a pulse length that matches my RF Outlet remote control
const rfEmitter = rpi433.emitter({
pin: 0,
pulseLength: 176
});
// Codes have been altered to nobody can come to my house and turn off the lights.
const code = {
1: { on: 9830000 , off: 9830000 },
2: { on: 9830000 , off: 9830000 },
3: { on: 9830000 , off: 9830000 },
4: { on: 9830000 , off: 9830000 },
5: { on: 9830000 , off: 9830000 },
};
const LAMP = 2;
const FEEDER = 3;
const XMAS = 1; // Broken :(
const BEDLAMP = 4;
const NOISE_MACHINE = 5;
// Export a function that takes one of the above objects (e.g. LAMP) and an 'on' or 'off'.
function rfCommand(object, state) {
return new Promise( function(resolve, reject) {
rfEmitter.sendCode(code[object][state], function(error, stdout){
if(error) {
console.log(error);
return;
}
console.log('Success: ' + stdout);
});
});
}
module.exports = {
LAMP,
FEEDER,
XMAS,
BEDLAMP,
NOISE_MACHINE,
rfCommand
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment