Connect IQ > APIメモ > Toybox > Communications

下位ページ

Content

Module: Toybox::Communications

Widget や Apps が Bluetooth Low Energy (BLE) を通じてスマホ(携帯電話)と通信をするために用いる。
スマホはデバイスとデータを共有したり、アプリやネットとの架け橋となり、ウェアラブルウェブの一部となる。

  • Since : 1.0.0
  • Supported Devices : All devices
  • App Types : Widget, App
  • Requires Permission : Communications

Defined Under Namespace

  • Classes : ConnectionListener, MailboxIterator

Constant Summary

  • UNKNOWN_ERROR = 0 : Additional Resonse codes that can occur from JSON requests. Since : 1.0.0

  • BLE_ERROR = -1 : Since:1.0.0
  • BLE_HOST_TIMEOUT = -2 : Since:1.0.0
  • BLE_SERVER_TIMEOUT = -3 : Since:1.0.0
  • BLE_NO_DATA = -4 : Since:1.0.0
  • BLE_REQUEST_CANCELLED = -5 : Since:1.0.0
  • BLE_QUEUE_FULL = -101 : Since:1.0.0
  • BLE_REQUEST_TOO_LARGE = -102 : Since:1.0.0
  • BLE_UNKNOWN_SEND_ERROR = -103 : Since:1.0.0
  • BLE_CONNECTION_UNAVAILABLE = -104 : Since:1.0.0

  • INVALID_HTTP_HEADER_FIELDS_IN_REQUEST = -200 : Since:1.0.0
  • INVALID_HTTP_BODY_IN_REQUEST = -201 : Since:1.0.0
  • INVALID_HTTP_METHOD_IN_REQUEST = -202 : Since:1.0.0

  • NETWORK_REQUEST_TIMED_OUT = -300 : Since:1.0.0

INVALID_HTTP_BODY_IN_NETWORK_RESPONSE = -400
Since:1.0.0

INVALID_HTTP_HEADER_FIELDS_IN_NETWORK_RESPONSE = -401
Since:1.0.0

NETWORK_RESPONSE_TOO_LARGE = -402
Since:1.0.0

HTTP_REQUEST_METHOD_GET = 1 : Since:1.2.0
HTTP_REQUEST_METHOD_PUT = 2 : Since:1.2.0
HTTP_REQUEST_METHOD_POST = 3 : Since:1.2.0
HTTP_REQUEST_METHOD_DELETE = 4 : Since:1.2.0

  • REQUEST_CONTENT_TYPE_URL_ENCODED = 0 : These values are used in conjunction with the "Content-Type" header key. Specifies a content type of application/x-www-form-urlencoded. Since:1.2.0
  • REQUEST_CONTENT_TYPE_JSON = 1 : Specifies a content type of application/json. Since:1.2.0
  • IMAGE_DITHERING_NONE = 1 : Since:1.2.0
  • IMAGE_DITHERING_FLOYD_STEINBERG = 2 : Since:1.2.0

Instance Method Summary

(collapse)
  • (Object) cancelAllRequests : To cancel all pending JSON and Image requests use cancelAllRequests().
   - (Object) emptyMailbox

   To clear the contents of the mailbox, call emptyMailbox().
   - (String) encodeURL(url)

   Convert a URL string into a percent-encoded string.
  • (MailboxIterator) getMailbox : Call getMailbox() to get the MailboxIterator for this App's mailbox.
   - (Object) makeImageRequest(url, parameters, options, responseCallback)

   To request an image through Garmin Connect Mobile, call makeImageRequest().
   - (Object) makeJsonRequest(url, parameters, options, responseCallback)

   To use Garmin Connect Mobile as a proxy to the web, use makeJsonRequest().
   - (Object) setMailboxListener(listener)

   Add a listener for mailbox events.
   - (Object) transmit(content, options, listener)

   Send data across the the BLE link.

Instance Method Details
  • (Object) cancelAllRequests

To cancel all pending JSON and Image requests use cancelAllRequests()

Since:

   1.2.0

  • (Object) emptyMailbox

To clear the contents of the mailbox, call emptyMailbox().

Since:

   1.0.0

  • (String) encodeURL(url)

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 which can be found here: www.ietf.org/rfc/rfc3986.txt

Parameters:

   url (String) —

   The URL string to be encoded

Returns:

   (String) —

   Percent-encoded string

Since:

   1.1.2

  • (MailboxIterator) getMailbox

Call getMailbox() to get the MailboxIterator for this App's mailbox.

Returns:

   (MailboxIterator) —

   Iterator for the mailbox

Since:

   1.0.0

  • (Object) makeImageRequest(url, parameters, options, responseCallback)

To request an image through Garmin Connect Mobile, call makeImageRequest(). 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)

Parameters:

   url (String) —

   URL of image to request
   parameters (Dictionary) —

   Dictionary of keys and values, appended to the URL. Can be null.
   options (Dictionary) —

   Additional image options
   responseCallback (Method) —

   This is a callback in the format function responseCallback(responseCode, data); responseCode has the server response code, and data contains a WatchUi.BitmapResource if it was successful.

Options Hash (options):

   :palette (Array) —

   The color palette to restrict the image dithering to. Using a smaller palette can reduce the size of the image data to speed up transfers.
   :maxWidth (Number) —

   The maximum width an image should be scaled to
   :maxHeight (Number) —

   The maximum height an image should be scaled to
   :dithering (Number) —

   The type of dithering to use when processing the image. Defaults to Floyd-Steinberg.

Since:1.2.0

(Object) makeJsonRequest(url, parameters, options, responseCallback) : 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.

  • Parameters:
    • url (String) : The URL being requested
    • parameters (Dictionary) : Dictionary of keys and values, appended to the URL as a GET request or set as the body for a POST request. Can be null.
    • options (Dictionary) : Dictionary of options. Can be null.
    • responseCallback (Method) : This is a callback in the format function responseCallback(responseCode, data); responseCode has the server response code, and data contains a Dictionary of content if the request was successful.

Options Hash (options):

   :method (Number) —

   The HTTP method of the request. Should be a HTTP_REQUEST_METHOD_* value.
   :headers (Dictionary) —

   A Dictionary of HTTP headers to include in the request. The “Content-Type” header can be specified using a REQUEST_CONTENT_TYPE_* value. If the content type is not specified, it will default to “appllication/json” for GET and DELETE requests, and will default to “application/x-www-form-urlencoded” for POST and PUT requests.

Since:

   1.0.0

  • (Object) setMailboxListener(listener)

Add a listener for mailbox events. The listener method is called whenever a new message is received

Parameters:

   listener (Method) —

   Callback in the format function listener(iterator) where iterator is the mailbox iterator for the app

Since:

   1.0.0

(Object) transmit(content, options, listener) : BLEリンクからデータを送る

  • Parameters :
    • content (Object) : The object to be sent
    • options (Dictionary) : Additional transmit options (TBD)
    • listener (ConnectionListener) : An extension of the ConnectionListener class

Since : 1.0.0
最終更新:2016年07月30日 23:36