1
<!DOCTYPE html>
2
<html>
3
<head>
4
    <meta charset="utf-8" />
5
    <title>Wialon Playground - Get sensors</title>
6
    <script type="text/javascript" src="//code.jquery.com/jquery-latest.min.js"></script>
7
    <script type="text/javascript" src="//hst-api.wialon.com/wsdk/script/wialon.js"></script>
8
</head>
9
<body>
10
11
Select unit: <select id="units"></select>
12
available sensors <select id="sensors"></select>
13
<div id="log"></div>
14
15
</body>
16
</html>
HTML
2
 
1
#log { border: 1px solid #c6c6c6; }
2
.icon {float:left; margin:10px;}
CSS
64
 
1
// Print message to log
2
function msg(text) { $("#log").prepend(text + "<br/>"); }
3
4
function init() { // Execute after login succeed
5
    var sess = wialon.core.Session.getInstance(); // get instance of current Session
6
    // flags to specify what kind of data should be returned
7
    var flags = wialon.item.Item.dataFlag.base |
8
                wialon.item.Unit.dataFlag.sensors | 
9
                wialon.item.Unit.dataFlag.lastMessage;
10
    sess.loadLibrary("unitSensors"); // load Sensor Library
11
    sess.updateDataFlags( // load items to current session
12
        [{type: "type", data: "avl_unit", flags: flags, mode: 0}], // Items specification
13
        function (code) { // updateDataFlags callback
14
            if (code) { msg(wialon.core.Errors.getErrorText(code)); return; } // exit if error code  
15
            
16
            var units = sess.getItems("avl_unit"); // get loaded 'avl_unit's items
17
            if (!units || !units.length){ msg("No units found"); return; } // check if units found
JS
Result
Source code of example Close ✕
1
 
1
/*source*/