You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
715 B
Python
40 lines
715 B
Python
from flask import Flask, jsonify, request
|
|
from DatabaseObject import sensordata
|
|
from SQLHandler import SQLconnect
|
|
|
|
|
|
app = Flask(__name__)
|
|
|
|
mydb = SQLconnect.createConnection("mysql")
|
|
|
|
mycursor = mydb.cursor()
|
|
|
|
@app.route('/')
|
|
def test():
|
|
return "Hello Test"
|
|
|
|
|
|
|
|
|
|
@app.route('/sensordata')
|
|
def get_sensordata():
|
|
return jsonify(sensordata)
|
|
|
|
|
|
|
|
|
|
@app.route('/sensordata', methods=['POST'])
|
|
def add_sensordata():
|
|
timestamp = request.json['timestamp']
|
|
moisture = request.json['moisture']
|
|
|
|
newdata = sensordata(timestamp, moisture)
|
|
|
|
sql = "INSERT INTO sensordata (timestamp, moisture_earth) VALUES (%s, %s)"
|
|
|
|
mycursor.execute(sql, newdata)
|
|
|
|
mydb.commit()
|
|
|
|
return '', 204
|