pebble/devsite/source/_guides/communication/index.md
2025-02-24 18:58:29 -08:00

3.3 KiB

title description guide_group menu permalink generate_toc hide_comments platform_choice
Communication How to talk to the phone via PebbleKit with JavaScript and on Android or iOS. communication false /guides/communication/ false true true

All Pebble watchapps and watchfaces have the ability to communicate with the outside world through its connection to the user's phone. The PebbleKit collection of libraries (see below) is available to facilitate this communication between watchapps and phone apps. Examples of additional functionality made possible through PebbleKit include, but are not limited to apps that can:

  • Display weather, news, stocks, etc.

  • Communicate with other web services.

  • Read and control platform APIs and features of the connected phone.

Contents

{% include guides/contents-group.md group=page.group_data %}

Communication Model

Pebble communicates with the connected phone via the Bluetooth connection, which is the same connection that delivers notifications and other alerts in normal use. Developers can leverage this connection to send and receive arbitrary data using the AppMessage API.

Depending on the requirements of the app, there are three possible ways to receive data sent from Pebble on the connected phone:

  • {% guide_link communication/using-pebblekit-js %} - A JavaScript environment running within the official Pebble mobile app with web, geolocation, and extended storage access.

  • {% guide_link communication/using-pebblekit-android %} - A library available to use in Android companion apps that allows them to interact with standard Android platform APIs.

  • {% guide_link communication/using-pebblekit-ios %} - As above, but for iOS companion apps.

{% markdown %} **Important**

PebbleKit JS cannot be used in conjunction with PebbleKit Android or PebbleKit iOS. {% endmarkdown %}

All messages sent from a Pebble watchapp or watchface will be delivered to the appropriate phone app depending on the layout of the developer's project:

{% markdown %} * If at least an `index.js` file is present in `src/pkjs/`, the message will be handled by PebbleKit JS. {% endmarkdown %}
{% markdown %} * If the project contains at least one JavaScript file, the message will be handled by PebbleKit JS. {% endmarkdown %}
  • If there is no valid JS file present (at least an index.js) in the project, the message will be delivered to the official Pebble mobile app. If there is a companion app installed that has registered a listener with the same UUID as the watchapp, the message will be forwarded to that app via PebbleKit Android/iOS.