Skip to content

rbublyk/devicehive-javascript

 
 

Repository files navigation

Build Status Bower version

#DeviceHive JavaScript framework

DeviceHive turns any connected device into the part of Internet of Things. It provides the communication layer, control software and multi-platform libraries to bootstrap development of smart energy, home automation, remote sensing, telemetry, remote control and monitoring software and much more.

Connect embedded Linux using Python or C++ libraries and JSON protocol or connect AVR, Microchip devices using lightweight C libraries and BINARY protocol. Develop client applications using HTML5/JavaScript, iOS and Android libraries. For solutions involving gateways, there is also gateway middleware that allows to interface with devices connected to it. Leave communications to DeviceHive and focus on actual product and innovation.

JavaScript framework is a wrapper around DeviceHive RESTful protocol that includes a set of methods to access corresponding DeviceHive resources.

#Components

##Client

This library could be a very good choice to quickly prototype an HTML client for your custom device. It could also be used in complex applications to enable interaction with the DeviceHive server from the client-side components. Check out DHClient API Reference to get information about all of the available fields and methods.

The library supports the following actions:

  • Authenticate with login and password or with an access key.
  • Get information about DeviceHive networks, devices and device classes
  • Get current state of equipment that devices have onboard
  • Get real-time notifications from devices about various events
  • Send a command to a particular device

##Device

This library can be used on the Device side. Any device which support javascript can be connected with DeviceHive using this module. Check out DHDevice API Reference to get information about all of the available fields and methods. The library supports the following actions:

  • Authenticate with a device key or with an access key.
  • Register and update a device in the DeviceHive network
  • Get information about the current device
  • Get and update real-time commands from clients
  • Send a notification to the cloud

#Compatibility

Client and Device libraries could be used in the following environments:

  • Chrome
  • Safari
  • Firefox
  • IE 10, 11

Node.js support will be added in future, but still you can leverage DeviceHive on node by workarounding transport related specifics. For example you can install a library which implements XMLHttpRequest and use only longpolling channel.

#Installation:

##Browser

Install package with bower:

$ bower install devicehive

or download package files from build\browser folder.

After that you should add references to your HTML file.

You can also use JQuery wrappers to utilize Deferreds instead of node-style callbacks.

#Usage

Create new instance of the DHClient or DHDevice

// Create DHClient instance specifying login and password as an auth parameters
var dhClient = new DHClient("http://xxxxx.pg.devicehive.com/api", "login", "password");

// Create DHClient instance specifying access key as an auth parameter
var dhClient = new DHClient("http://xxxxx.pg.devicehive.com/api", "AccessKeyExampleAccessKeyExampleAccessKeyEx=");

// Create DHDevice instance specifying device id and device key as an auth parameters
var dhDevice = new DHDevice("http://xxxxx.pg.devicehive.com/api", "someDeviceId_123-456", "someCustomDeviceKey");

// Create DHDevice instance specifying device id and access key as an auth parameters
var dhDevice = new DHDevice("http://xxxxx.pg.devicehive.com/api", "someDeviceId_123-456", "AccessKeyExampleAccessKeyExampleAccessKeyEx=");

or if you want to use Deferreds use builders from JQuery object

var dhClient = $.dhClient("http://xxxx.pg.devicehive.com/api", "login", "password");

After creating a new instance you will be able to get relevant information from the DeviceHive cloud

// Use DHClient library to get information about devices registered in the cloud
dhClient.getDevices(null, function(err, devices){
    if(!err)
        doWork(devices);
});

also you can register devices and update data in the cloud

// Use DHDevice library to register your device in the cloud.
// It will be registered with an id specified during DHDevice instance creation 
dhDevice.registerDevice({
    name: "My Device",
    // device key which can be used for device authentication.
    key: "some device key",
    // object with a description of the device class or existing device class id
    deviceClass: {
        name: 'My Device Class',
        version: '0.0.1',
        equipment: [
            { name: 'Example sensor', type: 'sensor', code: '1234' }
        ]
    }
}, function(err, res) {
    console.log(err ? 'failed' : 'success');
});

