Module: Toybox.Communications
Overview
The Communications Module provides tools for communication.
With the Communications module, widgets and apps will be able to communicate with a mobile phone via Bluetooth Low Energy (BLE). The mobile phone may be sharing data with the device, or it may act as a bridge between the app and the Internet. This allows the device to become part of the Internet of Things.
Classes Under Namespace
Classes: ConnectionListener, MailboxIterator, Message, OAuthMessage, PhoneAppMessage, SyncDelegate
Constant Summary
Enumerators
Name | Value | Since | Description |
---|---|---|---|
UNKNOWN_ERROR | 0 | 1.0.0 |
An unknown error has occurred. |
BLE_ERROR | -1 | 1.0.0 |
A generic BLE error has occurred. |
BLE_HOST_TIMEOUT | -2 | 1.0.0 |
We timed out waiting for a response from the host. |
BLE_SERVER_TIMEOUT | -3 | 1.0.0 |
We timed out waiting for a response from a server. |
BLE_NO_DATA | -4 | 1.0.0 |
Response contained no data. |
BLE_REQUEST_CANCELLED | -5 | 1.0.0 |
The request was cancelled at the request of the system. |
BLE_QUEUE_FULL | -101 | 1.0.0 |
Too many requests have been made. |
BLE_REQUEST_TOO_LARGE | -102 | 1.0.0 |
Serialized input data for the request was too large. |
BLE_UNKNOWN_SEND_ERROR | -103 | 1.0.0 |
Send failed for an unknown reason. |
BLE_CONNECTION_UNAVAILABLE | -104 | 1.0.0 |
No BLE connection is available. |
INVALID_HTTP_HEADER_FIELDS_IN_REQUEST | -200 | 1.0.0 |
Request contained invalid http header fields. |
INVALID_HTTP_BODY_IN_REQUEST | -201 | 1.0.0 |
Request contained an invalid http body. |
INVALID_HTTP_METHOD_IN_REQUEST | -202 | 1.0.0 |
Request used an invalid http method. |
NETWORK_REQUEST_TIMED_OUT | -300 | 1.0.0 |
Request timed out before a response was received. |
INVALID_HTTP_BODY_IN_NETWORK_RESPONSE | -400 | 1.0.0 |
Response body data is invalid for the request type. |
INVALID_HTTP_HEADER_FIELDS_IN_NETWORK_RESPONSE | -401 | 1.0.0 |
Response contained invalid http header fields. |
NETWORK_RESPONSE_TOO_LARGE | -402 | 1.0.0 |
Serialized response was too large. |
NETWORK_RESPONSE_OUT_OF_MEMORY | -403 | 3.0.0 |
Ran out of memory processing network response. |
STORAGE_FULL | -1000 | 2.2.0 |
Filesystem too full to store response data. |
SECURE_CONNECTION_REQUIRED | -1001 | 2.3.0 |
Indicates an https connection is required for the request. |
UNSUPPORTED_CONTENT_TYPE_IN_RESPONSE | -1002 | 2.4.1 |
Content type given in response is not supported or does not match what is expected. |
REQUEST_CANCELLED | -1003 | 2.4.2 |
Http request was cancelled by the system. |
REQUEST_CONNECTION_DROPPED | -1004 | 3.0.0 |
Connection was lost before a response could be obtained. |
UNABLE_TO_PROCESS_MEDIA | -1005 | 3.0.2 |
Downloaded media file was unable to be read. |
UNABLE_TO_PROCESS_IMAGE | -1006 | 3.0.3 |
Downloaded image file was unable to be processed. |
UNABLE_TO_PROCESS_HLS | -1007 | 3.0.10 |
HLS content could not be downloaded. Most often occurs when requested and provided bit rates do not match. |
Enumerators
Name | Value | Since | Description |
---|---|---|---|
OAUTH_RESULT_TYPE_URL | 0 | 1.3.0 |
How the OAuth token will be returned in the final step. |
Enumerators
Name | Value | Since | Description |
---|---|---|---|
OAUTH_SIGNING_METHOD_HMAC_SHA1 | 0 | 1.3.0 |
How the OAuth request will be signed |
Enumerators
Name | Value | Since | Description |
---|---|---|---|
HTTP_REQUEST_METHOD_GET | 1 | 1.2.0 |
Specifies a request be executed using the GET method. |
HTTP_REQUEST_METHOD_PUT | 2 | 1.2.0 |
Specifies a request be executed using the PUT method. |
HTTP_REQUEST_METHOD_POST | 3 | 1.2.0 |
Specifies a request be executed using the POST method. |
HTTP_REQUEST_METHOD_DELETE | 4 | 1.2.0 |
Specifies a request be executed using the DELETE method. |
Enumerators
Name | Value | Since | Description |
---|---|---|---|
HTTP_RESPONSE_CONTENT_TYPE_JSON | 0 | 1.3.0 |
Content type specifier for response is expected to be a json type. Content type string must be "application/json". |
HTTP_RESPONSE_CONTENT_TYPE_URL_ENCODED | 1 | 1.3.0 |
Content type specifier for response is expected to indicate url encoding. Content type string must be "application/x-www-form-urlencoded". |
HTTP_RESPONSE_CONTENT_TYPE_GPX | 2 | 2.2.0 |
Content type specifier for response is expected to be a gpx type. |
HTTP_RESPONSE_CONTENT_TYPE_FIT | 3 | 2.2.0 |
Content type specifier for response is expected to be a FIT type. |
HTTP_RESPONSE_CONTENT_TYPE_AUDIO | 4 | 3.0.0 |
Content type specifier for response is expected to be an audio type. Content type string must be of the "audio/*" format. |
HTTP_RESPONSE_CONTENT_TYPE_TEXT_PLAIN | 5 | 3.0.0 |
Content type specifier for response is expected to be plain text type. Content type string must be "text/plain" |
HTTP_RESPONSE_CONTENT_TYPE_HLS_DOWNLOAD | 6 | 3.0.10 |
Content type specifier for response is expected to be an HLS data type. Content type string must be either "application/vnd.apple.mpegurl" or "audio/mpegurl". |
HTTP_RESPONSE_CONTENT_TYPE_ANIMATION_MANIFEST | 7 | 3.1.0 |
Content type specifier for response is expected to be a CIQ animation manifest data type. Content type string must be "application/vnd.garmin.connectiq.animation.manifest". |
HTTP_RESPONSE_CONTENT_TYPE_ANIMATION | 8 | 3.1.0 |
Content type specifier for response is expected to be a CIQ animation data type. Content type string must be "image/vnd.garmin.connectiq.animation". |
Enumerators
Name | Value | Since | Description |
---|---|---|---|
REQUEST_CONTENT_TYPE_URL_ENCODED | 0 | 1.2.0 |
Specifies a content type of application/x-www-form-urlencoded |
REQUEST_CONTENT_TYPE_JSON | 1 | 1.2.0 |
Specifies a content type of application/json |
Enumerators
Name | Value | Since | Description |
---|---|---|---|
IMAGE_DITHERING_NONE | 1 | 1.2.0 |
Do not apply dithering to an image. |
IMAGE_DITHERING_FLOYD_STEINBERG | 2 | 1.2.0 |
Apply Floyd-Steinberg dithering to an image. |
Instance Method Summary collapse
-
cancelAllRequests()
Cancel all pending JSON and Image requests.
-
emptyMailbox()
deprecated
Clear the contents of the mailbox.
-
encodeURL(url) ⇒ Toybox.Lang.String
Convert a URL String into a percent-encoded string.
-
generateSignedOAuthHeader(url, params, requestMethod, signatureMethod, token, tokenSecret, consumerKey, consumerSecret) ⇒ Toybox.Lang.String
Generate the value for the "Authorization" header in an OAuth 1.0a request.
-
getMailbox() ⇒ Toybox.Communications.MailboxIterator
deprecated
Get the MailboxIterator for this Application's mailbox.
-
makeImageRequest(url, parameters, options, responseCallback)
Request an image through Garmin Connect Mobile.
-
makeJsonRequest(url, parameters, options, responseCallback)
deprecated
To use Garmin Connect Mobile as a proxy to the web, use makeJsonRequest().
-
makeOAuthRequest(requestUrl, requestParams, resultUrl, resultType, resultKeys)
Request an OAuth sign-in through Garmin Connect Mobile.
-
makeWebRequest(url, parameters, options, responseCallback)
Use Garmin Connect Mobile as a proxy to the web.
-
notifySyncComplete(errorMessage)
Send a system notification to indicate that the sync completed.
-
notifySyncProgress(percentageComplete)
Send a system notification to indicate overall sync progress.
-
openWebPage(url, params, options)
Request that GCM issue a phone notification that will open a web page.
-
registerForOAuthMessages(method)
Register a callback for receiving OAuth messages.
-
registerForPhoneAppMessages(method)
Register a callback for receiving Phone App messages.
-
setMailboxListener(listener)
deprecated
Add a listener for mailbox events.
-
startSync()
Exit the AppBase and launch it in sync mode.
-
transmit(content, options, listener)
Send data across the the BLE link.
Instance Method Details
cancelAllRequests()
Cancel all pending JSON and Image requests.
The number of active requests running in parallel is limited in the Connect IQ platform. This call will cancel all outstanding requests.
emptyMailbox()
This method will be removed in Connect IQ 4.0.0
Clear the contents of the mailbox.
encodeURL(url) ⇒ Toybox.Lang.String
Convert a URL String into a percent-encoded string.
The reserved characters in the string will be replaced with their corresponding hex-value pairs. This follows the URI-encoding scheme as detailed by RFC 3986.
generateSignedOAuthHeader(url, params, requestMethod, signatureMethod, token, tokenSecret, consumerKey, consumerSecret) ⇒ Toybox.Lang.String
Generate the value for the "Authorization" header in an OAuth 1.0a request.
The returned value can be set as the "Authorization" header for makeWebRequest().
getMailbox() ⇒ Toybox.Communications.MailboxIterator
This method will be removed in Connect IQ 4.0.0
Get the MailboxIterator for this Application's mailbox.
makeImageRequest(url, parameters, options, responseCallback)
Request an image through Garmin Connect Mobile.
GCM will scale and dither the image based on the capabilities of the device, but the user will be able to pass additional options (like dithering it down to a one color image)
makeJsonRequest(url, parameters, options, responseCallback)
This method will be removed in Connect IQ 4.0.0
To use Garmin Connect Mobile as a proxy to the web, use makeJsonRequest().
The request is asynchronous; the responseCallback will be called when the request returns.
makeOAuthRequest(requestUrl, requestParams, resultUrl, resultType, resultKeys)
Request an OAuth sign-in through Garmin Connect Mobile.
A notification will trigger on the phone, that when clicked, provides a
web view that shows requestUrl
. If the user grants permission to the app,
then the callback registered by
registerForOAuthMessages()
will be called with an OAuthMessage
from the OAuth response.
makeWebRequest(url, parameters, options, responseCallback)
Use Garmin Connect Mobile as a proxy to the web.
Web requests are asynchronous. The supplied response callback method will be called when the request returns.
notifySyncComplete(errorMessage)
Send a system notification to indicate that the sync completed.
notifySyncProgress(percentageComplete)
Send a system notification to indicate overall sync progress.
openWebPage(url, params, options)
Request that GCM issue a phone notification that will open a web page.
This method will push a phone notification that must be accepted by the user. If the used accepts it, a web page defined by this method will be opened in the default browser on the phone.
registerForOAuthMessages(method)
Register a callback for receiving OAuth messages.
The callback will be called once for each received OAuth message. If there are messages waiting for the app when this function is called, the callback will immediately be called once for each waiting message.
registerForPhoneAppMessages(method)
Register a callback for receiving Phone App messages.
The callback will be called once for each message received. If there are messages waiting for the app when this function is called, the callback will immediately be called once for each waiting message.
setMailboxListener(listener)
This method will be removed in Connect IQ 4.0.0
Add a listener for mailbox events.
The listener method is called whenever a new message is received.
startSync()
Exit the AppBase and launch it in sync mode.
transmit(content, options, listener)
Send data across the the BLE link.