From 8a05f1aacb7ce0d8a2ce8311678d50e1ccaf8f52 Mon Sep 17 00:00:00 2001 From: Tanner Collin Date: Mon, 29 Nov 2021 06:53:32 +0000 Subject: [PATCH] Fix update bugs --- README.md | 13 +++++++++++-- main.py | 17 ++++++++--------- requirements.txt | 22 ---------------------- settings.py.example | 4 ++-- 4 files changed, 21 insertions(+), 35 deletions(-) diff --git a/README.md b/README.md index 3ae6469..323b3d9 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,8 @@ $ sudo raspi-config - Reboot ``` +If wifi doesn't work, you're on your own. + For the watchdog to work, we need write access to `/dev/watchdog/`. Configure `/etc/udev/rules.d/60-watchdog.rules`: @@ -25,13 +27,20 @@ Configure `/etc/udev/rules.d/60-watchdog.rules`: KERNEL=="watchdog", MODE="0666" ``` +Change the hostname: + +```text +$ sudoedit /etc/hostname +$ sudoedit /etc/hosts +``` + ### Script Install dependencies: ```text $ sudo apt update -$ sudo apt install python3 python3-pip python-virtualenv python3-virtualenv supervisor +$ sudo apt install python3 python3-pip python-virtualenv python3-virtualenv supervisor python3-rpi.gpio ``` **Make sure you have at least Python 3.9 installed.** @@ -42,7 +51,7 @@ Clone this repo: $ cd $ git clone https://tanner@git.tannercollin.com/tanner/doorbelldingdongringringdoorbell.git $ cd doorbelldingdongringringdoorbell/ -$ virtualenv -p python3 env +$ virtualenv --system-site-packages -p python3 env $ source env/bin/activate (env) $ pip install -r requirements.txt ``` diff --git a/main.py b/main.py index 6a32a87..fd0f971 100644 --- a/main.py +++ b/main.py @@ -69,11 +69,13 @@ async def ws_listener(): settings.UFP_PASSWORD, ) - await unifiprotect.check_unifi_os() await unifiprotect.update() unsub = unifiprotect.subscribe_websocket(subscriber) + logging.info('Connecting to websocket.') + await asyncio.sleep(2) + while True: try: updates = await unifiprotect.update() @@ -82,14 +84,10 @@ async def ws_listener(): logging.error('Problem connecting to Unifi Protect. Reconnecting...') break - logging.debug('unifiprotect: %s', unifiprotect.__dict__) - logging.debug('ws_session %s', unifiprotect.ws_session.__dict__) - - breakpoint() - - #active_ws = await unifiprotect.check_ws() - #if not active_ws: - # logging.error('Websocket unactive. Reconnecting...') + active_ws = await unifiprotect.check_ws() + if not active_ws: + logging.error('Websocket unactive. Reconnecting...') + break if allow_watchdog and not DEBUG: feed_watchdog() @@ -112,6 +110,7 @@ def init(): for _, doorbell in settings.DOORBELLS.items(): GPIO.setup(doorbell['gpio'], GPIO.OUT) + set_relay(doorbell['gpio'], RELAY_OFF) #pulse_relay(doorbell['gpio']) time.sleep(1) logging.info('GPIO initialized') diff --git a/requirements.txt b/requirements.txt index 3c8cdb0..40a95e9 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,23 +1 @@ -aiohttp==3.7.4.post0 -aioshutil==1.1 -async-timeout==3.0.1 -asyncio==3.4.3 -attrs==21.2.0 -chardet==4.0.0 -click==8.0.3 -idna==3.3 -importlib-metadata==4.8.1 -multidict==5.2.0 -packaging==21.3 -Pillow==8.4.0 -pydantic==1.8.2 -PyJWT==2.2.0 -pyparsing==3.0.6 -python-dotenv==0.19.1 -pytz==2021.3 pyunifiprotect==1.1.0 -RPi.GPIO==0.7.0 -typer==0.4.0 -typing-extensions==3.10.0.2 -yarl==1.7.0 -zipp==3.6.0 diff --git a/settings.py.example b/settings.py.example index f525ae3..66840f2 100644 --- a/settings.py.example +++ b/settings.py.example @@ -6,10 +6,10 @@ UFP_PORT = 443 DOORBELLS = { '123456780ABC': { 'name': 'Front Door', - 'gpio': 26, + 'gpio': 19, }, '123456780ABC': { 'name': 'Side Door', - 'gpio': 19, + 'gpio': 26, }, }