You can check Core Implementation, DHClient Implementation and DHDevice Implementation or read DeviceHive RESTful protocol reference to get more information about supported methods.

##Channels

The framework also implements a facility to continuously receive device notifications, send notification, receive client commands and send client commands. These features utilizes WebSocket or HTTP long-polling mechanisms supported by DeviceHive. In order to provide that functionality, the library uses a concept of channels to transmit messages between the server and client. Clients and devices should simply open a channel, subscribe to messages and then handle them in the corresponding callback methods.

To open the channel

dhClient.openChannel(callbackFunction, channelName)

Channel names are websocket and longpolling. If channelName is not passed then the first compatible channel will be opened.

You can also subscribe for a channel state changed event:

// bind
var eventSubscription = dhClient.channelStateChanged(function(state){
    console.log(state.oldState);
    console.log(state.newState);
});

// unbind
eventSubscription.unbind();

After the channel is opened your clients will be able to interact with the devices in a real-time fashion.

Take a look at this example for the Client library:

// Open the channel for DHDevice instance
dhClient.openChannel(function(err) {
    if (err) return;

    // Send device command with custom parameters to the device with deviceId identifier
    var cmd = dhClient.sendCommand(deviceId, 'command_name', {
        someParameter: 'someValue'
    });

    // Do some work after the command is processed by the device with an id "deviceId"
    cmd.result(function(res) {
        doSomeWork(res);
    }, waitTimeout);

    // Start listening for notif1 and notif2 notifications from devices with deviceId1 and deviceId2 identifiers
    var options = {
        // optional device id or array of ids
        // if not specified subscription will be created for all devices
        deviceIds: [deviceId1, deviceId2],
        // optional notification name or array of names,
        // if not specified will listen for all notifications
        names: ['notif1', 'notif2']
    };
    // pass the callback as a first parameter and options as a second
    // if options object was not passed subscription will listen for all notifications for all devices
    var subscription = dhClient.subscribe(function(err, subscription) {
        if (!err)
            console.log('subscribed successfully')
    }, options);

    // add handler for the subscription which will be invoked when a new notification is received
    subscription.message(function(notification) {
        doSomeWork(notification);
    });

    // add as many handlers as you wish
    var handler = subscription.message(function(notification) {
        doSomeAdditionalWork(notification);
    });

    // and of course you can remove any handler
    handler.unbind();
});

// Close the channel for DHClient instance
dhClient.closeChannel();

Here is an example for the Device library:

// Open the channel for DHDevice instance
dhDevice.openChannel(function(err) {
    if (err) return;

    // Send device notification with the custom parameters
    dhDevice.sendNotification('notification_name', {
        someParameter: 'someValue'
    });

    // Start listening for command1 and command2 sent by some client
    var options = {
        // optional command name or array of names,
        // if not specified will listen for all commands
        names: ['command1', 'command2']
    };
    // pass the callback as a first parameter and options as a second
    // if options object was not passed subscription will listen for all commands
    var subscription = dhDevice.subscribe(function(err, subscription) {
        if (!err)
            console.log('subscribed successfully')
    }, options);

    // add handler for the subscription which will be invoked when a new command is received
    subscription.message(function(cmd) {
        var workResult = doSomeWork(cmd);

        // Update a received command so the client can be notified about the result
        cmd.update(workResult);
    });

    // add as many handlers as you wish
    var handler = subscription.message(function(notification) {
        doSomeAdditionalWork(notification);
    });

    // and of course you can remove any handler
    handler.unbind();
});

// Close the channel for DHDevice instance
dhDevice.closeChannel();

##CONTRIBUTING

Please run gulp test before committing to ensure your changes don't affect existing features. Editor preferences are available in the editor config for easy use in common text editors. Read more and download plugins at http://editorconfig.org.

##TODO

  • Node.js support
  • Remove deprecated features

