Slexy.org is shutting down and stopped accepting new Pastes on May 4th, 2021.
Existing Pastes will stop being available on or after May 10th, 2021.
Author: Not specified Language: javascript
Description: Not specified Timestamp: 2017-09-01 00:01:45 +0000
View raw paste Reply
device.on('connect', function() {
    console.log('Connected: ', +new Date());
    const watchButtonPressEverySecond = _.debounce(watchButtonPress, config.DEBOUNCE_MS);
    rpio.open(config.BUTTON_PIN, rpio.INPUT, rpio.PULL_UP);
    rpio.poll(config.BUTTON_PIN, watchButtonPressEverySecond, rpio.POLL_LOW);
});


function watchButtonPress(pin) {
    const pressedState = getPressedState(pin);
    const desiredObject = getDesiredObject(pressedState);
    device.publish(`$aws/things/${config.clientId}/update`, desiredObject);
    console.log('Published: ', +new Date(), desiredObject);
}

function getPressedState(pin) {
    const state = rpio.read(pin) ? PRESSED : UNPRESSED;
    return state;
}

function watchButtonPress(pin) {
    const pressedState = getPressedState(pin);
    const desiredObject = getDesiredObject(pressedState);
    device.publish(`$aws/things/${config.clientId}/update`, desiredObject);
    console.log('Published: ', +new Date(), desiredObject);
}

function getPressedState(pin) {
    const state = rpio.read(pin) ? PRESSED : UNPRESSED;
    return state;
}

const PUSH_BUTTON = 2;
const KEY_SWITCH = 1;

module.exports = {
    host: "ao6epnv875g5b.iot.us-east-1.amazonaws.com",
    clientId: "team<TEAM_NUMBER><BUTTON_OR_SWITCH>", //CHANGE
    caPath: "certs/root.crt",
    certPath: "certs/cert.crt",
    keyPath: "certs/privkey.pem",
    region: "us-east-1",
    port: 8883,
    BUTTON_PIN: 40,
    DEBOUNCE_MS: 1000,
    TEAM_NUMBER: < 1 _OR_2 > , //CHANGE
    BUTTON_TYPE: < PUSH_BUTTON_OR_KEY_SWITCH > //CHANGE
}
View raw paste Reply