Author: Not specified Language: javascript
Description: Not specified Timestamp: 2017-09-01 00:00:31 +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;
}
View raw paste Reply