I am developping a watchface for Pebble Time 2 using Alloy framework.
I am trying to display a step counter but cannot find how to access health Data with Javascript framework.
I only find documentation about C code.
Is there a way to get the step count in an Alloy watchface ?
In conclusion, developers cannot use C code in Alloy app.
Because Alloy app implements this through a feature called mods, it cannot include native C code.
If you want to add an API that executes C code, you need to add a JavaScript API using XS in C to the host application on the PebbleOS side.
I haven’t tried it yet, but I’ve been eyeing this section of the Moddable docs about the JavaScript @ language syntax extension and the Native API. However I’m unsure if the Pebble APIs for heath etc. are even available when building an Alloy project. Since there is some C involved (mdbl.c) I’m assuming more C code could be added as well. I’ve personally been struggling a bit with memory limits/allocation with Alloy and am considering making an attempt to translate some things to C (in which I have very little experience).
No luck so far. The build fails with the @, and while the Native API doesn’t fail at build time, it definitely doesn’t work without some monkeying with how the app is compiled I imagine. I even tried something like this Moddable XS in C example but couldn’t make it work.
None of the XS-in-C stuff works right now, but there is another path: PKJS messages.
I confirmed that Pebble C APIs are accessible from mdbl.c and was able to set up a PKJS relay for the information I want to display (steps and BPM). I’ve created a minimal Alloy watchface repo that I hope others will find useful:
The health_relay module should be portable enough to copy/paste into any project as long as you wire it up in main() and also copy the PKJS appmessage listener. Oh, and don’t forget to add the health capability in package.json!
Of course, having to relay this data via the phone isn’t ideal, but it’s a start until more robust Alloy-compatible APIs are available.
No luck so far. The build fails with the @, and while the Native API doesn’t fail at build time, it definitely doesn’t work without some monkeying with how the app is compiled I imagine
As I mentioned before, Alloy doesn’t allow including native code via XS in C. I don’t fully understand exactly what mdbl.c does, but Alloy applications built with Moddable target the contents under embeddedjs directory.
Using PKJS messages seems like a reasonable workaround for now. It might already be planned, but it could be worth asking in Moddable Discussions whether there are plans to implement an Alloy API.