A mechanism to store persistent application data and state.
The Persistent Storage API provides you with a mechanism for performing a variety of tasks, like saving user settings, caching data from the phone app, or counting high scores for Pebble watchapp games.
In Pebble OS, storage is defined by a collection of fields that you can create, modify or delete. In the API, a field is specified as a key with a corresponding value.
Using the Storage API, every app is able to get its own persistent storage space. Each value in that space is associated with a uint32_t key.
Storage supports saving integers, strings and byte arrays. The maximum size of byte arrays and strings is defined by PERSIST_DATA_MAX_LENGTH (currently set to 256 bytes). You call the function persist_exists(key), which returns a boolean indicating if the key exists or not. The Storage API enables your app to save its state, and when compared to using AppMessage to retrieve values from the phone, it provides you with a much faster way to restore state. In addition, it draws less power from the battery.
Note that the size of all persisted values cannot exceed 4K per app.
Checks whether a value has been set for a given key in persistent storage.
The key of the field to check.
true if a value exists, otherwise false.
Gets the size of a value for a given key in persistent storage.
The key of the field to lookup the data size.
The size of the value in bytes or E_DOES_NOT_EXIST if there is no field matching the given key.
Reads a bool value for a given key from persistent storage. If the value has not yet been set, this will return false.
The key of the field to read from.
The bool value of the key to read from.
Reads an int value for a given key from persistent storage.
The int is a signed 32-bit integer. If the value has not yet been set, this will return 0.
The key of the field to read from.
The int value of the key to read from.
Reads a blob of data for a given key from persistent storage into a given buffer. If the value has not yet been set, the given buffer is left unchanged.
The key of the field to read from.
The pointer to a buffer to be written to.
The maximum size of the given buffer.
The number of bytes written into the buffer or E_DOES_NOT_EXIST if there is no field matching the given key.
Reads a string for a given key from persistent storage into a given buffer. The string will be null terminated. If the value has not yet been set, the given buffer is left unchanged.
The key of the field to read from.
The pointer to a buffer to be written to.
The maximum size of the given buffer. This includes the null character.
The number of bytes written into the buffer or E_DOES_NOT_EXIST if there is no field matching the given key.
Writes a bool value flag for a given key into persistent storage.
The key of the field to write to.
The boolean value to write.
The number of bytes written if successful, a value from StatusCode otherwise.
Writes an int value for a given key into persistent storage.
The int is a signed 32-bit integer.
The key of the field to write to.
The int value to write.
The number of bytes written if successful, a value from StatusCode otherwise.
Writes a blob of data of a specified size in bytes for a given key into persistent storage. The maximum size is PERSIST_DATA_MAX_LENGTH.
The key of the field to write to.
The pointer to the blob of data.
The size in bytes.
The number of bytes written if successful, a value from StatusCode otherwise.
Writes a string a given key into persistent storage. The maximum size is PERSIST_STRING_MAX_LENGTH including the null terminator.
The key of the field to write to.
The pointer to null terminated string.
The number of bytes written if successful, a value from StatusCode otherwise.
Status codes. See status_t.
Operation completed successfully.
An error occurred (no description).
No idea what went wrong.
There was a generic internal logic error.
The function was not called correctly.
Insufficient allocatable memory available.
Insufficient long-term storage available.
Insufficient resources available.
Argument out of range (may be dynamic).
Target of operation does not exist.
Operation not allowed (may depend on state).
Another operation prevented this one.
Operation not completed; try again.
Equivalent of boolean true.
Equivalent of boolean false.
For list-style requests. At end of list.
No action was taken as none was required.
Return value for system operations. See StatusCode for possible values.
The maximum size of a persist value in bytes.
The maximum size of a persist string in bytes including the NULL terminator.
Do you have questions about the Pebble SDK?
Do you need some help understanding something on this page?
You can either take advantage of our awesome developer community and check out the SDK Help forums, or you can send us a message through the website!