Metadata-Version: 2.1
Name: smartdoor
Version: 2.0.0.dev4
Summary: Smartdoor system including NFC card detecting, key locking/unlocking, turning LED on/off, etc.
Author-email: Koyo Munechika <munechika.koyo@torus.nr.titech.ac.jp>
Maintainer-email: Koyo Munechika <munechika.koyo@torus.nr.titech.ac.jp>
Requires-Python: >=3.9
Description-Content-Type: text/markdown
Classifier: Development Status :: 5 - Production/Stable
Classifier: Environment :: Console
Classifier: Intended Audience :: End Users/Desktop
Classifier: License :: OSI Approved :: BSD License
Classifier: Natural Language :: English
Classifier: Operating System :: POSIX :: Linux
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Topic :: Home Automation
Classifier: Topic :: Security
Requires-Dist: rich-click
Requires-Dist: requests
Requires-Dist: nfcpy
Requires-Dist: gpiozero
Requires-Dist: tomli; python_version < "3.11"
Requires-Dist: flit ; extra == "dev"
Requires-Dist: pytest ; extra == "dev"
Requires-Dist: black ; extra == "dev"
Requires-Dist: ruff ; extra == "dev"
Requires-Dist: mypy ; extra == "dev"
Requires-Dist: pre-commit ; extra == "dev"
Project-URL: Home, https://github.com/munechika-koyo/smartdoor
Provides-Extra: dev

# Smartdoor client system

[![PyPI](https://img.shields.io/pypi/v/smartdoor?label=PyPI&logo=PyPI)](https://pypi.org/project/smartdoor/)
![PyPI - Python Version](https://img.shields.io/pypi/pyversions/smartdoor?logo=Python)

[![GitHub](https://img.shields.io/github/license/munechika-koyo/cherab_phix)](https://opensource.org/licenses/BSD-3-Clause)
[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/charliermarsh/ruff/main/assets/badge/v2.json)](https://github.com/charliermarsh/ruff)

Smartdoor system including NFC card detecting, key locking/unlocking, turning LED on/off, etc. with Raspberry Pi.

## Default circuit diagram
The default circuit diagram is shown below. If you want to use other GPIO pin numbers, please edit the configuration file (see below).

![circuit](docs/circuit.png) not yet updated


## Quick Installation
```bash
sudo python -m pip install smartdoor
```

## Before getting started

### `smartdoor_host` system
Smartdoor Host system which serves the web application for NFC key management must be run. Please
install and deploy it in adavnce. ([see here](https://github.com/munechika-koyo/smartdoor_host)).

### pigpio library
`pigpio` library enables hardware control for PWM signals. This is the optional library for `smartdoor` package. If you want to use it, please install it in advance ([see here](http://abyz.me.uk/rpi/pigpio/download.html)) and run the daemon by the following command:
```bash
sudo pigpiod
```
It is recommended to run the daemon automatically at the system startup. If `pigpio` is installed
and impotable from Python, `smartdoor` package will automatically register it in `systemd` service (see below).

### NFC reader permission
To access NFC reader, the permission of the device file must be set. Please execute the following.
```bash
sudo sh -c 'echo SUBSYSTEM==\"usb\", ACTION==\"add\", ATTRS{idVendor}==\"054c\", ATTRS{idProduct}==\"06c3\", GROUP=\"plugdev\" >> /etc/udev/rules.d/nfcdev.rules'
sudo udevadm control -R
```
Then, reboot the system.
This instruction is based on the result of `python -m nfc` command. If you use other NFC reader, please change the `idVendor` and `idProduct` according to your device.


## How to use

Almost all the operations are done by the `smartdoor` command. Please see the help message for the
details:
```bash
smartdoor --help
```

### 1. Set up the configuration file
The default configuration file ca be generated by the following command:
```bash
smartdoor config --generate
```
The configuration file is located at `~/.config/smartdoor.toml`. Please edit it according to your environment.

### 2. Run the main program for testing
The main program can be executed by the following command:
```bash
smartdoor start
```
If you want to specify door is locked/unlocked, add `--locked`/`--unlocked` option, by default
the door is locked.

The main program will be run in the foreground. If you want stop the program, press `Ctrl+C`.

### 3. Set up the auto start
The main program can be automatically run by `systemd` service. To register the `smartdoor.service`
to `systemd`, execute the following command:
```bash
smartdoor service --register
```
Then, the service will be ready for start. Simaltenously, the `pigpiod` service will be registered
if `pigpio` library is installed.

To manually start it, execute the following command:
```bash
smartdoor service --start
```

Please see the help message for other options:
```bash
smartdoor service --help
```

