Cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Programming Topography

ANSWERED

I am making a watch face that displays the current total water log, total calories consumed from the food log, and the total macronutrients (proteins, fats, carbs) also from the food log. 

 

This seemed like a simple enough concept that I could just pull the digits from the fitbit app using something like "document.getWaterLog()" but now from what I'm understanding I need to make an companion app to pull those digits? And on top of that I need to learn how to program authorizations?

 

I feel like I'll understand it better if I had a flowchart of how things communicated. Please correct me if I misunderstand anything. This is to the best of my understanding:

 Untitled-2.png

 

If this is accurate, then I'm a little lost as to what the procedure is to pull the necessary numbers from the fitbit app. I'm looking for something like (Get authorization token from user (Web API) > Pull data from fitbit app to companion app (Companion API) > Pull data from Companion app to app/index.js > display data on watch face with resources/index.view)

 

Best Answer
1 BEST ANSWER

Accepted Solutions

You're on the right track, and I love the effort!

 

I don't think it's strictly true to say that the data is obtained from the Fitbit Phone [Mobile] App. The data actually comes from Fitbit's database, which is accessed via the Web API. You don't have to communicate with the Fitbit Phone App; you go straight to the database. As I understand it, the Phone App gets its data from the database (possibly using the Web API), just like you can. So, where you've written 'Fitbit Phone App', you can probably replace it with 'Fitbit database' (which is accessed via the Web API after authentication, as you've got).

 

The companion is essentially 'headless' (ie, can't display anything directly). Its main role is as a communications conduit between the device (app) and the Fitbit database. It's the component that initiates authorisation and uses the Web API. In addition, it's best to do as much processing of the data as you can in the companion, because the device on which its running is more powerful than the watch. Make things as easy for the watch as possible.

 

widgets.def is used to specify system (or other) UI components that need to be included in your build.

 

I think you'll find this invaluable: it shows how to get data from the Web API and how to do the authorisation.

Peter McLennan
Gondwana Software

View best answer in original post

Best Answer
6 REPLIES 6

You're on the right track, and I love the effort!

 

I don't think it's strictly true to say that the data is obtained from the Fitbit Phone [Mobile] App. The data actually comes from Fitbit's database, which is accessed via the Web API. You don't have to communicate with the Fitbit Phone App; you go straight to the database. As I understand it, the Phone App gets its data from the database (possibly using the Web API), just like you can. So, where you've written 'Fitbit Phone App', you can probably replace it with 'Fitbit database' (which is accessed via the Web API after authentication, as you've got).

 

The companion is essentially 'headless' (ie, can't display anything directly). Its main role is as a communications conduit between the device (app) and the Fitbit database. It's the component that initiates authorisation and uses the Web API. In addition, it's best to do as much processing of the data as you can in the companion, because the device on which its running is more powerful than the watch. Make things as easy for the watch as possible.

 

widgets.def is used to specify system (or other) UI components that need to be included in your build.

 

I think you'll find this invaluable: it shows how to get data from the Web API and how to do the authorisation.

Peter McLennan
Gondwana Software
Best Answer

Hi @iPh33r - great post/presentation - @Gondwana - Also great explanations.

 

What happens with the companion and related clock face/app if the watch is not syncing/connectible with the phone?

 

As the Watch clock face/app can't reach the companion, or the phone can reach the Internet [when there is no wifi or data coverage] doesn't it stop working?

 

Presumably the clock face/app needs to handle the situation and a way to show if the information is current or historic?

 

And what happens when connectivity is restored? Is the companion still running?

 

And in the case the phone was unreachable when the clock face/app was started, how can the companion be started without reloading the clock face/app?

Author | ch, passion for improvement.

Best Answer
0 Votes

Yes, comms-down fallbacks need to be considered.

It's possible to set a wake interval for the companion, so the Fitbit app will restart it every so often. It can then try to query the database again. Alternatively, the companion should wake automatically whenever a message or file is sent to it from the watch (app).

Peter McLennan
Gondwana Software
Best Answer

I probably told a small fib in my lengthy explanation. While you don't get the data from the Fitbit App, your companion code runs within the Fitbit App. If you wanted to represent the Fitbit App on the diagram, I'd see it as a wrapper/container/environment surrounding the companion. You can largely ignore it though; it doesn't have an API. It does, however, let users install your app and change its settings.

Peter McLennan
Gondwana Software
Best Answer

@Gondwana  - thanks very useful information.

 

Firstly, Is it possible to start a companion, if when the watch app was started, the phone was unreachable, and if so how?

 

Obviously if the phone is unreachable when you start the watch app, the companion will not be started on the phone.

 

When subsequently the phone is reachable does the companion automatically get started? Probably not. And the only way to resolve that is to restart the watch app?

 

Secondly if the companion has a setInterval wake, what happens if the watch app is stopped

 

  • When the phone is reachable
  • Or when the phone is unreachable

Could an orphan companion keep waking itself?

Author | ch, passion for improvement.

Best Answer
0 Votes

That was a huge help! Especially the link to the github. Thank you!! 

 

Now to tackle authorization issues... different thread. 😁

Best Answer