services(params, success, error)

  • Call: appc.gapi.prototype.services(params, success, error)
  • Parameters: params, success, error
    params: an object:
    {
        did:        <device id>,
        suuid:      <Service UUID [optional; otherwise all Services]>,
        primary:    <search for just primary services or not.>
    }

success: a callback accepting an object:

    {
      c: 9,                 // command
      m: 0,                 // message id (optional)
      result: 200,
      node: "0f72fdd0c8de", // id of a particular BLE device
      services: [],         // array of services available, or service requested
      subcode: 0
    }

Each object in the services array contains Service identification, including handles, UUID, and whether the service type is primary:

    {
      end: "0007"   ,   // Service end handle
      handle: "0001",   // Service start handle
      uuid: "0018",     // Service UUID
      primary: 1
    }

error: a callback accepting an object:

    { result: <result code> }

Description:

Discover device Services. Discovers GATT Services supported by a device.

The result object contains a result code, result subcode, array of services, and other operational information:

Example: services call with a callback that prints the the result object:

    gapi.services({did: "0f72fdd0c8de", primary: 1},
        function (robj) {
            console.log('services: ', JSON.stringify(robj, null, 2);
        },
        function (robj) {
            errorTxt('services: ', JSON.stringify(robj, null, 2);
        }
    );

characteristics(params, success, error)

  • Call: appc.gapi.prototype.characteristics(params, success, error)
  • Parameters: params, success, error
    params: an object:
    {
        did:        <device id>,
        sh:         <Service start handle>,
        eh:         <Service end handle>, 
        uuid:       <Characteristic UUID [optional]>
    }

success: a callback accepting an object:

    {
      c: 14,                    // command
      m: 0,                 // message id (optional)
      result: 200,
      node: "0f72fdd0c8de",     // an id of a particular device
      characteristics: [],  // array of characteristics available
      subcode: 0
    }

Each object in the characteristics array contains Characteristic identification, including handles, UUID, and properties:

    {
      properties: "12",     // Characteristic properties
      handle: "0036",       // Characteristic start handle
      end: "0037"           // Characteristic end handle
      uuid: "00002235b38d4985720e0f993a68ee41"   // Characteristic UUID
    }

error: a callback accepting an object:

    { result: <result code> }

Description:

Discover device Characteristics.

If uuid is specified, only Characteristics in the Service with that UUID will be discovered. Otherwise, all Characteristics in the Service will be discovered.

Example:

    gapi.characteristics({did: did, sh: handle, eh: end},
        function (robj) {
            console.log('characteristics: ', JSON.stringify(robj, null, 2);
        },
        function (robj) {
            console.log('characteristics: ', JSON.stringify(robj, null, 2);
        });

descriptors(params, success, error)

  • Call: appc.gapi.prototype.descriptors(params, success, error)
  • Parameters: params, success, error
    params: an object:
    {
        did:        <device id>,
        sh:         <Characteristic start handle>,
        eh:         <Characteristic end handle>,
        uuid:       <Descriptor UUID [optional]>
    }

success: A callback accepting a result object.

    {
      c: 32 or 33,              // command (all descriptors)
      m: 0,                 // message id (optional)
      result: 200,
      node: "0f72fdd0c8de",     // an id of a particular device
      descriptors: [],  // array of descriptors available
      subcode: 0
    }

Each object in the descriptors array contains Descriptor identification, including handle and UUID:

    {
      handle: "001b",       // Descriptor handle
      uuid: "0229"          // Descriptor UUID
    }

error: a callback accepting an object:

Description:

Discover device Descriptors.

If uuid is specified, only Descriptors with that UUID will be discovered. Otherwise, all Descriptors in the Characteristic will be discovered.

Example:

    gapi.descriptors({did: characteristicHandle.did, sh: characteristicHandle.sh, eh: chearacteristicHandle.eh},
        function (robj) {
            successTxt('(descriptors)', robj)   // <<-- prints the output below.
        },
        function (robj) {
            errorTxt('(descriptors)', robj);
        });