Skip to content

Commit

Permalink
implement simple door controller
Browse files Browse the repository at this point in the history
implement simple door controller
  • Loading branch information
akiroz authored Aug 11, 2016
2 parents 275e740 + bffeaba commit f5b5dce
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

node_modules/

.DS_Store
._*
27 changes: 24 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,30 @@ Project Structure:
Circuit diagrams are drawn with this [Circuit Simulator](http://www.falstad.com/circuit/).<br/>
Diagrams are saved as `txt` files, you can import them under `File > Import From Text`.

Embedded System: Raspberry Pi 3.
Relay Board:
![](https://github.com/oursky/doorlock/raw/master/embedded/circuit.png)

The release button should be connected between a GPIO pin and ground.<br/>
The GPIO pin should be configured as an input **with internal pull-up**.
Embedded System: Raspberry Pi 3

Connections:
* Release Button: GPIO0/Ground
* Release Signal: GPIO1/Ground

## Embedded System
**System:** ArchLinux ARM

**Dependencies:**
* nodejs
* npm
* wiringpi-git (AUR)

**Install as systemd service:**
```
[oursky ~/]$ git clone ...
[oursky ~/]$ sudo cp doorlock/embedded/doorlock.service /etc/systemd/system/
[oursky ~/]$ sudo systemctl enable doorlock
[oursky ~/]$ sudo systemctl start doorlock
```
**Note: ** If your username is not `oursky`, you need to edit `doorlock.service` accordingly.

## App
1 change: 1 addition & 0 deletions embedded/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
loglevel=silent
10 changes: 10 additions & 0 deletions embedded/doorlock.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[Unit]
Description=Doorlock Controller Daemon

[Service]
User=oursky
WorkingDirectory=/home/oursky/doorlock/embedded
ExecStart=/usr/bin/npm start

[Install]
WantedBy=multi-user.target
22 changes: 22 additions & 0 deletions embedded/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const exec = require('child_process').exec;
const execSync = require('child_process').execSync;
const setTimeout = require('timers').setTimeout;
const log = require('simple-node-logger').createSimpleLogger();

execSync('gpio mode 0 up');
execSync('gpio mode 1 out');

function openDoor() {
execSync('gpio write 1 1');
setTimeout(_ => execSync('gpio write 1 0'), 3000);
}

(function listenButton() {
exec('gpio wfi 0 rising').on('exit', _ => {
log.info('Unlocked via Button');
openDoor();
setTimeout(_ => listenButton(), 500);
})
})()

log.info('=== Daemon Started ===');
8 changes: 8 additions & 0 deletions embedded/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"scripts": {
"start": "node index.js"
},
"dependencies": {
"simple-node-logger": "^0.93.12"
}
}

0 comments on commit f5b5dce

Please sign in to comment.