Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement simple door controller #3

Merged
merged 2 commits into from
Aug 11, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
}
}