AppMessage

The AppMessage service is primarily used for interacting with apps via the Pebble AppMessage protocol. AppMessage represents messages as flat dictionaries, with integer keys and arbitrary values. Because AppMessage dictionary values express more type information than Python types can, wrappers are provided for the relevant types.

class libpebble2.services.appmessage.AppMessageService(pebble, message_type=AppMessage)

Provides a mechanism for sending and receiving AppMessages to and from the Pebble.

Incoming messages will trigger an appmessage event with the arguments (transaction_id, app_uuid, data), where data is a python dict() containing the received values as native Python types.

AppMessageService can also be used to interact with non-AppMessage endpoints that use the same protocol, such as the legacy app state endpoint.

Parameters:
  • pebble (PebbleConnection) – The connection on which to operate.
  • message_type (PebblePacket) – The endpoint to operate on, if not the default AppMessage endpoint.
send_message(target_app, dictionary)

Send a message to the given app, which should be currently running on the Pebble (unless using a non-standard AppMessage endpoint, in which case its rules apply).

AppMessage can only represent flat dictionaries with integer keys; as such, dictionary must be flat and have integer keys.

Because the AppMessage dictionary type is more expressive than Python’s native types allow, all entries in the dictionary provided must be wrapped in one of the value types:

AppMessageService type C type Python type
Uint8 uint8_t int
Uint16 uint16_t int
Uint32 uint32_t int
Int8 int8_t int
Int16 int16_t int
Int32 int32_t int
CString char * str
ByteArray uint8_t * bytes

For instance:

appmessage.send_message(UUID("6FEAF2DE-24FA-4ED3-AF66-C853FA6E9C3C"), {
    16: Uint8(62),
    6428356: CString("friendship"),
})
Parameters:
  • target_app (UUID) – The UUID of the app to which to send a message.
  • dictionary (dict) – The dictionary to send.
Returns:

The transaction ID sent message, as used in the ack and nack events.

Return type:

int

shutdown()

Unregisters the AppMessageService from the PebbleConnection that was passed into the constructor. After calling this method, no more events will be fired.

class libpebble2.services.appmessage.Uint8(value)

Represents a uint8_t

class libpebble2.services.appmessage.Uint16(value)

Represents a uint16_t

class libpebble2.services.appmessage.Uint32(value)

Represents a uint32_t

class libpebble2.services.appmessage.Int8(value)

Represents an int8_t

class libpebble2.services.appmessage.Int16(value)

Represents an int16_t

class libpebble2.services.appmessage.Int32(value)

Represents an int32_t

class libpebble2.services.appmessage.CString(value)

Represents a char *

class libpebble2.services.appmessage.ByteArray(value)

Represents a uint8_t *