2

我已经用鹅卵石试验了一两天了,我已经有点停滞不前了。也就是说,我似乎无法弄清楚某些事情是如何相关的。我想要做的是从 Android 上的应用程序获取数据以发送到 pebble,然后让 pebble 对这些数据做一些富有成效的事情。

我意识到您在 android 应用程序中使用 PebbleKit API 来与 pebble 进行通信,使用诸如sendDataToPebble(). 不过,在那之后,我不太确定该怎么做。

使用 cloudpebble.net,我使用 pebble SDK 在 C 中创建了一个应用程序来确认数据(使用他们网站上建议的处理程序)。但是,我最近发现整个组合中也可以有 javascript,我只是不知道如何与 js 交互。

是否有可能完全通过 javascript 完成所有 ack/nack 数据,以及数据的后续处理/显示,完全避免使用 C,或者我是否需要在 c 中接收数据,然后将其发送到 javascript使用(我目前不知道该怎么做)。

相信当JS应用程序接收到数据时会触发某种事件(appmessage我认为),但是,我认为那只是来自C应用程序?

因此,大多数情况下,我的困惑在于 JS 如何融入整个组合。如果有人能为我解决这个问题,我将由衷地感激。

编辑:我应该补充一点,我正在尝试在 cloudpebble.net 中使用 pebble.js 创建一个应用程序。

谢谢!

4

1 回答 1

7

Note: Some of the links below go to Pebble API documentation, which at the time of writing is only accessible if you're logged into the developer site with your Pebble account.

Getting started with Pebble development can be a little overwhelming. There are lots of moving parts, some of which you'll need and some of which you won't. Here's a quick overview of the major components:

  1. An app written in C. You'll definitely need to write one of these. (Well, almost definitely. See the note about SimplyJS below.)

    This is what runs on the actual watch. Here you'll likely create windows, menus, maybe do some work with graphics. You'll probably set up click handlers to handle button presses.

    The watch itself can't do very many interesting things. For example, it can't make any network requests, so no communication with the web. It can't do geolocation itself. You could build a completely self-contained watchface or timer or simple game though.

  2. Unless your app runs entirely on the watch, you'll also need one of the following:

    • An Android app written in Java, using PebbleKit for Android.
    • An iOS app written in Objective C, using PebbleKit for iOS.

      I don't have any experience with either PebbleKit for Android or PebbleKit for iOS, but they do both have official API documentation:

      Neither of these can be used from CloudPebble.net.

    • A JavaScript app written using PebbleKitJS, which works on both Android and iOS.

      Because this option lets developers target both mobile platforms, it's my favourite option. My sense is that many other developers agree. Unless you need to access things outside of what PebbleKitJS offers, I'd recommend using it.

      The JavaScript code here gets executed from within the official Pebble application on your phone. Essentially, the Pebble app has a sandboxed JavaScript environment for each watch app. If you go this route, you do not build a companion Android or iOS app. The official Pebble app effectively becomes your companion app.

      (Note that on iOS the JavaScript code must actually be bundled inside the official Pebble app. This generates a roughly 5-6 day period after releasing your app where iOS users will get the message that it's "available soon", while Android users will be able to use it immediately.)

  3. Finally, if you really don't want to use C, you can write a Pebble app purely in JavaScript using Simply.js (an unsupported, third-party tool). I've never used this, primarly because it seems that you can only have one Simply.js app running on your watch at once:

    How Do I Use This?

    You'll need a Pebble with OS 2.0.

    • Write a Simply.js script and host it online.
    • Download Simply.js v0.3.2 onto your Pebble.
    • Go to "My Pebble" in the new official Pebble Phone App.
    • Tap the Simply.js settings gear.
    • Place the URL to your script and hit Save.† Your script should immediately run.
    • Play with your Pebble!

    †If you're hosting your script on Github, use the raw URL to your script.

To make things even more confusing, with any of the three phone APIs you can use one of two communication APIs:

  1. AppMessage is the foundational communication API that developers can use:

    AppMessage is a bi-directional messaging subsystem that enables communication between phone apps and Pebble watchapps. This is accomplished by allowing phone and watchapps to exchange arbitrary sets of key/value pairs. The key/value pairs are stored in the form of a Dictionary, the layout of which is left for the application developer to define.

    It works reasonably well, but it can be a bit tricky to get working at times. If you're working with PebbleKitJS, use console.log freely as there is no debugger.

  2. AppSync is a higher level library that claims to be for UI synchronization:

    AppSync is a convenience layer that resides on top of AppMessage, and serves as a UI synchronization layer for AppMessage. In so doing, AppSync makes it easier to drive the information displayed in the watchapp UI with messages sent by a phone app.

    AppSync maintains and updates a Dictionary, and provides your app with a callback (AppSyncTupleChangedCallback) routine that is called whenever the Dictionary changes and the app's UI is updated. Note that the app UI is not updated automatically. To update the UI, you need to implement the callback.

    I haven't used it yet, but I'm about to try migrating an app from AppMessage to AppSync. It looks useful even when you're not doing UI synchronization.

Along with the official guides and API docs, Pebble provides a number of useful sample apps in the SDK. Since you seem to be interested in the JavaScript option, the most interesting are probably

  • the stock quotes app, located at Examples/pebblekit-js/quotes/, and
  • the weather app, located at Examples/pebblekit-js/weather/.

Check out each app's src/<appname>.c and src/js/pebble-js-app.js files.

于 2014-06-25T12:55:12.517 回答