-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
61 lines (52 loc) · 1.48 KB
/
main.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
60
61
# import ujson
from machine import Pin, I2C
# from i2c_lcd import I2cLcd
from time import sleep, sleep_ms
from functions import *
# Configure the LCD
lcd = lcd_create(0x27, 5, 4)
sleep(2)
# # Configure the siren
# p2 = Pin(2, Pin.OUT)
# # Load config
# with open('config.json') as fh:
# config = ujson.load(fh)
# Set up API
nvr = 0
while not nvr:
try:
nvr = Reo_api(config)
except Exception as e:
lcd_load(lcd, "API Failure", sta_if.ifconfig()[0])
sleep(10)
def main():
counter = 30
while True:
# Get new token
if "error" in nvr.alm_state():
try:
nvr.get_api_token()
except:
lcd_load(lcd, "Error: Sess lim", sta_if.ifconfig()[0])
sleep(10)
counter = 0
# Reload address
if address != sta_if.ifconfig()[0]:
address = sta_if.ifconfig()[0]
lcd_load(lcd, message, address)
sleep(2)
# Pull the alarm status
# print(f'alarm state return is: {nvr.alm_state()[0]["value"]["state"]}')
if nvr.alm_state()[0]["value"]["state"]:
lcd_load(lcd, "Alarm Active", sta_if.ifconfig()[0])
for i in range(1,5):
p2.value(1)
sleep_ms(500)
p2.value(0)
sleep_ms(500)
sleep(30)
lcd_load(lcd, "Alarm Ready", sta_if.ifconfig()[0])
sleep(1)
counter += 1
if __name__ == "__main__":
main()