Library API Reference

  • DHClient - DeviceHive Client API Reference
  • DHDevice - DeviceHive Device API Reference

DHClient

Kind: global class
Mixes: DeviceHive

new DHClient(serviceUrl, loginOrKey, password)

DHClient object constructor specify login & password or access key as an authentication/authorization parameters

Param Type Description
serviceUrl String DeviceHive cloud API url
loginOrKey String User's login name or access key
password String User's password. If access key authentication is used this argument should be omitted

dhClient.channelStates : enum

DeviceHive channel states

Kind: instance enum property of DHClient
Mixes: channelStates
Read only: true
Properties

Name Type Default Description
disconnected number 0 channel is not connected
connecting number 1 channel is being connected
connected number 2 channel is connected

dhClient.getNetworks(filter, cb) ⇒ Http

Gets a list of networks

Kind: instance method of DHClient
Returns: Http - - current module:Core~Http request

Param Type Description
filter NetworksFilter Networks filter
cb getNetworksCb The callback that handles the response

dhClient.getNetwork(networkId, cb) ⇒ Http

Gets information about the network and associated devices

Kind: instance method of DHClient
Returns: Http - - current module:Core~Http request

Param Type Description
networkId String Network identifier
cb getNetworkCb The callback that handles the response

dhClient.getDevices(filter, cb) ⇒ Http

Gets a list of devices

Kind: instance method of DHClient
Returns: Http - - current module:Core~Http request

Param Type Description
filter DevicesFilter Devices filter
cb getDevicesCb The callback that handles the response

dhClient.getDevice(deviceId, cb) ⇒ Http

Gets information about the device

Kind: instance method of DHClient
Returns: Http - - current module:Core~Http request

Param Type Description
deviceId String Device identifier
cb getDeviceCb The callback that handles the response

dhClient.getDeviceClass(deviceClassId, cb) ⇒ Http

Gets information about a device class and associated equipment

Kind: instance method of DHClient
Returns: Http - - current module:Core~Http request
Throws:

  • Will throw an error if user's credentials are not used as an authentication mechanism
Param Type Description
deviceClassId String Device Class identifier
cb getDeviceClassCb The callback that handles the response

dhClient.getEquipmentState(deviceId, cb) ⇒ Http

Gets a list of device equipment states (current state of device equipment)

Kind: instance method of DHClient
Returns: Http - - current module:Core~Http request

Param Type Description
deviceId String Device identifier
cb getEquipmentStateCb The callback that handles the response

dhClient.getNotifications(deviceId, filter, cb) ⇒ Http

Gets a list of notifications generated by the device

Kind: instance method of DHClient
Returns: Http - - current module:Core~Http request

Param Type Description
deviceId String Device identifier
filter NotificationsFilter Notification filter
cb getNotificationsCb The callback that handles the response

dhClient.getNotification(deviceId, notificationId, cb) ⇒ Http

Gets information about a device class and associated equipment

Kind: instance method of DHClient
Returns: Http - - current module:Core~Http request

Param Type Description
deviceId String Device identifier
notificationId Number Notification identifier
cb getNotificationCb The callback that handles the response

dhClient.getCommands(deviceId, filter, cb) ⇒ Http

Gets a list of notifications generated by the device

Kind: instance method of DHClient
Returns: Http - - current module:Core~Http request

Param Type Description
deviceId String Device identifier
filter CommandsFilter Notification filter
cb getCommandsCb The callback that handles the response

dhClient.getCommand(deviceId, commandId, cb) ⇒ Http

Gets information about a device command

Kind: instance method of DHClient
Returns: Http - - current module:Core~Http request

Param Type Description
deviceId String Device identifier
commandId Number Notification identifier
cb getCommandCb The callback that handles the response

dhClient.getCurrentUser(cb) ⇒ Http

Gets information about the logged-in user and associated networks

Kind: instance method of DHClient
Returns: Http - - current module:Core~Http request
Throws:

  • Will throw an Error if an access key is used as an authentication mechanism
Param Type Description
cb getCurrentUserCb The callback that handles the response

