Pebble.System

System-state commands and subscriptions sourced from Pebble event services.

Poll once in init, then subscribe to live updates for battery and phone link.

import Pebble.System as System

type Msg
    = GotBattery Int
    | BatteryChanged Int
    | GotConnection Bool
    | ConnectionChanged Bool

init _ =
    ( model
    , Cmd.batch
        [ System.batteryLevel GotBattery
        , System.connectionStatus GotConnection
        ]
    )

subscriptions _ =
    Sub.batch
        [ System.onBatteryChange BatteryChanged
        , System.onConnectionChange ConnectionChanged
        ]

For a runnable example, use the watch-demo-system project template in the IDE.

Native Pebble C API

Commands

batteryLevel

batteryLevel : (Int -> msg) -> Cmd msg

Request the current battery level as a percentage from 0 to 100.

connectionStatus

connectionStatus : (Bool -> msg) -> Cmd msg

Request whether the watch is connected to the phone.

Subscriptions

onBatteryChange

onBatteryChange : (Int -> msg) -> Sub msg

Receive the current battery percentage when battery state changes.

onConnectionChange

onConnectionChange : (Bool -> msg) -> Sub msg

Receive whether the watch is connected to the phone when connection state changes.