subscribe(params, success, error)

  • Call: appc.gapi.prototype.subscribe(params, success, error)
  • Parameters: params, success, error
    params: an object:
    { 
        did:        <device id>,
        ch:         <Characteristic handle>,
        notify:     <1 (Notification) or 0 (Indication)>
    }

success: a callback accepting a result object:

    {
        c: 26 or 27,                // command
        m: 0,                   // message id (optional)
        result: <result code>,
        subcode: <result subcode>,
        node: <device id>
    }

error: a callback accepting a result object:

    { result: <result code> }

Description:

Subscribe to a Notification or Indication.

Given a device id, did and a handle to a characeteristic this method requests a notification to be processed by the success callback of report;

Example:

    var params = { did: node, ch: handle };

    gapi.subscribe(params,
        function (robj) {
            console.log('subscribe: ', JSON.stringify(robj, null, 2);
        },
        function (errObj) {
            console.log('subscribe: ', JSON.stringify(robj, null, 2);
        });
    );

unsubscribe(params, success, error)

  • Call: appc.gapi.prototype.unsubscribe(params, success, error)
  • Parameters: params, success, error
    params: A JavaScript object with properties:   did,   ch,   notify (see below)
{ 
    did:        <device id>,
    ch:         <Characteristic handle>,
    notify:     <1 (Notification) or 0 (Indication)>
}

success: a callback accepting a result object:

    {
        c: 26 or 27,
        m: 0,
        result: <result code>,
        subcode: <result subcode>,
        node: <device id> 
    }

error: a callback accepting a result object:

    { result: <result code> }

Description:

Unsubscribe from a Notification or Indication.

Example:

    var params = { did: node, ch: handle, notify: 1 };

    gapi.unsubscribe(params,
        function (robj) {
            console.log('subscribe: ', JSON.stringify(robj, null, 2);
        },
        function (errObj) {
            console.log('subscribe: ', JSON.stringify(robj, null, 2);
        });

read(params, success, error)

  • Call: appc.gapi.prototype.read(params, success, error)
  • Parameters: params, success, error
    params: an object:
{
    did:        <device id>,
    ch:         <Characteristic handle>
}

success: a callback accepting a result object:

    {
        c: 20 or 34,
        m: 0,
        result: <result code>,
        subcode: <result subcode>,
        node: <device id>,
        handle: <Attribute handle>,
        value: <Attribute value>
    }

error: a callback accepting a result object:

    { result: <result code> }

Description:

Read device Characteristic or Descriptor.

Example:

    var params = {did: node, ch: handle};

    gapi.read(params,
        function (robj) {
            console.log('subscribe: ', JSON.stringify(robj, null, 2);
        },
        function (errObj) {
            console.log('subscribe: ', JSON.stringify(robj, null, 2);
        });

write(params, success, error)

  • Call: appc.gapi.prototype.write(params, success, error)
  • Parameters: params, success, error
    params: an object:
{
    did:        <device id>,
    ch:         <Characteristic handle>,
    dh:         <Descriptor handle>
    value:      <Characteristic Value>
}

success: a callback accepting a result object:

    {
        c: 28 or 29 or 35 or 36,
        m: 0,
        result: <result code>,
        subcode: <result subcode>,
        node: <device id>,
    }

error: a callback accepting a result object:

    { result: <result code> }

Description:

Write device Characteristic or Descriptor value.

Multi-octet values are encoded and in little-endian format. So, the 16-bit integer 0xABCD would use a 4-character string 'CDAB' for the value.

Example:

    var params = {did: node, ch: handle, value: 0};

    gapi.write(params,
        function (robj) {
            console.log('subscribe: ', JSON.stringify(robj, null, 2);
        },
        function (errObj) {
            console.log('subscribe: ', JSON.stringify(robj, null, 2);
        });

writenoresponse(params, success, error)

  • Call: appc.gapi.prototype.writenoresponse(params, success, error)
  • Parameters: params, success, error
    params: an object:
{
    did:        <device id>,
    ch:         <Characteristic handle>,
    value:      <Characteristic>
}

success: a callback accepting a result object:

    {
        c: 30,
        m: 0,
        result: <result code>,
        subcode: <result subcode>,
        node: <device id>,
    }

error: a callback accepting a result object:

    { result: <result code> }

Description:

Write device Characteristic without a response.

Example:

    var params = {did: node, ch: handle, value: 0};

    gapi.writenoresponse(params,
        function (robj) {
            console.log('subscribe: ', JSON.stringify(robj, null, 2);
        },
        function (errObj) {
            console.log('subscribe: ', JSON.stringify(robj, null, 2);
        });