Toggle navigation
Wialon Playground
Add library
jQuery latest
Bootstrap 3.3.1
Wialon Javascript SDK
Run
Get code
Fork
Save
Examples
Login
Get units
Change unit icon
Get messages
Get sensors
Edit sensors
Commands
Monitoring notification
Track layer
Get resources
Resources and accounts
Account parameters
Do payment
Management Driver
Get POIs
Create POI
Create notification
Get geofences
Geofence parameters
Create geofence
Export geofences
Gurtam map
Units on map
Unit trace
Create report template
Execute report
Execute custom report
Remaining SMS
Create driver
Bind driver to unit
Export resource props
Import resource props
Unit edit fields
Import fillings
Fuel by mail
Token login for site
Advanced authorization form
Token usage in app
Get location's geofences
Account hierarchy
Nearest units
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title>Wialon Playground - Get units</title> <script type="text/javascript" src="//code.jquery.com/jquery-latest.min.js"></script> <script type="text/javascript" src="//hst-api.wialon.com/wsdk/script/wialon.js"></script> </head> <body> <pre id="log"></pre> </body> </html>
HTML
#log { border: 1px solid #c6c6c6; } .icon {float:left; margin:10px;}
CSS
// Print message to log function msg(text) { $("#log").prepend(text + "<br/>"); } function init() { // Execute after login succeed var s = wialon.core.Session.getInstance(); // get instance of current Session var r = wialon.core.Remote.getInstance(); var UNIT_ID = 734477; r.remoteCall('messages/load_last', { itemId: UNIT_ID, lastTime: s.getServerTime(), lastCount: 1, flags: 0, flagsMask: 0, loadCount: 1 }, function(error) { if (error) { msg(wialon.core.Errors.getErrorText(error)); return; } r.remoteCall('unit/calc_sensors', { source: '', indexFrom: 0, indexTo: 1, unitId: UNIT_ID, sensorId: 0 }, function(error, data) { if (error) { msg(wialon.core.Errors.getErrorText(error)); return; } msg('sensor values: ' + JSON.stringify(data, null, 1)); }); }); } // execute when DOM ready $(document).ready(function () { wialon.core.Session.getInstance().initSession("https://hst-api.wialon.com"); // init session // For more info about how to generate token check // http://sdk.wialon.com/playground/demo/app_auth_token wialon.core.Session.getInstance().loginToken("5dce19710a5e26ab8b7b8986cb3c49e58C291791B7F0A7AEB8AFBFCEED7DC03BC48FF5F8", "", // try to login function (code) { // login callback // if error code - print error message if (code){ msg(wialon.core.Errors.getErrorText(code)); return; } msg("Logged successfully"); init(); // when login suceed then run init() function }); });
JS
Result
Source code of example
Close ✕
×
Source code