Author: Not specified Language: text
Description: Not specified Timestamp: 2017-08-31 23:58:29 +0000
View raw paste Reply
  1.         device.on('connect', function() {
  2.             console.log('Connected: ', +new Date());
  3.             const watchButtonPressEverySecond = _.debounce(watchButtonPress, config.DEBOUNCE_MS);
  4.             rpio.open(config.BUTTON_PIN, rpio.INPUT, rpio.PULL_UP);
  5.             rpio.poll(config.BUTTON_PIN, watchButtonPressEverySecond, rpio.POLL_LOW);
  6.         });
  7.  
  8.  
  9.         function watchButtonPress(pin) {
  10.             const pressedState = getPressedState(pin);
  11.             const desiredObject = getDesiredObject(pressedState);
  12.             device.publish(`$aws/things/${config.clientId}/update`, desiredObject);
  13.             console.log('Published: ', +new Date(), desiredObject);
  14.         }
  15.  
  16.         function getPressedState(pin) {
  17.             const state = rpio.read(pin) ? PRESSED : UNPRESSED;
  18.             return state;
  19.         }
  20.  
  21.         function watchButtonPress(pin) {
  22.             const pressedState = getPressedState(pin);
  23.             const desiredObject = getDesiredObject(pressedState);
  24.             device.publish(`$aws/things/${config.clientId}/update`, desiredObject);
  25.             console.log('Published: ', +new Date(), desiredObject);
  26.         }
  27.  
  28.         function getPressedState(pin) {
  29.             const state = rpio.read(pin) ? PRESSED : UNPRESSED;
  30.             return state;
  31.         }
View raw paste Reply