-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconstval.py
More file actions
46 lines (39 loc) · 1.16 KB
/
Copy pathconstval.py
File metadata and controls
46 lines (39 loc) · 1.16 KB
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
MAIN_URL = "http://localhost:53028/"
GAIN = 1
TOTALLY_DRY = 1650
TOTALLY_WET = 640
SOIL_WILTING_POINT = 1055
def _get_field_capacity_from_web():
try:
import requests
r = requests.get(url=MAIN_URL + "sensor?action=get_field_capacity")
print(r)
data = r.json()
print(data)
return data['field_capacity']
except requests.exceptions.ConnectionError as e:
print(e)
except requests.exceptions.HTTPError as e:
print(e)
except requests.exceptions.Timeout as e:
print(e)
except requests.exceptions.TooManyRedirects as e:
print(e)
except requests.exceptions.RequestException as e:
print(e)
def get_field_capacity():
try:
import redis
r = redis.StrictRedis(host='localhost', port=6379, db=0)
if r.exists('field_capacity'):
return int(r.get('field_capacity'))
else:
return _get_field_capacity_from_web()
except ModuleNotFoundError:
return _get_field_capacity_from_web()
SOIL_FIELD_CAPACITY = get_field_capacity()
print(SOIL_FIELD_CAPACITY)
GPIO_POS = 26
DRY = 0
WET = 100
URL = MAIN_URL + "sensor_status_reporter"