-
Notifications
You must be signed in to change notification settings - Fork 3
/
doorbotd.py
executable file
·60 lines (44 loc) · 1.2 KB
/
doorbotd.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/env python
import argparse
import logging
import select
import socket
import sys
import sqlite3
import time
import re
import os
import doorbot
import doorio
import recoverserial
import userdb
def path_relative(name):
return os.path.join(os.path.dirname(__file__), name)
auth_dev = {
'dev' : "/dev/ttyAUTH",
'baudrate' : 9600,
}
lock_dev = {
'dev' : "/dev/ttyLOCK",
'baudrate' : 9600,
}
dbfile = path_relative("db/user.db")
logfile = path_relative("doorbot.log")
bindhost, port = '::1', 4242
sock = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
sock.bind( (bindhost, port) )
sock.listen(5)
logging.basicConfig(filename=logfile, format="%(asctime)-15s: %(message)s", level=logging.INFO)
log = logging.getLogger("doorbotd")
log.info("Doorbot started")
conn = sqlite3.connect(dbfile)
auth = recoverserial.RecoverSerial(auth_dev['dev'], auth_dev['baudrate'])
lock = recoverserial.RecoverSerial(lock_dev['dev'], lock_dev['baudrate'])
door_io = doorio.DoorIO(auth_serial=auth, lock_serial=lock, socket=sock)
doorbot = doorbot.Doorbot(conn, door_io)
ret = doorbot.run()
if (ret):
sys.exit(0)
else:
sys.exit(1)