summaryrefslogtreecommitdiff
path: root/bin/gpiorelayd.py
blob: 022bc812f1a703c8b83074b2a87992dfacc4a703 (plain)
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
#!/usr/bin/env python3
import logging
import os
import sys
import include_homekit

from argparse import ArgumentParser
from homekit.util import Addr
from homekit.config import config
from homekit.relay.sunxi_h3_server import RelayServer

logger = logging.getLogger(__name__)


if __name__ == '__main__':
    if os.getegid() != 0:
        sys.exit('Must be run as root.')

    parser = ArgumentParser()
    parser.add_argument('--pin', type=str, required=True,
                        help='name of GPIO pin of Allwinner H3 sunxi board')
    parser.add_argument('--listen', type=str, required=True,
                        help='address to listen to, in ip:port format')

    arg = config.load_app(no_config=True, parser=parser)
    listen = Addr.fromstring(arg.listen)

    try:
        RelayServer(pinname=arg.pin, addr=listen).run()
    except KeyboardInterrupt:
        logger.info('Exiting...')