This is my GUI. My GUI app
Code for GUI (frontend):
from tkinter import *
from tk_tools import *
from tkinter.ttk import *
from tkinter import messagebox
root=Tk()
root.title('Fitbit Dashboard')
root.grid()
hr=RotaryScale(root, max_value=(220-age), unit=' BPM Heart rate')
steps=Gauge(root, max_value=10000, label='steps', unit='', red_low=20, yellow_low=30, red=100, yellow=100)
steps.grid(column=2, row=1)
cals=Gauge(root, max_value=2400, label='calories', unit='', red_low=20, yellow_low=30, red=100, yellow=100)
cals.grid(column=4, row=1)
dist=Gauge(root, max_value=5, label='distance', unit=' mi', red_low=20, yellow_low=30, red=100, yellow=100)
dist.grid(column=3, row=1)
actmins=Gauge(root, max_value=30, label='active minutes', unit='', red_low=20, yellow_low=30, red=100, yellow=100)
actmins.grid(column=5, row=1)
hr.grid(column=1, row=1)
hr.set_value(0) hrEntry=Spinbox(root, from_=0, to=23, state='readonly')
hrEntry.grid(column=7, row=1)
minEntry=Spinbox(root, from_=0, to=59, state='readonly')
minEntry.grid(column=8, row=1)
addbutton=Button(root, text='Add Alarm', command=add_alarm) a
ddbutton.grid(column=9, row=1)
lo_bat=Led(root, size=50) lo_bat.grid(column=4, row=2)
lo_bat.to_red(on=False)
Label(root, text='Battery low when lit').grid(column=4, row=3)
Pseudocode for backend:
def add_alarm():
if all textboxes filled:
add alarm and notify user via messagebox
else:
show error via messagebox
while True:
set cals needle to cals burned
set steps needle to steps
set heart needle to current heart rate
set active minutes needle to active minutes
set distance needle to distance walked
if battery<=17:
turn on LED
else:
turn off LED
How do I turn the needles of the gauges on my GUI according to Fitbit stats, light the low battery indicator when the Fitbit's battery runs low, and add an alarm when pressing the "Add Alarm" button? In other words, how do I do my pseudocode in Python? The gauge's needles turn to show live data.
If not, how do I get the data (steps, calories, dist. active mins) from the last day and light the "Low Battery" LED as mentioned?
Best AnswerYou can probably get yesterday's data (so long as it's not just after midnight). If you want current (near-real-time) data, you'll need to use the device and companion APIs.
Best Answer@Gondwana Then how do I light the "Battery Low" LED when my Alta HR battery runs low, and how do I capture the last synced data?
Best AnswerCan I light the "Low Battery" LED when the battery gets low?
Best AnswerOh sorry, I didn't realise this was about Alta. You can't use device and companion APIs with Alta.
Best Answer@Gondwana What libraries/variables should I use to detect a low battery on my fitbit and light the "Low Battery" LED?
Best AnswerCheck whether battery charge is exposed in the Web API. I suspect it isn't.
There may be Python libraries you could use to help with the Oauth flow. If so, they'll be mentioned in the Web API documentation site.
Best Answer
Fitbit Developers oversee the SDK and API forums. We're here to answer questions about Fitbit developer tools, assist with projects, and make sure your voice is heard by the development team.
As @Gondwana described, you may use the Fitbit Web APIs to pull the device data after the device syncs with the mobile application. This includes querying the activity data for the previous day. We do not have a Web API to turn on a low battery light. My understanding is low battery notifications are managed by the device itself. However, you may use the Get Devices endpoint, https://dev.fitbit.com/build/reference/web-api/devices/#get-devices, to find out a device's battery life. From there, you could send an additional notification through your mobile application recommending the user charge their device.
Gordon
Best Answer