var http = require('http');
var express = require('express');
var lockedState = 2200;
var unlockedState = 500;
var motorPin = 14;
var buttonPin = 17;
var app = express();
// *** Start code *** //
var locked = true;
//Setup servo
var Gpio = require(
motor = new Gpio(motorPin, {mode: Gpio.OUTPUT});
//setup button
button = new Gpio(buttonPin, {mode: Gpio.INPUT,
pullUpDown: Gpio.PUD_DOWN,
edge: Gpio.EITHER_EDGE
}),
servo = new Gpio(motorPin, {mode: Gpio.OUTPUT});
button.on('interrupt', function () {
motor.servoWrite(lockedState);
setTimeout(function(){motor.servoWrite(0)}, 2000);
});
// ------------------------------------------------------------------------
// configure Express to serve index.html and any other static pages stored
// in the home directory
app.use(express.static(__dirname));
//lock rest get call
app.get('/uit', function (req, res) {
motor.servoWrite(lockedState);
locked = true;
res.send('uit')
console.log('uit gezet')
//After 1.5 seconds, the door lock servo turns off to avoid stall current
setTimeout(function(){motor.servoWrite(0)}, 2000);
});
//unlock rest get call
app.get('/aan', function (req, res){
motor.servoWrite(unlockedState);
locked = false;
res.send('aan')
console.log('aan gezet')
//After 1.5 seconds, the door lock servo turns off to avoid stall current
setTimeout(function(){motor.servoWrite(0)}, 2000)
});
// ------------------------------------------------------------------------
// Start Express App Server
//
app.listen(3000);
console.log('App Server is listening on port 3000');