Created
February 26, 2017 01:05
-
-
Save ericterpstra/3119f89dac874e1a37676a1c43f5f159 to your computer and use it in GitHub Desktop.
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
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