Started work on vitalsd and navigationd, updated README.
This commit is contained in:
parent
39148b0c7b
commit
91a7d03dce
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1 +1,2 @@
|
|||
src/**/__pycache__
|
||||
src/venv
|
||||
|
|
|
@ -1,3 +1,10 @@
|
|||
# nightui
|
||||
|
||||
Software for the K.A.T.I.E.
|
||||
Software for the K.A.T.I.E.
|
||||
|
||||
## Components
|
||||
nightserver.py - The central API that the frontend recieves data from. Also serves the frontend itself.
|
||||
|
||||
modules/vitalsd/ - Vitals Daemon. Obtains vitals information and POSTs to nightserver.
|
||||
|
||||
modules/navigationd/ - Navigation Daemon. Obtains navigation data and POSTs to nightserver.
|
||||
|
|
0
src/modules/navigationd/navigationd.py
Normal file
0
src/modules/navigationd/navigationd.py
Normal file
1
src/modules/navigationd/requirements.txt
Normal file
1
src/modules/navigationd/requirements.txt
Normal file
|
@ -0,0 +1 @@
|
|||
pygarmin
|
2
src/modules/vitalsd/requirements.txt
Normal file
2
src/modules/vitalsd/requirements.txt
Normal file
|
@ -0,0 +1,2 @@
|
|||
flask
|
||||
requests
|
60
src/modules/vitalsd/vitalsd.py
Normal file
60
src/modules/vitalsd/vitalsd.py
Normal file
|
@ -0,0 +1,60 @@
|
|||
import subprocess
|
||||
import time
|
||||
import requests
|
||||
from flask import jsonify
|
||||
|
||||
heartrateCmd = ['itctl', 'get', 'heart']
|
||||
stepsCmd = ['itctl', 'get', 'steps']
|
||||
batteryCmd = ['itctl', 'get', 'battery']
|
||||
|
||||
def getHeartrate():
|
||||
proc = subprocess.Popen(heartrateCmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
o, e = proc.communicate()
|
||||
|
||||
if(proc.returncode != 0):
|
||||
return -1 # Inform that cyberware is inoperative
|
||||
o = o.decode("utf-8")
|
||||
bpm = o.split(' ')
|
||||
return bpm[0]
|
||||
|
||||
def getSteps():
|
||||
proc = subprocess.Popen(stepsCmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
o, e = proc.communicate()
|
||||
|
||||
if(proc.returncode != 0):
|
||||
return -1 # Inform that cyberware is inoperative
|
||||
o = o.decode("utf-8")
|
||||
steps = o.split(' ')
|
||||
return steps[0]
|
||||
|
||||
def getBattery():
|
||||
proc = subprocess.Popen(batteryCmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
o, e = proc.communicate()
|
||||
|
||||
if(proc.returncode != 0):
|
||||
return -1 # Inform that cyberware is inoperative
|
||||
o = o.decode("utf-8")
|
||||
battery = o.split('%')
|
||||
return battery[0]
|
||||
|
||||
heartrate = 0
|
||||
steps = 0
|
||||
battery = 0
|
||||
|
||||
urlBase = 'http://localhost:5000'
|
||||
urlHeartrate = urlBase + '/api/vitals/heartrate'
|
||||
urlSteps = urlBase + '/api/fitness/steps'
|
||||
#urlBattery = urlBase + # Cyberware management not yet implemented
|
||||
|
||||
while True:
|
||||
try:
|
||||
heartrate = getHeartrate()
|
||||
steps = getSteps()
|
||||
#battery = getBattery()
|
||||
|
||||
requests.post(urlHeartrate, json={ 'heartrate': heartrate } )
|
||||
requests.post(urlSteps, json={ 'steps': steps })
|
||||
except:
|
||||
print("An exception occured. TODO: Exception report to frontend.")
|
||||
|
||||
time.sleep(1)
|
|
@ -2,9 +2,9 @@ from flask import Flask, render_template, jsonify, request
|
|||
app = Flask(__name__)
|
||||
|
||||
# Vitals
|
||||
vitalsHeartrate = 0
|
||||
vitalsOxygen = 0
|
||||
vitalsBodytemp = 0.0
|
||||
vitalsHeartrate = -1
|
||||
vitalsOxygen = -1
|
||||
vitalsBodytemp = -1.0
|
||||
|
||||
@app.route('/api/vitals/heartrate')
|
||||
def getVitalsHeartrate():
|
||||
|
@ -56,6 +56,62 @@ def getVitals():
|
|||
returnArr = [ { 'heartrate': vitalsHeartrate, 'oxygen': vitalsOxygen, 'bodytemp': vitalsBodytemp } ]
|
||||
return jsonify(returnArr)
|
||||
|
||||
@app.route('/api/vitals', methods=['POST'])
|
||||
def setVitals():
|
||||
global vitalsHeartrate
|
||||
global vitalsOxygen
|
||||
global vitalsBodytemp
|
||||
|
||||
json = request.get_json()
|
||||
try:
|
||||
# This is a bit ugly but its just how I'm checking that everything is there without setting variables if the json is incorrect
|
||||
tempH = json['heartrate']
|
||||
tempO = json['oxygen']
|
||||
tempB = json['bodytemp']
|
||||
vitalsHeartrate = tempH
|
||||
vitalsOxygen = tempO
|
||||
vitalsBodytemp = tempB
|
||||
except:
|
||||
return 'Incorrect usage.\nUsage: { heartrate: INT, oxygen: INT, bodytemp: FLOAT }\n', 400
|
||||
return 'Information set successfully', 204
|
||||
|
||||
# Fitness
|
||||
fitnessSteps = -1
|
||||
|
||||
@app.route('/api/fitness/steps')
|
||||
def getSteps():
|
||||
return getFitness() # This is the same for now.
|
||||
|
||||
@app.route('/api/fitness/steps', methods=['POST'])
|
||||
def setFitnessSteps():
|
||||
global fitnessSteps
|
||||
json = request.get_json()
|
||||
try:
|
||||
vitalsBodytemp = json['steps']
|
||||
except:
|
||||
return 'Incorrect usage.\nUsage: { steps: INT }\n', 400
|
||||
return 'Information set successfully', 204
|
||||
|
||||
|
||||
@app.route('/api/fitness')
|
||||
def getFitness():
|
||||
returnArr = [ { 'steps': fitnessSteps } ]
|
||||
return jsonify(returnArr)
|
||||
|
||||
@app.route('/api/fitness', methods=['POST'])
|
||||
def setFitness():
|
||||
global fitnessSteps
|
||||
json = request.get_json()
|
||||
try:
|
||||
vitalsBodytemp = json['steps']
|
||||
except:
|
||||
return 'Incorrect usage.\nUsage: { steps: INT }\n', 400
|
||||
return 'Information set successfully', 204
|
||||
|
||||
|
||||
# Cyberware management
|
||||
#@app.route('/api/cyberware/add', methods=['POST'])
|
||||
#def addCyberware
|
||||
|
||||
|
||||
@app.route('/')
|
||||
|
|
2
src/requirements-all.txt
Normal file
2
src/requirements-all.txt
Normal file
|
@ -0,0 +1,2 @@
|
|||
flask
|
||||
pygarmin
|
1
src/requirements.txt
Normal file
1
src/requirements.txt
Normal file
|
@ -0,0 +1 @@
|
|||
flask
|
Loading…
Reference in a new issue