-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
113 lines (80 loc) · 3.37 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
from temperature import temperature
from rain import rain
from wind import wind
from system import system
from database import database
from flask import Flask, jsonify, request, url_for, json
from flask_cors import CORS
from dotenv import load_dotenv
import os
app = Flask(__name__)
CORS(app)
load_dotenv()
endpoint = '/api/v1'
db = database(os.getenv('DBFILENAME'))
temperature = temperature(int(os.getenv('DHT11SENSORPIN')), os.getenv('ONEWIRESENSORADDRESS'))
rain = rain(int(os.getenv('PLUVIOPIN')), float(os.getenv('PLUVIOSIZE')))
wind = wind(os.getenv('DBFILENAME'), int(os.getenv('ANEMOPIN')))
system = system()
@app.route(endpoint + '/pool/temperature', methods=['GET'])
def get_pool_temperature():
if (request.method == 'GET'):
return jsonify(temperature.read_one_wire_temperature())
@app.route(endpoint + '/pool/temperature/history', methods=['GET'])
def get_pool_temperature_history():
if (request.method == 'GET'):
return jsonify('Endpoint not implemented')
@app.route(endpoint + '/weather/temperature', methods=['GET'])
def get_temperature():
if (request.method == 'GET'):
return jsonify(temperature.read_temperature_humidity_sensor().get('temperature'))
@app.route(endpoint + '/weather/temperature/history', methods=['GET'])
def get_temperature_history():
if (request.method == 'GET'):
return jsonify('Endpoint not implemented')
@app.route(endpoint + '/weather/humidity', methods=['GET'])
def get_humidity():
if (request.method == 'GET'):
return jsonify(temperature.read_temperature_humidity_sensor().get('humidity'))
@app.route(endpoint + '/weather/humidity/history', methods=['GET'])
def get_humidity_history():
if (request.method == 'GET'):
return jsonify('Endpoint not implemented')
@app.route(endpoint + '/weather/rain', methods=['GET'])
def get_rain():
if (request.method == 'GET'):
return jsonify(rain.mm_per_hour)
@app.route(endpoint + '/weather/rain/history', methods=['GET'])
def get_rain_history():
if (request.method == 'GET'):
return jsonify('Endpoint not implemented')
@app.route(endpoint + '/weather/wind/speed', methods=['GET'])
def get_wind_speed():
if (request.method == 'GET'):
return jsonify(wind.wind_speed)
@app.route(endpoint + '/weather/wind/speed/history', methods=['GET'])
def get_wind_speed_history():
if (request.method == 'GET'):
return jsonify('Endpoint not implemented')
@app.route(endpoint + '/weather/wind/direction', methods=['GET'])
def get_wind_direction():
if (request.method == 'GET'):
return jsonify('Endpoint not implemented')
@app.route(endpoint + '/weather/wind/direction/history', methods=['GET'])
def get_wind_direction_history():
if (request.method == 'GET'):
return jsonify('Endpoint not implemented')
@app.route(endpoint + '/system/status', methods=['GET'])
def get_weather_station_status():
if (request.method == 'GET'):
return jsonify(system.get_status())
@app.route(endpoint + '/system/battery', methods=['GET'])
def get_weather_station_battery_status():
if (request.method == 'GET'):
return jsonify(system.get_battery_percentage())
@app.route(endpoint + '/system/uptime', methods=['GET'])
def get_weather_station_uptime():
if (request.method == "GET"):
return jsonify(system.get_system_uptime())
if __name__ == '__main__':
Flask.run(app, host="0.0.0.0", port=5500)