diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0bdc70d --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +SQLHandler/config.json diff --git a/SQLHandler/SQLconnect.py b/SQLHandler/SQLconnect.py new file mode 100644 index 0000000..3b8c283 --- /dev/null +++ b/SQLHandler/SQLconnect.py @@ -0,0 +1,26 @@ +# This file contains the function to connect to a secified database. +import json +import mysql.connector +from Util import configuration as decryption + +# Open the config file and readout the data +with open('config.json', 'r') as file: + data = file.read() + config = json.loads(data) + + +# -------------------------------------------------------------------------------------------------------------------- # +def createConnection(configuration): + """ + It creates the connection to the database + :param configuration: This specifies which configuration should be used + :return: It returns the database connection + """ + connection = mysql.connector.connect( + host=config[configuration]["host"], + user=config[configuration]["user"], + password=decryption.decryptKey(config[configuration]["passwd"]), + database=config[configuration]["dbname"], + autocommit=True + ) + return connection \ No newline at end of file diff --git a/ServerNode/api.py b/ServerNode/api.py index e69de29..8ed7dc3 100644 --- a/ServerNode/api.py +++ b/ServerNode/api.py @@ -0,0 +1,18 @@ +from flask import Flask, jsonify, request + +app = Flask(__name__) + + +@app.route('/sensordata') +def get_sensordata(): + return jsonify(sensordata) + + + + +@app.route('/sensordata', methods=['POST']) +def add_sensordata(): + + sensordata.append(request.get_json()) + + return '', 204