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
appmessageevent with the arguments(transaction_id, app_uuid, data), wheredatais a pythondict()containing the received values as native Python types.AppMessageServicecan 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
AppMessageendpoint.
-
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,
dictionarymust 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 Uint8uint8_tintUint16uint16_tintUint32uint32_tintInt8int8_tintInt16int16_tintInt32int32_tintCStringchar *strByteArrayuint8_t *bytesFor instance:
appmessage.send_message(UUID("6FEAF2DE-24FA-4ED3-AF66-C853FA6E9C3C"), { 16: Uint8(62), 6428356: CString("friendship"), })
Parameters: Returns: The transaction ID sent message, as used in the
ackandnackevents.Return type:
-
shutdown()¶ Unregisters the
AppMessageServicefrom thePebbleConnectionthat 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 *