dhClient.updateCurrentUser(user, cb) ⇒ Http

Updates information for the current user

Kind: instance method of DHClient
Returns: Http - - current module:Core~Http request
Throws:

  • Will throw an Error if an access key is used as an authentication mechanism
Param Type Description
user Object User info
cb noDataCallback The callback that handles the response

dhClient.sendCommand(deviceId, command, parameters, cb) ⇒ SendCommandResult

Sends a new command to the device

Kind: instance method of DHClient

Param Type Description
deviceId String Device identifier
command String Command name
parameters Object Command parameters
cb sendCommandCb The callback that handles the response

dhClient.openChannel(cb, [channels])

Opens the first compatible communication channel to the server

Kind: instance method of DHClient
Mixes: openChannel

Param Type Default Description
cb openChannelCb The callback that handles the response
[channels] Array | String Channel names to open. Default supported channels: 'websocket', 'longpolling'

dhClient.closeChannel(cb)

Closes the communications channel to the server

Kind: instance method of DHClient
Mixes: closeChannel

Param Type Description
cb noDataCallback The callback that handles the response

dhClient.channelStateChanged(cb)

Adds a callback that will be invoked when the communication channel state is changed

Kind: instance method of DHClient
Mixes: channelStateChanged

Param Type Description
cb channelStateChangedCb The callback that handles an event

dhClient.subscribe(cb, [params]) ⇒ Subscription

Subscribes to messages and return a subscription object

Kind: instance method of DHClient
Mixes: subscribe
Returns: Subscription - - Added subscription object

Param Type Default Description
cb subscribeCb The callback that handles the response
[params] SubscribeParameters Subscription parameters

dhClient.unsubscribe(subscriptionOrId, cb) ⇒ Subscription

Remove subscription to messages

Kind: instance method of DHClient
Mixes: unsubscribe
Returns: Subscription - - Added subscription object
Throws:

  • Will throw an error if subscriptionId was not found
Param Type Description
subscriptionOrId String | Subscription Identifier of the subscription or subscription object returned by subscribe method
cb unsubscribeCb The callback that handles the response

DHClient.channelStates

DHClient channel states

Kind: static property of DHClient

DHClient.subscriptionStates

DHClient subscription states

Kind: static property of DHClient

DHClient~NetworksFilter : Object

Get Networks request filtering parameters

Kind: inner typedef of DHClient
Properties

Name Type Description
name String filter by network name
namePattern String filter by network name pattern
sortField String result list sort field: ID or Name
take Number number of records to take from the result list
skip Number number of records to skip from the result list

DHClient~getNetworksCb : function

Kind: inner typedef of DHClient

Param Type Description
err DHError an error object if any errors occurred
networks Array an array of requested networks

DHClient~getNetworkCb : function

Kind: inner typedef of DHClient

Param Type Description
err DHError An error object if any errors occurred
network Object Requested network information

DHClient~DevicesFilter : Object

Get Devices request filtering parameters

Kind: inner typedef of DHClient
Properties

Name Type Description
name String filter by device name
namePattern String filter by device name pattern
status String filter by device status
networkId String filter by associated network identifier
networkName String filter by associated network name
deviceClassId String filter by associated device class identifier
deviceClassName String filter by associated device class name
deviceClassVersion String filter by associated device class version
sortField String result list sort field: Name, Status, Network or DeviceClass
sortOrder String result list sort order: ASC or DESC
take Number number of records to take from the result list
skip Number number of records to skip from the result list

DHClient~getDevicesCb : function

Kind: inner typedef of DHClient

Param Type Description
err DHError an error object if any errors occurred
devices Array an array of requested devices

DHClient~getDeviceCb : function

Kind: inner typedef of DHClient

Param Type Description
err DHError An error object if any errors occurred
device Object Requested device information

DHClient~getDeviceClassCb : function

Kind: inner typedef of DHClient

Param Type Description
err DHError An error object if any errors occurred
deviceClass Object Requested device class information

