devicehive v2.1.0
DeviceHive-javascript
DeviceHive-javascript is promise-based library for using DeviceHive.
Installation Instructions
For Node.js use case (Node v4.x on Mac, Linux, or Windows on a x86 or x64 processor), DeviceHive-javascript will install nice and easy with:
npm install devicehive
Generation bundle for browser usage
In case you want to use DeviceHive-javascript in the browser:
1. Clone repo;
2. Inside repo folder run npm install
;
3. Inside repo folder run npm run build
;
4. Get devicehive.js
/devicehive.min.js
in dist
folder.
Usage
During development you can use this library with Promises, and Async/Await functions.
Connecting to DeviceHive
Using HTTP/HTTPS
Note: Using HTTP/HTTPS you need to pass 3 different service URL`s: mainServiceURL, authServiceURL and pluginServiceURL.
const DeviceHive = require('devicehive');
const httpDeviceHive = new DeviceHive({
login: 'login',
password: 'password',
mainServiceURL: 'http://<host>:<port>/<path>',
authServiceURL: 'http://<host>:<port>/<path>',
pluginServiceURL: 'http://<host>:<port>/<path>'
});
httpDeviceHive.connect();
Using WebSocket
Note: Using WebSocket you need to pass only one service URL: mainServiceURL.
const DeviceHive = require('devicehive');
const wsDeviceHive= new DeviceHive({
login: 'login',
password: 'password',
mainServiceURL: 'ws://<host>:<port>/<path>'
});
wsDeviceHive.connect();
Using Models
You can use models described in DeviceHive.models
// Getting Device model
const Device = DeviceHive.models.Device;
// Getting Device list query model
const DeviceListQuery = DeviceHive.models.query.DeviceListQuery;
Full Example and using API
You can use API described in DeviceHive.command, DeviceHive.configuration, DeviceHive.device, DeviceHive.deviceType, DeviceHive.info, DeviceHive.notification, DeviceHive.network, DeviceHive.plugin, DeviceHive.token, DeviceHive.user.
Here is example of how you can use DeviceHive-javascript:
const DeviceHive = require('devicehive');
// Getting Device model
const Device = DeviceHive.models.Device
// Getting Device list query model
const DeviceListQuery = DeviceHive.models.query.DeviceListQuery;
// Configurating DeviceHive
const myDeviceHive = new DeviceHive({
login: 'login',
password: 'password',
mainServiceURL: 'ws://<host>:<port>/<path>'
});
// Configurating Device model
const device = new Device({
id: 'myTestId',
name: 'myTestName',
networkId: 1,
deviceTypeId: 1,
blocked: false
});
// Configurating Device List query
const myDeviceListQuery = new DeviceListQuery({
networkId: 1
});
// Push message handler
myDeviceHive.on(DeviceHive.MESSAGE_EVENT, (message) => {
console.log(message);
});
// Error handler
myDeviceHive.on(DeviceHive.ERROR_EVENT, (error) => {
console.error(error);
});
// Connecting and usin API
myDeviceHive.connect()
.then(() => myDeviceHive.device.list(myDeviceListQuery))
.then(data => console.log(data))
.then(() => myDeviceHive.device.add(device))
.then(data => console.log(data))
.then(() => myDeviceHive.device.list(myDeviceListQuery))
.then(data => console.log(data))
.then(() => myDeviceHive.device.delete(device.id))
.then(data => console.log(data))
.then(() => myDeviceHive.device.list(myDeviceListQuery))
.then(data => console.log(data))
.catch(error => console.warn(error));
API Reference
DeviceHive
DeviceHive module
- DeviceHive
- new DeviceHive(options)
- instance
- static
- .models : Object
new DeviceHive(options)
DeviceHive module
Param | Type | Description |
---|---|---|
options | object | Initial settings |
options.accessToken | string | Access token |
options.refreshToken | string | Refresh token |
options.login | string | Login |
options.password | string | Password |
options.mainServiceURL | string | Main Service URL |
options.authServiceURL | string | Auth Service URL (required only for http) |
options.pluginServiceURL | string | Plugin Service URL (required only for http) |
options.autoUpdateSession | boolean | Flag to enable/disable autoupdating session. Default: true |
deviceHive.connect({ accessToken, refreshToken, login, password, reconnectionAttempts, reconnectionInterval })
Connect and authorize
Params: | Param | Type | Description | | --- | --- | --- | | options.accessToken | string | Access token (default DeviceHive constructor configuration) (optional) | | options.refreshToken | string | Refresh token (default DeviceHive constructor configuration) (optional) | | options.login | string | Login (default DeviceHive constructor configuration) (optional) | | options.password | string | Password (default DeviceHive constructor configuration) (optional) | | options.reconnectionAttempts | number | Reconnection attempts (default infinity (-1)) (optional) | | options.reconnectionInterval | number | Reconnection interval in ms (default 5000) (optional) |
DeviceHive.models : Object
Returns DeviceHive models
- Command
- Configuration
- DeviceType
- Network
- Notification
- UserToken
- PluginToken
- User
- query
- CommandListQuery
- CommandPollManyQuery
- CommandPollQuery
- CommandWaitQuery
- DeviceCountQuery
- DeviceListQuery
- DeviceTypeCountQuery
- DeviceTypeListQuery
- DeviceTypeDeleteQuery
- PluginUpdateQuery
- NetworkCountQuery
- NetworkListQuery
- NetworkDeleteQuery
- NotificationListQuery
- NotificationPollManyQuery
- NotificationPollQuery
- UserCountQuery
- UserListQuery
- PluginCountQuery
- PluginListQuery
- PluginRegisterQuery
DeviceHive.command: Object
Look at DeviceCommandAPI.
DeviceHive.configuration : Object
Look at ConfigurationAPI.
DeviceHive.device: Object
Look at DeviceAPI.
DeviceHive.deviceType: Object
Look at deviceTypeAPI.
DeviceHive.info: Object
Look at InfoAPI.
DeviceHive.notification: Object
Look at DeviceNotificationAPI.
DeviceHive.network: Object
Look at NetworkAPI.
DeviceHive.plugin: Object
Look at PluginAPI.
DeviceHive.token: Object
Look at TokenAPI.
DeviceHive.user: Object
Look at UserAPI.
Nested DeviceHive API
ConfigurationAPI
Returns information about the current configuration
- ConfigurationAPI
- .get(name) ⇒ Promise
- .put(configuration) ⇒ Promise
- .delete(name) ⇒ Promise
configurationAPI.get(name) ⇒ Promise
Creates ConfigurationAPI
Param | Type |
---|---|
name | number |
configurationAPI.put(configuration) ⇒ Promise
Updates a configuration
Param | Type |
---|---|
configuration | Configuration |
configurationAPI.delete(name) ⇒ Promise
Deletes an existing configuration
Param | Type |
---|---|
name | number |
DeviceAPI
Returns information about the current device
- DeviceAPI
- .get(deviceId) ⇒ Promise
- .list(deviceListQuery) ⇒ Promise
- .count(deviceCountQuery) ⇒ Promise
- .add(device) ⇒ Promise
- .delete(deviceId) ⇒ Promise
deviceAPI.get(deviceId) ⇒ Promise
Creates DeviceAPI
Param | Type |
---|---|
deviceId | string |
deviceAPI.list(deviceListQuery) ⇒ Promise
Return a list of devices
Param | Type |
---|---|
deviceListQuery | DeviceListQuery |
deviceAPI.count(deviceCountQuery) ⇒ Promise
Returns count of devices
Param | Type |
---|---|
deviceCountQuery | DeviceCountQuery |
deviceAPI.add(device) ⇒ Promise
Registers or updates a device
Param | Type | Description |
---|---|---|
device | object | data |
deviceAPI.delete(deviceId) ⇒ Promise
Deletes an existing device
Param | Type |
---|---|
deviceId | string |
DeviceCommandAPI
Returns information about the current command
- DeviceCommandAPI
- .get(deviceId, commandId) ⇒ Promise
- .list(commandListQuery) ⇒ Promise
- .insert(deviceId, command) ⇒ Promise
- .update(command) ⇒ Promise
- .poll(commandPollQuery) ⇒ Promise
- .pollMany(commandPollManyQuery) ⇒ Promise
- .wait(deviceId, commandId) ⇒ Promise
- .subscribe(commandPollQuery) ⇒ Promise
- .unsubscribe(subscriptionId) ⇒ Promise
deviceCommandAPI.get(deviceId, commandId) ⇒ Promise
Creates DeviceCommandAPI
Param | Type | Description |
---|---|---|
deviceId | number | Device ID |
commandId | number | Command ID |
deviceCommandAPI.list(commandListQuery) ⇒ Promise
Return a list of commands
Param | Type |
---|---|
commandListQuery | CommandListQuery |
deviceCommandAPI.insert(deviceId, command) ⇒ Promise
Registers a command
Param | Type | Description |
---|---|---|
deviceId | number | Device ID |
command | Command |
deviceCommandAPI.update(command) ⇒ Promise
Updates a command
Param | Type |
---|---|
command | Command |
deviceCommandAPI.poll(commandPollQuery) ⇒ Promise
Param | Type |
---|---|
commandPollQuery | CommandPollQuery |
deviceCommandAPI.pollMany(commandPollManyQuery) ⇒ Promise
Param | Type |
---|---|
commandPollManyQuery | CommandPollManyQuery |
deviceCommandAPI.wait(deviceId, commandId) ⇒ Promise
Param |
---|
deviceId |
commandId |
deviceCommandAPI.subscribe(commandPollQuery) ⇒ Promise
Param | Type |
---|---|
commandPollQuery | CommandPollQuery |
deviceCommandAPI.unsubscribe(subscriptionId) ⇒ Promise
Param | Type |
---|---|
subscriptionId | Number |
DeviceNotificationAPI
Returns information about the current notification
- DeviceNotificationAPI
- .get(deviceId, notificationId) ⇒ Promise
- .list(notificationListQuery) ⇒ Promise
- .insert(notification) ⇒ Promise
- .poll(notificationPollQuery) ⇒ *
- .pollMany(notificationPollManyQuery) ⇒ *
- .subscribe(notificationPollQuery) ⇒ Promise
- .unsubscribe(subscriptionId) ⇒ Promise
deviceNotificationAPI.get(deviceId, notificationId) ⇒ Promise
Creates DeviceNotificationAPI
Param | Type | Description |
---|---|---|
deviceId | number | Device ID |
notificationId | number | Notification ID |
deviceNotificationAPI.list(notificationListQuery) ⇒ Promise
Return a list of notifications
Param | Type |
---|---|
notificationListQuery | NotificationListQuery |
deviceNotificationAPI.insert(notification) ⇒ Promise
Registers a notification
Param | Type |
---|---|
notification | Notification |
deviceNotificationAPI.poll(notificationPollQuery) ⇒ *
Param | Type |
---|---|
notificationPollQuery | NotificationPollQuery |
deviceNotificationAPI.pollMany(notificationPollManyQuery) ⇒ *
Param | Type |
---|---|
notificationPollManyQuery | NotificationPollManyQuery |
deviceNotificationAPI.subscribe(notificationPollQuery) ⇒ Promise
Param | Type |
---|---|
notificationPollQuery | NotificationPollQuery |
deviceNotificationAPI.unsubscribe(subscriptionId) ⇒ Promise
Param | Type |
---|---|
subscriptionId | Number |
DeviceTypeAPI
Returns information about the current deviceType
- DeviceTypeAPI
- .get(deviceTypeId) ⇒ Promise
- .list(deviceTypeListQuery) ⇒ Promise
- .count(deviceTypeCountQuery) ⇒ Promise
- .insert(deviceType) ⇒ Promise
- .update(deviceType) ⇒ Promise
- .delete(deviceTypeDeleteQuery) ⇒ Promise
deviceTypeAPI.get(deviceTypeId) ⇒ Promise
Creates DeviceTypeAPI
Param | Type |
---|---|
deviceTypeId | number |
deviceTypeAPI.list(deviceTypeListQuery) ⇒ Promise
Return a list of deviceTypes
Param | Type |
---|---|
deviceTypeListQuery | DeviceTypeListQuery |
deviceTypeAPI.count(deviceTypeCountQuery) ⇒ Promise
Returns count of deviceTypes
Param | Type |
---|---|
deviceTypeCountQuery | DeviceTypeCountQuery |
deviceTypeAPI.insert(deviceType) ⇒ Promise
Registers a deviceType
Param | Type | Description |
---|---|---|
deviceType | DeviceType | data |
deviceTypeAPI.update(deviceType) ⇒ Promise
Updates a deviceType
Param | Type | Description |
---|---|---|
deviceType | DeviceType | data |
deviceTypeAPI.delete(deviceTypeDeleteQuery) ⇒ Promise
Deletes an existing deviceType
Param | Type |
---|---|
deviceTypeDeleteQuery | deviceTypeDeleteQuery |
NetworkAPI
Returns information about the current network
- NetworkAPI
- .get(networkId) ⇒ Promise
- .list(networkListQuery) ⇒ Promise
- .count(networkCountQuery) ⇒ Promise
- .insert(network) ⇒ Promise
- .update(networkId, network) ⇒ Promise
- .delete(networkDeleteQuery) ⇒ Promise
networkAPI.get(networkId) ⇒ Promise
Returns a network
Param | Type |
---|---|
networkId | number |
networkAPI.list(networkListQuery) ⇒ Promise
Return a list of networks
Param | Type |
---|---|
networkListQuery | NetworkListQuery |
networkAPI.count(networkCountQuery) ⇒ Promise
Returns count of networks
Param | Type |
---|---|
networkCountQuery | NetworkCountQuery |
networkAPI.insert(network) ⇒ Promise
Registers a network
Param | Type | Description |
---|---|---|
network | Network | data |
networkAPI.update(networkId, network) ⇒ Promise
Updates a network
Param | Type | Description |
---|---|---|
networkId | number | |
network | Network | data |
networkAPI.delete(networkDeleteQuery) ⇒ Promise
Deletes an existing network
Param | Type |
---|---|
networkDeleteQuery | networkDeleteQuery |
PluginAPI
Returns information about the current plugin
- PluginAPI
- .list(pluginListQuery) ⇒ Promise
- .count(pluginCountQuery) ⇒ Promise
- .insert(plugin, pluginRegisterQuery) ⇒ Promise
- .update(plugin) ⇒ Promise
- .delete(Plugin) ⇒ Promise
pluginAPI.list(pluginListQuery) ⇒ Promise
Return a list of plugins
Param | Type |
---|---|
pluginListQuery | PluginListQuery |
pluginAPI.count(pluginCountQuery) ⇒ Promise
Returns count of plugins
Param | Type |
---|---|
pluginCountQuery | PluginCountQuery |
pluginAPI.insert(plugin, pluginRegisterQuery) ⇒ Promise
Registers a plugin
Param | Type |
---|---|
plugin | Plugin |
pluginRegisterQuery | PluginRegisterQuery |
pluginAPI.update(plugin) ⇒ Promise
Updates a plugin
Param | Type |
---|---|
plugin | Promise |
pluginAPI.delete(Plugin) ⇒ Promise
Deletes an existing plugin
Param | Type |
---|---|
Plugin | object |
InfoAPI
Get server info
infoAPI.getServerInfo()
Creates InfoAPI
infoAPI.getCacheInfo()
Get cache info
infoAPI.getClusterInfo()
Get cluster info
TokenAPI
Authentificate using login and password
tokenAPI.login(login, password)
Creates TokenAPI
Param | Type |
---|---|
login | string |
password | string |
tokenAPI.authPlugin(token)
Create user token
Param | Type | Description |
---|---|---|
token | string | Plugin token |
tokenAPI.createUserToken(userToken)
Create user token
Param | Type |
---|---|
userToken | UserToken |
tokenAPI.createPluginToken(pluginToken)
Create plugin token
Param | Type |
---|---|
pluginToken | PluginToken |
tokenAPI.refresh(refreshToken)
Refresg token
Param | Type |
---|---|
refreshToken | string |
UserAPI
ConfigurationAPI
Returns information about the current configuration
- ConfigurationAPI
- .get(name) ⇒ Promise
- .put(configuration) ⇒ Promise
- .delete(name) ⇒ Promise
configurationAPI.get(name) ⇒ Promise
Creates ConfigurationAPI
Returns: Promise - selected configuration
Param | Type |
---|---|
name | number |
configurationAPI.put(configuration) ⇒ Promise
Updates a configuration
Returns: Promise - count of configuration
Param | Type |
---|---|
configuration | Configuration |
configurationAPI.delete(name) ⇒ Promise
Deletes an existing configuration
Param | Type |
---|---|
name | number |
DeviceAPI
Returns information about the current device
- DeviceAPI
- .get(deviceId) ⇒ Promise
- .list(deviceListQuery) ⇒ Promise
- .count(deviceCountQuery) ⇒ Promise
- .add(device) ⇒ Promise
- .delete(deviceId) ⇒ Promise
deviceAPI.get(deviceId) ⇒ Promise
Creates DeviceAPI
Returns: Promise - selected device
Param | Type |
---|---|
deviceId | string |
deviceAPI.list(deviceListQuery) ⇒ Promise
Return a list of devices
Returns: Promise - list of devices
Param | Type |
---|---|
deviceListQuery | DeviceListQuery |
deviceAPI.count(deviceCountQuery) ⇒ Promise
Returns count of devices
Returns: Promise - count of devices
Param | Type |
---|---|
deviceCountQuery | DeviceCountQuery |
deviceAPI.add(device) ⇒ Promise
Registers or updates a device
Returns: Promise - count of devices
Param | Type | Description |
---|---|---|
device | object | data |
deviceAPI.delete(deviceId) ⇒ Promise
Deletes an existing device
Param | Type |
---|---|
deviceId | string |
DeviceCommandAPI
Returns information about the current command
- DeviceCommandAPI
- .get(deviceId, commandId) ⇒ Promise
- .list(commandListQuery) ⇒ Promise
- .insert(deviceId, command) ⇒ Promise
- .update(command) ⇒ Promise
- .poll(commandPollQuery) ⇒ Promise
- .pollMany(commandPollManyQuery) ⇒ Promise
- .wait(deviceId, commandId) ⇒ Promise
- .subscribe(commandPollQuery) ⇒ Promise
- .unsubscribe(subscriptionId) ⇒ Promise
deviceCommandAPI.get(deviceId, commandId) ⇒ Promise
Creates DeviceCommandAPI
Returns: Promise - selected command
Param | Type | Description |
---|---|---|
deviceId | number | Device ID |
commandId | number | Command ID |
deviceCommandAPI.list(commandListQuery) ⇒ Promise
Return a list of commands
Returns: Promise - list of commands
Param | Type |
---|---|
commandListQuery | CommandListQuery |
deviceCommandAPI.insert(deviceId, command) ⇒ Promise
Registers a command
Returns: Promise - count of commands
Param | Type | Description |
---|---|---|
deviceId | number | Device ID |
command | Command |
deviceCommandAPI.update(command) ⇒ Promise
Updates a command
Returns: Promise - count of commands
Param | Type |
---|---|
command | Command |
deviceCommandAPI.poll(commandPollQuery) ⇒ Promise
Param | Type |
---|---|
commandPollQuery | CommandPollQuery |
deviceCommandAPI.pollMany(commandPollManyQuery) ⇒ Promise
Param | Type |
---|---|
commandPollManyQuery | CommandPollManyQuery |
deviceCommandAPI.wait(deviceId, commandId) ⇒ Promise
Param |
---|
deviceId |
commandId |
deviceCommandAPI.subscribe(commandPollQuery) ⇒ Promise
Param | Type |
---|---|
commandPollQuery | CommandPollQuery |
deviceCommandAPI.unsubscribe(subscriptionId) ⇒ Promise
Param | Type |
---|---|
subscriptionId | Number |
DeviceNotificationAPI
Returns information about the current notification
- DeviceNotificationAPI
- .get(deviceId, notificationId) ⇒ Promise
- .list(notificationListQuery) ⇒ Promise
- .insert(deviceId, notification) ⇒ Promise
- .poll(notificationPollQuery) ⇒ *
- .pollMany(notificationPollManyQuery) ⇒ *
- .subscribe(notificationPollQuery) ⇒ Promise
- .unsubscribe(subscriptionId) ⇒ Promise
deviceNotificationAPI.get(deviceId, notificationId) ⇒ Promise
Creates DeviceNotificationAPI
Returns: Promise - selected notification
Param | Type | Description |
---|---|---|
deviceId | number | Device ID |
notificationId | number | Notification ID |
deviceNotificationAPI.list(notificationListQuery) ⇒ Promise
Return a list of notifications
Returns: Promise - list of notifications
Param | Type |
---|---|
notificationListQuery | NotificationListQuery |
deviceNotificationAPI.insert(deviceId, notification) ⇒ Promise
Registers a notification
Returns: Promise - count of notifications
Param | Type |
---|---|
deviceId | Number |
notification | Notification |
deviceNotificationAPI.poll(notificationPollQuery) ⇒ *
Param | Type |
---|---|
notificationPollQuery | NotificationPollQuery |
deviceNotificationAPI.pollMany(notificationPollManyQuery) ⇒ *
Param | Type |
---|---|
notificationPollManyQuery | NotificationPollManyQuery |
deviceNotificationAPI.subscribe(notificationPollQuery) ⇒ Promise
Param | Type |
---|---|
notificationPollQuery | NotificationPollQuery |
deviceNotificationAPI.unsubscribe(subscriptionId) ⇒ Promise
Param | Type |
---|---|
subscriptionId | Number |
DeviceTypeAPI
Returns information about the current deviceType
- DeviceTypeAPI
- .get(deviceTypeId) ⇒ Promise
- .list(deviceTypeListQuery) ⇒ Promise
- .count(deviceTypeCountQuery) ⇒ Promise
- .insert(deviceType) ⇒ Promise
- .update(deviceType) ⇒ Promise
- .delete(deviceTypeDeleteQuery) ⇒ Promise
deviceTypeAPI.get(deviceTypeId) ⇒ Promise
Creates DeviceTypeAPI
Returns: Promise - selected deviceType
Param | Type |
---|---|
deviceTypeId | number |
deviceTypeAPI.list(deviceTypeListQuery) ⇒ Promise
Return a list of deviceTypes
Returns: Promise - list of deviceTypes
Param | Type |
---|---|
deviceTypeListQuery | DeviceTypeListQuery |
deviceTypeAPI.count(deviceTypeCountQuery) ⇒ Promise
Returns count of deviceTypes
Returns: Promise - count of deviceTypes
Param | Type |
---|---|
deviceTypeCountQuery | DeviceTypeCountQuery |
deviceTypeAPI.insert(deviceType) ⇒ Promise
Registers a deviceType
Returns: Promise - count of deviceTypes
Param | Type | Description |
---|---|---|
deviceType | DeviceType | data |
deviceTypeAPI.update(deviceType) ⇒ Promise
Updates a deviceType
Returns: Promise - count of deviceTypes
Param | Type | Description |
---|---|---|
deviceType | DeviceType | data |
deviceTypeAPI.delete(deviceTypeDeleteQuery) ⇒ Promise
Deletes an existing deviceType
Param | Type |
---|---|
deviceTypeDeleteQuery | deviceTypeDeleteQuery |
NetworkAPI
Returns information about the current network
- NetworkAPI
- .get(networkId) ⇒ Promise
- .list(networkListQuery) ⇒ Promise
- .count(networkCountQuery) ⇒ Promise
- .insert(network) ⇒ Promise
- .update(network) ⇒ Promise
- .delete(networkDeleteQuery) ⇒ Promise
networkAPI.get(networkId) ⇒ Promise
Returns a network
Returns: Promise - selected network
Param | Type |
---|---|
networkId | number |
networkAPI.list(networkListQuery) ⇒ Promise
Return a list of networks
Returns: Promise - list of networks
Param | Type |
---|---|
networkListQuery | NetworkListQuery |
networkAPI.count(networkCountQuery) ⇒ Promise
Returns count of networks
Returns: Promise - count of networks
Param | Type |
---|---|
networkCountQuery | NetworkCountQuery |
networkAPI.insert(network) ⇒ Promise
Registers a network
Returns: Promise - Network
Param | Type | Description |
---|---|---|
network | Network | data |
networkAPI.update(network) ⇒ Promise
Updates a network
Returns: Promise - Network
Param | Type | Description |
---|---|---|
network | Network | data |
networkAPI.delete(networkDeleteQuery) ⇒ Promise
Deletes an existing network
Returns: Promise - Network
Param | Type |
---|---|
networkDeleteQuery | networkDeleteQuery |
PluginAPI
Returns information about the current plugin
- PluginAPI
- .list(pluginListQuery) ⇒ Promise
- .count(pluginCountQuery) ⇒ Promise
- .register(plugin, pluginRegisterQuery) ⇒ Promise
- .update(pluginUpdateQuery) ⇒ Promise
- .delete(topicName) ⇒ Promise
pluginAPI.list(pluginListQuery) ⇒ Promise
Return a list of plugins
Returns: Promise - list of plugins
Param | Type |
---|---|
pluginListQuery | PluginListQuery |
pluginAPI.count(pluginCountQuery) ⇒ Promise
Returns count of plugins
Returns: Promise - count of plugins
Param | Type |
---|---|
pluginCountQuery | PluginCountQuery |
pluginAPI.register(plugin, pluginRegisterQuery) ⇒ Promise
Registers a plugin
Returns: Promise - Plugin
Param | Type |
---|---|
plugin | Plugin |
pluginRegisterQuery | PluginRegisterQuery |
pluginAPI.update(pluginUpdateQuery) ⇒ Promise
Updates a plugin
Returns: Promise - Plugin
Param | Type |
---|---|
pluginUpdateQuery | PluginUpdateQuery |
pluginAPI.delete(topicName) ⇒ Promise
Deletes an existing plugin
Returns: Promise - Plugin
Param | Type |
---|---|
topicName | string |
InfoAPI
Get server info
- InfoAPI
- .getServerInfo() ⇒ Promise
- .getCacheInfo() ⇒ Promise
- .getClusterInfo() ⇒ Promise
infoAPI.getServerInfo() ⇒ Promise
Get server info
infoAPI.getCacheInfo() ⇒ Promise
Get cache info
infoAPI.getClusterInfo() ⇒ Promise
Get cluster info
TokenAPI
Authenticate using login and password
tokenAPI.login(login, password)
Creates TokenAPI
Param | Type |
---|---|
login | string |
password | string |
tokenAPI.authPlugin(token)
Create user token
Param | Type | Description |
---|---|---|
token | string | Plugin token |
tokenAPI.createUserToken(userToken)
Create user token
Param | Type |
---|---|
userToken | UserToken |
tokenAPI.createPluginToken(pluginToken)
Create plugin token
Param | Type |
---|---|
pluginToken | PluginToken |
tokenAPI.refresh(refreshToken)
Refresh token
Param | Type |
---|---|
refreshToken | string |
UserAPI
Return a list of users
- UserAPI
- .list(userListQuery) ⇒ Promise
- .count(userCountQuery) ⇒ Promise
- .get(userId) ⇒ Promise
- .insert(user) ⇒ Promise
- .update(user) ⇒ Promise
- .delete(userId) ⇒ Promise
- .getCurrent() ⇒ Promise
- .updateCurrent(user) ⇒ Promise
- .getDeviceTypes(userId) ⇒ Promise
- .unassignAllDeviceTypes(userId) ⇒ Promise
- .assignAllDeviceTypes(userId) ⇒ Promise
- .unassignDeviceType(userId, deviceTypeId) ⇒ Promise
- .getDeviceType(userId, deviceTypeId) ⇒ Promise
- .assignDeviceType(userId, deviceTypeId) ⇒ Promise
- .getNetwork(userId, networkId) ⇒ Promise
- .assignNetwork(userId, networkId) ⇒ Promise
- .unassignNetwork(userId, networkId) ⇒ Promise
userAPI.list(userListQuery) ⇒ Promise
Creates UserAPI
Returns: Promise - list of users
Param | Type |
---|---|
userListQuery | UserListQuery |
userAPI.count(userCountQuery) ⇒ Promise
Returns count of users
Returns: Promise - count of users
Param | Type |
---|---|
userCountQuery | UserCountQuery |
userAPI.get(userId) ⇒ Promise
Returns information about the current user
Returns: Promise - selected user
Param | Type |
---|---|
userId | number |
userAPI.insert(user) ⇒ Promise
Registers a user
Returns: Promise - count of users
Param | Type | Description |
---|---|---|
user | User | data |
userAPI.update(user) ⇒ Promise
Updates a user (only for administrators)
Returns: Promise - count of users
Param | Type | Description |
---|---|---|
user | User | data |
userAPI.delete(userId) ⇒ Promise
Deletes an existing user
Param | Type |
---|---|
userId | number |
userAPI.getCurrent() ⇒ Promise
Returns information about the current user
Returns: Promise - selected user
userAPI.updateCurrent(user) ⇒ Promise
Updates a user (only for administrators)
Returns: Promise - count of users
Param | Type | Description |
---|---|---|
user | User | data |
userAPI.getDeviceTypes(userId) ⇒ Promise
Param |
---|
userId |
userAPI.unassignAllDeviceTypes(userId) ⇒ Promise
Param |
---|
userId |
userAPI.assignAllDeviceTypes(userId) ⇒ Promise
Param |
---|
userId |
userAPI.unassignDeviceType(userId, deviceTypeId) ⇒ Promise
Param |
---|
userId |
deviceTypeId |
userAPI.getDeviceType(userId, deviceTypeId) ⇒ Promise
Param |
---|
userId |
deviceTypeId |
userAPI.assignDeviceType(userId, deviceTypeId) ⇒ Promise
Param |
---|
userId |
deviceTypeId |
userAPI.getNetwork(userId, networkId) ⇒ Promise
Gets information about user/network association
Param | Type | Description |
---|---|---|
userId | number | User ID |
networkId | number | Network ID |
userAPI.assignNetwork(userId, networkId) ⇒ Promise
Associates network with the user
Param | Type | Description |
---|---|---|
userId | number | User ID |
networkId | number | Network ID |
userAPI.unassignNetwork(userId, networkId) ⇒ Promise
Removes association between network and user
Param | Type | Description |
---|---|---|
userId | number | User ID |
networkId | number | Network ID |
Models
Configuration
Configuration model
new Configuration(options)
Creates new Configuration model
Param | Type | Description |
---|---|---|
options | Object | model options object |
options.name | string | Configuration parameter name. |
options.value | string | Configuration parameter value. |
options.entityVersion | number | Specifies the version field or property of an entity class. |
configuration.toObject() ⇒ Object
Returns instance as a plain JS object
Device
Device model
- Device
- new Device(options)
- .toObject() ⇒ Object
new Device(options)
Creates new Device model
Param | Type | Description |
---|---|---|
options | object | model options object |
options.id | string | Device unique identifier |
options.name | string | Device display name |
options.data | object | Device data, a JSON object with an arbitrary structure |
options.networkId | number | Associated network id |
options.deviceTypeId | number | Associated deviceType id |
options.blocked | boolean | Indicates whether device is blocked |
device.toObject() ⇒ Object
Returns instance as a plain JS object
DeviceCommand
DeviceCommand model
new DeviceCommand(options)
Creates new DeviceCommand model
Param | Type | Description |
---|---|---|
options | object | model options object |
options.id | number | Command identifier |
options.command | string | Command name |
options.timestamp | string | Command UTC datetime (yyyy-MM-dd'T'HH:mm:ss.SSS ISO 8601) |
options.lastUpdated | string | Last command update UTC datetime (yyyy-MM-dd'T'HH:mm:ss.SSS ISO 8601) |
options.userId | number | Associated user identifier |
options.deviceId | string | Device unique identifier |
options.networkId | number | Network unique identifier |
options.deviceTypeId | number | DeviceType unique identifier |
options.parameters | object | Command parameters, a JSON object with an arbitrary structure |
options.lifetime | number | Command lifetime, a number of seconds until this command expires |
options.status | string | Command status, as reported by device or related infrastructure |
options.result | object | Command execution result, an optional value that could be provided by device |
deviceCommand.toObject() ⇒ Object
Returns instance as a plain JS object
DeviceNotification
DeviceNotification model
new DeviceNotification(options)
Creates new DeviceNotification model
Param | Type | Description |
---|---|---|
options | object | model options object |
options.id | number | Notification identifier |
options.deviceId | string | Device unique identifier |
options.networkId | number | Network unique identifier |
options.deviceTypeId | number | Device type unique identifier |
options.notification | string | Notification name |
options.timestamp | string | Notification UTC datetime (yyyy-MM-dd'T'HH:mm:ss.SSS ISO 8601) |
options.parameters | object | Notification parameters, a JSON object with an arbitrary structure |
deviceNotification.toObject() ⇒ Object
Returns instance as a plain JS object
DeviceType
DeviceType model
new DeviceType(options)
Creates new DeviceType model
Param | Type | Description |
---|---|---|
options | object | model options object |
options.id | number | Device type identifier |
options.name | string | Device type name |
options.description | string | Device type description |
deviceType.toObject() ⇒ Object
Returns instance as a plain JS object
Network
Network model
new Network(options)
Creates new Network model
Param | Type | Description |
---|---|---|
options | object | model options object |
options.id | number | Network identifier |
options.name | string | Network name |
options.description | string | Network description |
network.toObject() ⇒ Object
Returns instance as a plain JS object
Plugin
Plugin model
- Plugin
- new Plugin(options)
- .toObject() ⇒ Object
new Plugin(options)
Creates new Plugin model
Param | Type | Description |
---|---|---|
options | object | model options object |
options.id | id | Plgin unique idnetifier |
options.name | string | Plugin name |
options.description | string | Plugin description |
options.topicName | string | Plugin topic name |
options.filter | string | Plugin filter |
options.status | string | Plugin status |
options.subscriptionId | string | Plugin subscribtion id |
options.userId | number | Plugin user id |
options.parameters | object | Json object with parameters |
plugin.toObject() ⇒ Object
Returns instance as a plain JS object
PluginToken
PluginToken model
new PluginToken(options)
Creates new PluginToken model
Param | Type | Description |
---|---|---|
options | object | model options object |
options.actions | Array | Plugin Token actions |
options.expiration | string | Plugin expiration |
options.type | number | Plugin type |
options.topicName | string | Plugin topic name |
pluginToken.toObject() ⇒ Object
Returns instance as a plain JS object
User
User model
- User
- new User(options)
- .toObject() ⇒ Object
new User(options)
Creates new User model
Param | Type | Description |
---|---|---|
options | object | model options object |
options.id | numebr | User identifier |
options.login | string | User login using during authentication |
options.role | number | User role. Available values: 0: Administrator role, 1: Client role. |
options.status | number | User status. Available values: 0: The user is active, 1: The user has been locked out due to invalid login attempts, 2: The user has been disabled |
options.lastLogin | string | User last login timestamp (UTC) |
options.data | object | User data, a JSON object with an arbitrary structure |
options.password | string | User Password |
options.introReviewed | boolean | Indicates if user reviewed an intro |
options.allDeviceTypesAvailable | boolean | Is all device types awailable |
user.toObject() ⇒ Object
Returns instance as a plain JS object
UserToken
UserToken model
new UserToken(options)
Creates new UserToken model
Param | Type | Description |
---|---|---|
options | object | model options object |
options.userId | number | User id |
options.actions | Array | User Actions |
options.networkIds | Array | Network id's |
options.deviceTypeIds | Array | Devicetype id's |
options.expiration | string | Token expiration datetme |
userToken.toObject() ⇒ Object
Returns instance as a plain JS object
Query models
CommandListQuery
CommandListQuery class
new CommandListQuery(options)
Creates new CommandListQuery model
Param | Type | Description |
---|---|---|
options | object | model options object |
options.deviceId | string | Device ID |
options.start | string | Start timestamp |
options.end | string | End timestamp |
options.command | string | Command name |
options.status | string | Command status |
options.sortField | string | Sort field |
options.sortOrder | string | Sort order |
options.take | number | Limit param |
options.skip | number | Skip param |
commandListQuery.toObject() ⇒ Object
Returns instance as a plain JS object
CommandPollManyQuery
CommandPollManyQuery class
new CommandPollManyQuery(options)
Creates new CommandPollManyQuery model
Param | Type | Description |
---|---|---|
options | object | model options object |
options.deviceIds | string | List of device IDs |
options.networkIds | string | List of network IDs |
options.deviceTypeIds | string | List of devicetype IDs |
options.names | string | Command names |
options.timestamp | string | Timestamp to start from |
options.waitTimeout | number | Wait timeout in seconds |
options.limit | number | Limit number of commands |
commandPollManyQuery.toObject() ⇒ Object
Returns instance as a plain JS object
CommandPollQuery
CommandPollQuery class
new CommandPollQuery(options)
Creates new CommandPollQuery model
Param | Type | Description |
---|---|---|
options | object | model options object |
options.deviceId | string | Device ID |
options.names | string | Command names |
options.timestamp | number | Timestamp to start from |
options.returnUpdatedCommands | boolean | Checks if updated commands should be returned |
options.waitTimeout | number | Wait timeout in seconds |
options.limit | number | Limit number of commands |
commandPollQuery.toObject() ⇒ Object
Returns instance as a plain JS object
CommandWaitQuery
CommandWaitQuery class
new CommandWaitQuery(options)
Creates new CommandWaitQuery model
Param | Type | Description |
---|---|---|
options | Object | model options object |
options.waitTimeout | Number | wait timeout (sec) |
commandWaitQuery.toObject() ⇒ Object
Returns instance as a plain JS object
DeviceCountQuery
DeviceCountQuery class
new DeviceCountQuery(options)
Creates new DeviceCountQuery model
Param | Type | Description |
---|---|---|
options | object | model options object |
options.name | string | Filter by device name |
options.namePattern | string | Filter by device name pattern. In pattern wildcards '%' and '_' can be used |
options.networkId | number | Filter by associated network identifier |
options.networkName | string | Filter by associated network name |
deviceCountQuery.toObject() ⇒ Object
Returns instance as a plain JS object
DeviceListQuery
DeviceListQuery class
<a name="new_DeviceListQ