open-index/open-npm huggingface dataset:
npm package: @frezik/doorbot-ts
Description: Framework for automatic door opening
Author: Timm Murray
Latest version: 0.15.0

# Doorbot.ts

Allows access to something (like a door lock) by authenticating through 
something else (like an RFID reader or pin pad).

This module isn't particularly useful by itself. You'll need supporting modules
to run this on (for example) the Raspberry Pi and to interface with Wiegand 
readers.

## Setup

After cloning from github, run `npm install .` to install the prereqs. You can 
run the tests with `npm test`.

## Architechtural Overview

There are three main components: Reader, Authenticator, and Activator. The 
Reader interfaces with some device that is meant to allow access, such as a 
Wiegand RFID reader or a pin pad (or maybe both). The data from that is then 
passed through a ReadData object to an Authenticator. The auth portion checks 
if the given input should be allowed or not. If it is, the Activator will 
do a thing, such as triggering a GPIO pin on a Raspberry Pi to unlock the door.

This makes heavy use of Promises so that everything is done asynchronously. 
Async is important for maintaining low latency.
npm package: @frezik/rpi-doorbot-ts
Description: Modules to interface doorbot-ts to the Raspberry Pi
Author: Timm Murray
Latest version: 0.7.0

# RPi Doorbot.ts

Interfaces Doorbot.ts to the Raspberry Pi.

# Setup

After cloning from github, run `npm install .` to install the prereqs. You can 
run the tests with `npm test`.

# Example

Here's an example of reading entries from a Wiegand reader, using pins 12 
and 13 as data 0 and 1, respectively.  This uses an `AlwaysAuthenticator`, so 
all reads will pass through. Once it does, GPIO pin 22 will be turned on for 
30 seconds.

(This uses an external program to read the Wiegand data. You can get that at:
https://github.com/frezik/wiegand_pigpio)

```
import * as Doorbot from '@frezik/doorbot-ts';
import * as RPi from '@frezik/rpi-doorbot-ts';
import * as Bodgery from '@bodgery/bodgery-doorbot-ts';


const PIN = 22;
const DATA0 = 12;
const DATA1 = 13;
const OPEN_TIME_MS = 30000;

Doorbot.init_logger( "/home/pi/doorbot/doorbot.log"  )

// Launch wiegand reader program as its own process. Run its STDOUT into
// an fs reader.

const wiegand = Process.spawn( WIEGAND_PROGRAM, [
    DATA0.toString()
    ,DATA1.toString()
]);
wiegand.on( 'error', (err) => {
    Doorbot.log.error( '<Main> Error starting Wiegand reader: ' + err );
    process.exit(1);
});
wiegand.on( 'exit', (code, signal) => {
    Doorbot.log.error( '<Main> Wiegand reader exited with code ' + code );
    process.exit(1);
});
wiegand.stderr.on( 'data', (data) => {
    Doorbot.log.info( '<Main> Wiegand reader stderr: ' + data );
});


const reader = new Doorbot.FHReader( wiegand.stdout );
const auth = new Doorbot.AlwaysAuthenticator();
const act = new RPi.GPIOActivator( PIN, OPEN_TIME_MS );

reader.init();
act.init();

reader.setAuthenticator( auth );
auth.setActivator( act );

reader
    .run()
    .then( (res) => {} );
```

If you save this to `/home/pi/doorbot/index.ts`, you can run it at 
startup with the following systemd service:

```
# /etc/systemd/system/rfid.service
[Unit]
Description=RFID Doorbot
After=getty.target rfid_db.service

[Service]
ExecStart=/usr/local/bin/ts-node /home/pi/doorbot/index.ts
Restart=on-abort

[Install]
WantedBy=multi-user.target
```

Save this to `/etc/syistemd/system/rfid.service`. You can start it with 
`sudo systemctl start rfid`, and if it works, have it come up at startup with 
`sudo systemctl enable rfid`.