DHClient~getEquipmentStateCb : function

Kind: inner typedef of DHClient

Param Type Description
err DHError An error object if any errors occurred
equipmentState Array Requested array of equipment states for the specified device

DHClient~NotificationsFilter : Object

Get Notifications request filtering parameters

Kind: inner typedef of DHClient
Properties

Name Type Description
start Date filter by notification start timestamp (inclusive, UTC)
end Date filter by notification end timestamp (inclusive, UTC)
notification String filter by notification name
sortField String result list sort field - Timestamp (default) or Notification
sortOrder String result list sort order - ASC or DESC
take Number number of records to take from the result list
skip Number number of records to skip from the result list
gridInterval String grid interval in seconds. Filter to retrieve maximum one notification of the same type within the specified grid interval

DHClient~getNotificationsCb : function

Kind: inner typedef of DHClient

Param Type Description
err DHError an error object if any errors occurred
notifications Array an array of requested notifications

DHClient~getNotificationCb : function

Kind: inner typedef of DHClient

Param Type Description
err DHError An error object if any errors occurred
notification Object Requested notification information

DHClient~CommandsFilter : Object

Gets a list of commands previously sent to the device

Kind: inner typedef of DHClient
Properties

Name Type Description
start Date filter by command start timestamp (inclusive, UTC)
end Date filter by command end timestamp (inclusive, UTC)
command String filter by command name
status String filter by command status
sortField String result list sort field - Timestamp (default), Command or Status
sortOrder String result list sort order - ASC or DESC
take Number number of records to take from the result list
skip Number number of records to skip from the result list

DHClient~getCommandsCb : function

Kind: inner typedef of DHClient

Param Type Description
err DHError an error object if any errors occurred
commands Array an array of requested commands

DHClient~getCommandCb : function

Kind: inner typedef of DHClient

Param Type Description
err DHError An error object if any errors occurred
command Object requested command information

DHClient~getCurrentUserCb : function

Kind: inner typedef of DHClient

Param Type Description
err DHError An error object if any errors occurred
user Object information about the current user

DHClient~SendCommandResult : Object

Kind: inner typedef of DHClient
Properties

Name Type Description
result commandResult Waits for the command to be completed

DHClient~commandResult : function

Wait for result function

Kind: inner typedef of DHClient

Param Type Description
cb commandResultCallback
waitTimeout Number Timestamp to wait for the result in seconds. Default = 30 seconds. Maximum for longpolling channel = 60 seconds

DHClient~commandResultCallback : function

A callback function which is executed when the device has processed a command and has sent the result to the DeviceHive cloud

Kind: inner typedef of DHClient

Param Type Description
err DHError An error object if any errors occurred
res Object Processing result of the command

DHClient~sendCommandCb : function

Kind: inner typedef of DHClient

Param Type Description
err DHError An error object if any errors occurred
cmd Object Already sent command

DHDevice

Kind: global class
Mixes: DeviceHive

new DHDevice(serviceUrl, deviceId, accessKeyOrDeviceKey, forceDeviceKeyAuth)

DHDevice object constructor Specify device key or access key as an authentication/authorization parameters Auth type is predicted based on the parameters of the supplied string

Note that authentication with device key is deprecated and will be removed in future

Param Type Description
serviceUrl String DeviceHive cloud API url
deviceId String Device unique identifier
accessKeyOrDeviceKey String Access key or device key (device key is deprecated) used for auth
forceDeviceKeyAuth Boolean Force using the third parameter as a device key

dhDevice.channelStates : enum

DeviceHive channel states

Kind: instance enum property of DHDevice
Mixes: channelStates
Read only: true
Properties

Name Type Default Description
disconnected number 0 channel is not connected
connecting number 1 channel is being connected
connected number 2 channel is connected

dhDevice.getDevice(cb) ⇒ Http

Gets information about the current device

Kind: instance method of DHDevice
Returns: Http - - Current module:Core~Http request

Param Type Description
cb getDeviceCb The callback that handles the response

