Fix update bugs

This commit is contained in:
Tanner Collin 2021-11-29 06:53:32 +00:00
parent 0053b78e41
commit 8a05f1aacb
4 changed files with 21 additions and 35 deletions

View File

@ -17,6 +17,8 @@ $ sudo raspi-config
- Reboot - Reboot
``` ```
If wifi doesn't work, you're on your own.
For the watchdog to work, we need write access to `/dev/watchdog/`. For the watchdog to work, we need write access to `/dev/watchdog/`.
Configure `/etc/udev/rules.d/60-watchdog.rules`: Configure `/etc/udev/rules.d/60-watchdog.rules`:
@ -25,13 +27,20 @@ Configure `/etc/udev/rules.d/60-watchdog.rules`:
KERNEL=="watchdog", MODE="0666" KERNEL=="watchdog", MODE="0666"
``` ```
Change the hostname:
```text
$ sudoedit /etc/hostname
$ sudoedit /etc/hosts
```
### Script ### Script
Install dependencies: Install dependencies:
```text ```text
$ sudo apt update $ 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.** **Make sure you have at least Python 3.9 installed.**
@ -42,7 +51,7 @@ Clone this repo:
$ cd $ cd
$ git clone https://tanner@git.tannercollin.com/tanner/doorbelldingdongringringdoorbell.git $ git clone https://tanner@git.tannercollin.com/tanner/doorbelldingdongringringdoorbell.git
$ cd doorbelldingdongringringdoorbell/ $ cd doorbelldingdongringringdoorbell/
$ virtualenv -p python3 env $ virtualenv --system-site-packages -p python3 env
$ source env/bin/activate $ source env/bin/activate
(env) $ pip install -r requirements.txt (env) $ pip install -r requirements.txt
``` ```

17
main.py
View File

@ -69,11 +69,13 @@ async def ws_listener():
settings.UFP_PASSWORD, settings.UFP_PASSWORD,
) )
await unifiprotect.check_unifi_os()
await unifiprotect.update() await unifiprotect.update()
unsub = unifiprotect.subscribe_websocket(subscriber) unsub = unifiprotect.subscribe_websocket(subscriber)
logging.info('Connecting to websocket.')
await asyncio.sleep(2)
while True: while True:
try: try:
updates = await unifiprotect.update() updates = await unifiprotect.update()
@ -82,14 +84,10 @@ async def ws_listener():
logging.error('Problem connecting to Unifi Protect. Reconnecting...') logging.error('Problem connecting to Unifi Protect. Reconnecting...')
break break
logging.debug('unifiprotect: %s', unifiprotect.__dict__) active_ws = await unifiprotect.check_ws()
logging.debug('ws_session %s', unifiprotect.ws_session.__dict__) if not active_ws:
logging.error('Websocket unactive. Reconnecting...')
breakpoint() break
#active_ws = await unifiprotect.check_ws()
#if not active_ws:
# logging.error('Websocket unactive. Reconnecting...')
if allow_watchdog and not DEBUG: if allow_watchdog and not DEBUG:
feed_watchdog() feed_watchdog()
@ -112,6 +110,7 @@ def init():
for _, doorbell in settings.DOORBELLS.items(): for _, doorbell in settings.DOORBELLS.items():
GPIO.setup(doorbell['gpio'], GPIO.OUT) GPIO.setup(doorbell['gpio'], GPIO.OUT)
set_relay(doorbell['gpio'], RELAY_OFF)
#pulse_relay(doorbell['gpio']) #pulse_relay(doorbell['gpio'])
time.sleep(1) time.sleep(1)
logging.info('GPIO initialized') logging.info('GPIO initialized')

View File

@ -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 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

View File

@ -6,10 +6,10 @@ UFP_PORT = 443
DOORBELLS = { DOORBELLS = {
'123456780ABC': { '123456780ABC': {
'name': 'Front Door', 'name': 'Front Door',
'gpio': 26, 'gpio': 19,
}, },
'123456780ABC': { '123456780ABC': {
'name': 'Side Door', 'name': 'Side Door',
'gpio': 19, 'gpio': 26,
}, },
} }