devicehive / devicehive-javascript Goto Github PK
View Code? Open in Web Editor NEWDeviceHive JavaScript Library. Works with NodeJs and browsers.
License: Apache License 2.0
DeviceHive JavaScript Library. Works with NodeJs and browsers.
License: Apache License 2.0
Hello ,
I have a problem with the determining of api type.
The version of NodeJS that I use is v7.10.1 .
Currently I'am doing this:
const refreshToken = "xxxx.xxx.xxxx"
const serverURL = "https://playground.devicehive.com/api/rest"
const devicehive = require('devicehive');
async function Authenticate(token, url){
return await new devicehive({
refreshToken: refreshToken,
serverURL: serverURL
})
}
async function main(){
try{
let conn = await Authenticate(refreshToken,serverURL)
let info = await conn.getInfo();
console.log(info)
let networks = await conn.listNetworks({})
console.log(networks)
let saveDevice = await conn.putDevice('44m6',{})
console.log(saveDevice)
let device = await conn.getDevice('44m6')
console.log(device)
await conn.subscribeCommands('44m6',function(cmd){ // problem here
console.log(cmd)
},{names:'hi'})
}catch(err){
console.log(err)
}
}
main()
The log result that I get is this:
api.js init function api type = ht
api.js init function https://playground.devicehive.com/api/rest
{ apiVersion: '3.3.2',
serverTimestamp: '2017-09-30T15:23:33.995',
webSocketServerUrl: 'ws://playground.devicehive.com/api/websocket' }
[ Network {
id: 35,
name: 'Network LJXKWO for ([email protected])',
description: 'Playground Network' } ]
{}
Device {
id: '44m6',
name: '44m6',
data: null,
networkId: 35,
isBlocked: false,
_commandsSubscribers: {},
_notificationsSubscribers: {} }
api.js subscribeCommands function api type = undefined
TypeError: api.commandsSubscribe is not a function
at DeviceHive.subscribeCommands (/home/mike/Desktop/Devicehive_dev/node_modules/devicehive/lib/DeviceHive.js:344:18)
at main (/home/mike/Desktop/Devicehive_dev/connector.js:25:16)
at process._tickCallback (internal/process/next_tick.js:109:7)
I tried to debug this problem and realized that,
when DeviceHive class constructor is called it runs init function from /src/api.js file, and the
init function returns the API determined by the serverURL which in my case should be 'ht'.
Little bit later when i try to call subscribeCommands the error appeared. I printed the value of 'type' from the subscribeCommands function
// lib/DeviceHive.js
subscribeCommands(deviceIds, subscriber, commandFilter){
commandFilter.deviceIds = deviceIds;
console.log('api.js subscribeCommands function api type = ' + type)
if (type === `ht`){
const filterKey = JSON.stringify(commandFilter);
this._commandsSubscribers[filterKey] = subscriber;
this._pollCommands(commandFilter);
return Promise.resolve();
} else {
return api.commandsSubscribe(commandFilter, subscriber, DeviceCommand);
}
}
So type turned out to be undefined and the code ends up in the else block and tries to call the function commandsSubscribe which does not exist in rest api.
When I force the value of 'type' to 'ht' in src/api.js everything works fine.
Can you please tell me if I am doing something wrong, or the problem is really there.
Thank you,
Mihail Lyaskov
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.