dhDevice.registerDevice(device, cb) ⇒ Http

Registers a device in the DeviceHive network with the current device id device key will be implicitly added if specified as an authentication parameter

Kind: instance method of DHDevice
Returns: Http - - Current module:Core~Http request

Param Type Description
device Object Device parameters
cb noDataCallback The callback that handles the response

dhDevice.updateDevice(device, cb) ⇒ Http

Updates a device in the DeviceHive network with the current device id

Kind: instance method of DHDevice
Returns: Http - - Current module:Core~Http request

Param Type Description
device Object Device parameters
cb noDataCallback The callback that handles the response

dhDevice.sendNotification(notification, params, cb) ⇒ Http

Sends new notification to the client

Kind: instance method of DHDevice
Returns: Http - - Current module:Core~Http request

Param Type Description
notification String Notification name
params Object Notification parameters
cb noDataCallback The callback that handles the response

dhDevice.subscribe(cb, params) ⇒ NotificationSubscription

Subscribes to device commands and returns a subscription object Use subscription object to bind to a 'new command received' event use command.update to specify command result parameters

Kind: instance method of DHDevice
Returns: NotificationSubscription - - Added subscription object

Param Type Description
cb notificationSubscribeCb The callback that handles the response
params NotificationSubscribeParameters Subscription parameters

dhDevice.openChannel(cb, [channels])

Opens the first compatible communication channel to the server

Kind: instance method of DHDevice
Mixes: openChannel

Param Type Default Description
cb openChannelCb The callback that handles the response
[channels] Array | String Channel names to open. Default supported channels: 'websocket', 'longpolling'

dhDevice.closeChannel(cb)

Closes the communications channel to the server

Kind: instance method of DHDevice
Mixes: closeChannel

Param Type Description
cb noDataCallback The callback that handles the response

dhDevice.channelStateChanged(cb)

Adds a callback that will be invoked when the communication channel state is changed

Kind: instance method of DHDevice
Mixes: channelStateChanged

Param Type Description
cb channelStateChangedCb The callback that handles an event

dhDevice.subscribe(cb, [params]) ⇒ Subscription

Subscribes to messages and return a subscription object

Kind: instance method of DHDevice
Mixes: subscribe
Returns: Subscription - - Added subscription object

Param Type Default Description
cb subscribeCb The callback that handles the response
[params] SubscribeParameters Subscription parameters

dhDevice.unsubscribe(subscriptionOrId, cb) ⇒ Subscription

Remove subscription to messages

Kind: instance method of DHDevice
Mixes: unsubscribe
Returns: Subscription - - Added subscription object
Throws:

  • Will throw an error if subscriptionId was not found
Param Type Description
subscriptionOrId String | Subscription Identifier of the subscription or subscription object returned by subscribe method
cb unsubscribeCb The callback that handles the response

DHDevice.channelStates

DHDevice channel states

Kind: static property of DHDevice

DHDevice.subscriptionStates

DHDevice subscription states

Kind: static property of DHDevice

DHDevice~getDeviceCb : function

Kind: inner typedef of DHDevice

Param Type Description
err module:Coremodule:CoreDHError An error object if any errors occurred
device Object Current device information

DHDevice~notificationSubscribeCb : function

Kind: inner typedef of DHDevice

Param Type Description
err module:Coremodule:CoreDHError An error object if any errors occurred
subscription NotificationSubscription added subscription object

DHDevice~NotificationSubscribeParameters : Object

Kind: inner typedef of DHDevice
Properties

Name Type Description
onMessage function initial callback that will be invoked when a command is received
names Array | String notification name, array of notifications or null (subscribe to all notifications)

DHDevice~NotificationSubscription : Subscription

Kind: inner typedef of DHDevice
Properties

Name Type Description
cb notificationReceivedCb a callback that will be invoked when a command is received

DHDevice~notificationReceivedCb : function

Kind: inner typedef of DHDevice

Param Type Description
command ReceivedCommand Received command information

