AlloyJS WatchFace and Health Data

Hello all,

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 ?

Thank you in advance for your answers.

Regards.

Nicolas.

3 Likes

Good question! @jpx I might have some tips on how to call C functions from inside an Alloy app.

1 Like

unfortunately I do not, sorry!

1 Like

Hello,

No problem. I am still looking for documentation.

I found this page : Moddable | Documentation | XS | XS in C

But I don’t really know what to do with that :sweat_smile:.

Regards.

Nicolas

1 Like

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.

1 Like

OK,

If I understand well I can use XS in C to create a bridge between JavaScript and C code.

And I can do and build all of this in the same project.

Is that so ?

Regards,

Nicolas

1 Like

I definitely have to take the time to read that documentation.

Thank you for your help.

1 Like

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).

1 Like

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.

1 Like

Hey folks, I have found a way!

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.

3 Likes

Clever workaround, looking good!
Definitely not ideal to have to go out and back to the phone. Hopefully the Alloy API gets these features soon.

2 Likes

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.

2 Likes