Modify vitalsd to reflect changes in 0bf03afb4f
This commit is contained in:
parent
0bf03afb4f
commit
e67bc84e3a
|
@ -1,6 +1,7 @@
|
||||||
import subprocess
|
import subprocess
|
||||||
import time
|
import time
|
||||||
import requests
|
import requests
|
||||||
|
import sys
|
||||||
from flask import jsonify
|
from flask import jsonify
|
||||||
|
|
||||||
heartrateCmd = ['itctl', 'get', 'heart']
|
heartrateCmd = ['itctl', 'get', 'heart']
|
||||||
|
@ -44,17 +45,29 @@ battery = 0
|
||||||
urlBase = 'http://localhost:5000'
|
urlBase = 'http://localhost:5000'
|
||||||
urlHeartrate = urlBase + '/api/vitals/heartrate'
|
urlHeartrate = urlBase + '/api/vitals/heartrate'
|
||||||
urlSteps = urlBase + '/api/fitness/steps'
|
urlSteps = urlBase + '/api/fitness/steps'
|
||||||
|
urlAddCyberware = urlBase + '/api/cyberware/add'
|
||||||
#urlBattery = urlBase + # Cyberware management not yet implemented
|
#urlBattery = urlBase + # Cyberware management not yet implemented
|
||||||
|
|
||||||
|
# Add to Cyberware and get UUID
|
||||||
|
uuidRequest = requests.post(urlAddCyberware, json={ 'name': "PineTime", 'hotpluggable': True, 'canSet': [ '/api/vitals/heartrate', '/api/fitness/steps' ] })
|
||||||
|
if(uuidRequest.status_code == 204):
|
||||||
|
uuid = uuidRequest.json()['uuid']
|
||||||
|
else:
|
||||||
|
sys.exit("Failed to get UUID")
|
||||||
|
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
heartrate = getHeartrate()
|
heartrate = getHeartrate()
|
||||||
steps = getSteps()
|
steps = getSteps()
|
||||||
#battery = getBattery()
|
#battery = getBattery()
|
||||||
|
|
||||||
requests.post(urlHeartrate, json={ 'heartrate': heartrate } )
|
requests.post(urlHeartrate, json={ 'heartrate': heartrate, 'uuid': uuid } )
|
||||||
requests.post(urlSteps, json={ 'steps': steps })
|
requests.post(urlSteps, json={ 'steps': steps, 'uuid': uuid })
|
||||||
except:
|
except:
|
||||||
print("An exception occured. TODO: Exception report to frontend.")
|
print("An exception occured. TODO: Exception report to frontend.")
|
||||||
|
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
|
||||||
|
# Disconnect Cyberware
|
||||||
|
requests.post(urlRemoveCyberware, json={ 'uuid': uuid })
|
||||||
|
|
Loading…
Reference in a new issue