diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f842932 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ + +node_modules/ + +.DS_Store +._* diff --git a/README.md b/README.md index fb054da..8787233 100644 --- a/README.md +++ b/README.md @@ -11,9 +11,30 @@ Project Structure: Circuit diagrams are drawn with this [Circuit Simulator](http://www.falstad.com/circuit/).
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.
-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 diff --git a/embedded/.npmrc b/embedded/.npmrc new file mode 100644 index 0000000..2ae2317 --- /dev/null +++ b/embedded/.npmrc @@ -0,0 +1 @@ +loglevel=silent diff --git a/embedded/doorlock.service b/embedded/doorlock.service new file mode 100644 index 0000000..c4e9e9d --- /dev/null +++ b/embedded/doorlock.service @@ -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 diff --git a/embedded/index.js b/embedded/index.js new file mode 100644 index 0000000..a00b136 --- /dev/null +++ b/embedded/index.js @@ -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 ==='); diff --git a/embedded/package.json b/embedded/package.json new file mode 100644 index 0000000..f89d76e --- /dev/null +++ b/embedded/package.json @@ -0,0 +1,8 @@ +{ + "scripts": { + "start": "node index.js" + }, + "dependencies": { + "simple-node-logger": "^0.93.12" + } +}