diff --git a/src/nightserver.py b/src/nightserver.py index 498c4cf..22d6d3b 100644 --- a/src/nightserver.py +++ b/src/nightserver.py @@ -198,6 +198,8 @@ def getCyberware(): @app.route('/api/cyberware/get') def getCyberwareSpecific(): + json = request.get_json() + try: desiredId = json['uuid'] i = 0 @@ -217,6 +219,57 @@ def resetCyberwareMalfunction(): return 'Not Implemented', 501 +# Environment data +environmentTemperature = -1 +environmentHumidity = -1 + +@app.route('/api/environment') +def getEnvironment(): + returnArr = [ { 'temperature': environmentTemperature, 'humidity': environmentHumidity } ] + return jsonify(returnArr), 200 + +# Environment//Temperature +@app.route('/api/environment/temperature') +def getEnvironmentTemperature(): + returnArr = [ { 'temperature': environmentTemperature } ] + return jsonify(returnArr), 200 + +@app.route('/api/environment/temperature', methods=['POST']) +def setEnvironmentTemperature(): + global environmentTemperature + json = request.get_json() + + try: + tempTemperature = json['temperature'] + + environmentTemperature = tempTemperature + except: + return 'Incorrect usage.\nUsage: { temperature: INT, uuid: STRING }\n', 400 + return '', 204 + +# Environment//Humidity +@app.route('/api/environment/humidity') +def getEnvironmentHumidity(): + returnArr = [ { 'humidity': environmentHumidity } ] + return jsonify(returnArr), 200 + +@app.route('/api/environment/humidity', methods=['POST']) +def setEnvironmentHumidity(): + global environmentHumidity + json = request.get_json() + + try: + tempHumidity = json['humidity'] + + environmentHumidity = tempHumidity + except: + return 'Incorrect usage.\nUsage: { humidity: INT, uuid: STRING }\n', 400 + return '', 204 + +# Authentication method +# This authorizes the given UUID to determine whether the request is +# allowed to set the requested endpoint. +# This is ONLY used for PUSH requests currently. def authenticate(uuid, endpoint): for c in cyberware: # UUID Match if c['uuid'] == uuid: