Created
October 8, 2014 22:13
Wialon + Node.js - Simple sample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var request = require('request'); | |
var URL = 'https://hst-api.wialon.com/wialon/ajax.html?'; | |
var SID = null; | |
function searchItems () { | |
var params = { | |
spec: { | |
itemsType: 'avl_unit', | |
propName: 'sys_name', | |
propValueMask: '*', | |
sortType: 'sys_name' | |
}, | |
force: 1, | |
flags: 1, | |
from: 0, | |
to: 0 | |
}; | |
request.post({ | |
url: URL + 'svc=core/search_items', | |
json: true, | |
form: { | |
sid: SID, | |
params: JSON.stringify(params) | |
} | |
}, function (error, response, body) { | |
console.log('Search items'); | |
console.log(body); | |
logout(); | |
}); | |
} | |
function logout () { | |
request.get(URL + 'svc=core/logout¶ms={}', function (error, response, body) { | |
console.log('logout'); | |
}); | |
} | |
function login (user, password) { | |
var url = URL + 'svc=core/login¶ms={user:"' + user + '",password:"' + password + '"}'; | |
request.get({ | |
url: url, | |
json: true | |
}, function (error, response, body) { | |
console.log('login'); | |
SID = body.eid; | |
searchItems(); | |
}); | |
} | |
login("wialon_test", "test"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
$ npm install request
before run script