Alloy is a JavaScript framework for building Pebble apps, based on the Moddable SDK. Alloy provides developers a mix of standard Web APIs, standard Embedded JavaScript APIs from ECMA-419, and dedicated Pebble OS APIs. It allows you to write apps using modern JavaScript (ES2025, ES6++) with powerful UI frameworks and access to Pebble hardware features.
Platform Support: Alloy currently supports Emery (Pebble Time 2) and Gabbro (Pebble Round 2).
localStorage, key-value storage, or filesTo create a new Alloy project:
$ pebble new-project --alloy my-app
This creates a new project with the standard Alloy structure:
my-app/
src/
embeddedjs/
main.js # Watch code (runs on Pebble)
pkjs/
index.js # Phone code (for networking, location)
c/
mdbl.c # C code as entry point for embeddedjs (usually no need to modify)
resources/ # App resources (images, fonts)
package.json # App manifest
Alloy apps have two JavaScript environments: embeddedjs runs on the watch, while pkjs runs on the connected phone for network and location services.
The simplest Alloy app:
console.log("Hello, Pebble!");
Advanced Networking - Low-level HTTP and WebSocket clients for advanced networking needs.
Animations - Create smooth animations using Timeline and easing functions.
App Messages - Send and receive messages between the watch and the phone.
Getting Started with Alloy - Learn how to create your first Alloy app for Pebble.
Networking - Make HTTP requests and use WebSockets via the phone proxy.
Piu UI Framework - Build declarative user interfaces with the Piu framework.
Poco Graphics - Low-level graphics rendering with the Poco framework.
Port (Custom Drawing) - Combine Piu's declarative UI with custom drawing using Port.
Sensors and Input - Access Pebble sensors and handle button input in Alloy apps.
Storage - Persist data between app launches using localStorage, key-value storage, or files.
Watchfaces - Build custom watchfaces with Alloy.
The Moddable Pebble Examples repository contains a collection of examples covering all aspects of Alloy development. Here's a categorized overview:
| Example | Description |
|---|---|
| hellopebble | "Hello, world" - the simplest starting point |
| hellotimer | Using setTimeout |
| hellomodule | Loading multiple modules |
| hellotypescript | TypeScript with the Pebble Button class |
| Example | Description |
|---|---|
| hellokeyvalue | ECMA-419 Key-Value Storage for persistent data |
| hellolocalstorage | Web standard localStorage for persisting strings |
| hellofiles | File system storage |
| Example | Description |
|---|---|
| helloaccelerometer | Subscribing to accelerometer readings |
| hellobattery | Battery and charging status |
| hellolocation | GPS location via phone |
| hellobutton | Pebble button events |
| Example | Description |
|---|---|
| hellopiu-text | Dynamic text layout with different fonts |
| hellopiu-pebbletext | Text using Pebble built-in fonts |
| hellopiu-balls | Classic bouncing balls demo |
| hellopiu-coloredsquares | Drawing colored squares |
| hellopiu-gbitmap | Pebble GBitmap PNG images as Piu textures |
| hellopiu-jsicon | Moddable SDK bitmaps as Piu textures |
| hellopiu-port | Animated graph using Piu Port |
| hellopiu-timeline | Easing equations with Timeline animation |
| Example | Description |
|---|---|
| cupertino | Classic macOS watch cursor as a watchface |
| london | Big Ben (color watches only) |
| helsinki | Minimal design with per-model assets |
| redmond | Classic Windows clock |
| zurich | Iconic Swiss railway clock |
| Example | Description |
|---|---|
| hellopoco-text | Text rendering with Moddable SDK fonts |
| hellopoco-pebbletext | Text rendering with Pebble built-in fonts |
| hellopoco-gbitmap | Rendering GBitmap resources |
| hellopoco-pebblegraphics | Lines, round rectangles, and circles |
| hellopoco-qrcode | Dynamic QR code generation |
| hellopoco-pdc | Rendering PDC (SVG) images |
| hellopoco-pdc-rotate | Spinning a PDC image |
| hellopoco-pdc-scale | Animated PDC scaling with easing |
| hellopoco-pdc-sequence | PDC image sequence animation |
| hellowatchface | Simple watchface app |
| Example | Description |
|---|---|
| hellomessage | Watch-phone messaging via app_message |
| helloconnected | Phone connection status notifications |
| hellofetch | HTTP requests using the fetch() API |
| hellohttpclient | HTTP requests using ECMA-419 HTTP Client |
| hellowebsocket | WebSocket using the Web standard API |
| hellowebsocketclient | WebSocket using ECMA-419 WebSocket Client |
| Example | Description |
|---|---|
| compass | Compass visualization (Emery only) |
| gravity | Accelerometer visualization (Emery only) |