-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
78 lines (66 loc) · 2.29 KB
/
app.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
from flask import Flask, jsonify, request
import database
app = Flask(__name__)
app.config['DEBUG'] = True
app.config['JSON_SORT_KEYS'] = False
app.config['ENV'] = 'development'
@app.route('/api/database/pushDataToDatabase', methods=['POST'])
def pushDataToDatabase():
print('[INFO]--[pushDataToDatabase]--[FUNCTION]')
stringData = request.form['stringData']
dataList = stringData.split('#')
MeasurementDate = dataList[0].split('.')[0]
PlantID = dataList[1]
SoilHumidity = dataList[2]
SoilTemperature = dataList[3]
AirQuality = dataList[4]
Temperature = dataList[5]
Humidity = dataList[6]
response = database.pushSoilsData(plantID=PlantID,soilHumidity=SoilHumidity,
soilTemperature=SoilTemperature,measurementDate=MeasurementDate)
response = database.pushAmbientsData(airQuality=AirQuality,temperature=Temperature,
humidity=Humidity,measurementDate=MeasurementDate)
responseMessage = 'Could not write to database'
if(response==True):
responseMessage = 'Successfully written to database'
return jsonify(
{
'measurementDate' : MeasurementDate,
'PlantID' : PlantID,
'soilHumidity' : SoilHumidity,
'soilTemperature' : SoilTemperature,
'AirQuality' : AirQuality,
'Temperature' : Temperature,
'Humidity' : Humidity,
'Database Message' : responseMessage
}
)
@app.route('/api/test/getTest', methods=['GET'])
def getTest():
print('[INFO]--[getTest]--[FUNCTION]')
return jsonify('Test Successful')
@app.route('/api/test/getTestJenkins', methods=['GET'])
def getTestJenkins():
print('[INFO]--[getTest]--[FUNCTION]')
return jsonify('Test Successful for Jenkins')
@app.route('/', methods=['GET'])
def home():
print('[INFO]--[home]--[FUNCTION]')
homePage = '''
<html>
<head>
<style>
h1 {text-align: center;}
</style>
</head>
<body>
<h1>WELCOME TO THE DIJI-DOM DATABASE WEB API</h1>
</body>
</html>
'''
return homePage
@app.route('/favicon.ico')
def favicon():
return 'None'
if __name__ == '__main__':
app.run()