DHDevice~ReceivedCommand : Object

Kind: inner typedef of DHDevice
Properties

Name Type Description
update updateCommandFunction function for updating the current command with the result

DHDevice~updateCommandFunction : function

Kind: inner typedef of DHDevice
Throws:

  • Error - throws an error if status is not specified
Param Type Description
result Object command result
cb function The callback that handles the response

DHDevice~getDeviceCb : function

Kind: inner typedef of DHDevice

Param Type Description
err module:Coremodule:CoreDHError An error object if any errors occurred
device Object Current device information

Core

Core~Subscription

Subscription object constructor

Kind: inner class of Core

subscription.stateChanged(cb)

Adds a callback that will be invoked when the subscription state is changed

Kind: instance method of Subscription

Param Type Description
cb subscriptionStateChangedCb The callback that handles an event

subscription.message(cb)

Adds a callback that will be invoked when a message is received

Kind: instance method of Subscription

Param Type Description
cb messageReceivedCb The callback that handles an event

Subscription.states : enum

Subscription states

Kind: static enum property of Subscription
Read only: true
Properties

Name Type Default Description
unsubscribed number 0 subscription is unsubscribed
subscribing number 1 subscription is being subscribed
subscribed number 2 subscription is subscribed

Core~DeviceHive

Core DeviceHive class

Kind: inner mixin of Core

DeviceHive.channelStates : enum

DeviceHive channel states

Kind: static enum property of DeviceHive
Read only: true
Properties

Name Type Default Description
disconnected number 0 channel is not connected
connecting number 1 channel is being connected
connected number 2 channel is connected

DeviceHive.openChannel(cb, [channels])

Opens the first compatible communication channel to the server

Kind: static method of DeviceHive

Param Type Default Description
cb openChannelCb The callback that handles the response
[channels] Array | String Channel names to open. Default supported channels: 'websocket', 'longpolling'

DeviceHive.closeChannel(cb)

Closes the communications channel to the server

Kind: static method of DeviceHive

Param Type Description
cb noDataCallback The callback that handles the response

DeviceHive.channelStateChanged(cb)

Adds a callback that will be invoked when the communication channel state is changed

Kind: static method of DeviceHive

Param Type Description
cb channelStateChangedCb The callback that handles an event

DeviceHive.subscribe(cb, [params]) ⇒ Subscription

Subscribes to messages and return a subscription object

Kind: static method of DeviceHive
Returns: Subscription - - Added subscription object

Param Type Default Description
cb subscribeCb The callback that handles the response
[params] SubscribeParameters Subscription parameters

DeviceHive.unsubscribe(subscriptionOrId, cb) ⇒ Subscription

Remove subscription to messages

Kind: static method of DeviceHive
Returns: Subscription - - Added subscription object
Throws:

  • Will throw an error if subscriptionId was not found
Param Type Description
subscriptionOrId String | Subscription Identifier of the subscription or subscription object returned by subscribe method
cb unsubscribeCb The callback that handles the response

Core~noDataCallback : function

A callback function which is executed when an operation has been completed

Kind: inner typedef of Core

Param Type Description
err DHError An error object if any errors occurred

Core~DHError : Object

Error object which is passed to the callback if an error occurred

Kind: inner typedef of Core
Properties

Name Type Description
error boolean Error message
http boolean An object representing a transport mechanism if an error is related ot transport problems.

Core~Http : Object

Http request object

Kind: inner typedef of Core
Properties

Name Type Description
abort function Aborts current request

##DeviceHive license

DeviceHive is developed by DataArt Apps and distributed under Open Source MIT license. This basically means you can do whatever you want with the software as long as the copyright notice is included. This also means you don't have to contribute the end product or modified sources back to Open Source, but if you feel like sharing, you are highly encouraged to do so!

© Copyright 2014 DataArt Apps © All Rights Reserved

About

DeviceHive Client & Device JavaScript libraries

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 92.7%
  • Handlebars 3.7%
  • HTML 3.1%
  • CSS 0.5%