Differences

This shows you the differences between two versions of the page.

Link to this comparison view

en:local:remoteapi1504:codesamples:messages [13/03/2015 10:38]
en:local:remoteapi1504:codesamples:messages [13/03/2015 10:38] (current)
Line 1: Line 1:
 +{{indexmenu_n>​9}}
 +====== Messages ======
  
 +You can operate messages with the help of a special object -- the message loader. First, you load messages into the message loader using either of two commands -- [[../​apiref/​messages/​load_last|messages/​load_last]] or [[../​apiref/​messages/​load_interval|messages/​load_interval]]. Then you can work with them. However, if you need to load other messages, you must clear the loader first, using the command [[../​apiref/​messages/​unload|messages/​unload]].
 +
 +
 +//:!: Attention!//​ To launch this example at Wialon Kit, change **<​nowiki>​https://​hst-api.wialon.com</​nowiki>​** for **<​nowiki>​https://​kit-api.wialon.com</​nowiki>​** in all requests and use user name and password of your account to login to the system or name and password of demo user //**kitdemo kitdemo**//​.
 +
 +===== Loading messages =====
 +
 +Let's load data messages with position for the interval from 01.04.2013 to 20.04.2013 with the help of the request [[../​apiref/​messages/​load_interval|messages/​load_interval]] and get first 3 of them. To query only data messages with position use mask 0xFF01 (0xFF00 - determines message type, 0x0001 - determines availability of position info in data messages). Also it is necessary to use flag 0x0001, ​ which comes from sum of flags: 0x0000 - data messages, 0x0001 - messages with position.
 +<​code>​
 +https://​hst-api.wialon.com/​wialon/​ajax.html?​svc=messages/​load_interval&​
 + params={
 + "​itemId":​34868,​
 + "​timeFrom":​1364760000,​
 + "​timeTo":​1366487999,​
 + "​flags":​0x0001,​
 + "​flagsMask":​0xFF01,​
 + "​loadCount":​3
 + }&​sid=<​your_sid>​
 +</​code>​
 +
 +Response:
 +<code javascript>​
 +{
 +    "​count":​ 9172,
 +    "​messages":​ [{
 +        "​t":​ 1364760081,
 +        "​f":​ 3,
 +        "​tp":​ "​ud",​
 +        "​pos":​ {
 +            "​y":​ 53.8396544,
 +            "​x":​ 27.5608672,
 +            "​z":​ 213,
 +            "​s":​ 0,
 +            "​c":​ 51,
 +            "​sc":​ 9
 +        },
 +        "​i":​ 0,
 +        "​p":​ {
 +            "​param22":​ 3,
 +            "​adc1":​ 12.606,
 +            "​pwr_ext":​ 12.598,
 +            "​param199":​ 0,
 +            "​param241":​ 25701,
 +            "​battery_charge":​ 0
 +        }
 +    }, {
 +        "​t":​ 1364760381,
 +        "​f":​ 3,
 +        "​tp":​ "​ud",​
 +        "​pos":​ {
 +            "​y":​ 53.8396544,
 +            "​x":​ 27.5609312,
 +            "​z":​ 213,
 +            "​s":​ 0,
 +            "​c":​ 73,
 +            "​sc":​ 9
 +        },
 +        "​i":​ 0,
 +        "​p":​ {
 +            "​param22":​ 3,
 +            "​adc1":​ 12.545,
 +            "​pwr_ext":​ 12.547,
 +            "​param199":​ 0,
 +            "​param241":​ 25701,
 +            "​battery_charge":​ 0
 +        }
 +    }, {
 +        "​t":​ 1364760682,
 +        "​f":​ 3,
 +        "​tp":​ "​ud",​
 +        "​pos":​ {
 +            "​y":​ 53.8396736,
 +            "​x":​ 27.5609664,
 +            "​z":​ 215,
 +            "​s":​ 0,
 +            "​c":​ 64,
 +            "​sc":​ 9
 +        },
 +        "​i":​ 0,
 +        "​p":​ {
 +            "​param22":​ 3,
 +            "​adc1":​ 12.6,
 +            "​pwr_ext":​ 12.569,
 +            "​param199":​ 0,
 +            "​param241":​ 25701,
 +            "​battery_charge":​ 0
 +        }
 +    }]
 +}
 +</​code>​
 +
 +After loading messages, you can choose any number of them for further processing. For example, let's choose the ninth message from the loader. For this, use the request [[../​apiref/​messages/​get_messages|messages/​get_messages]]:​
 +
 +<​code>​
 +https://​hst-api.wialon.com/​wialon/​ajax.html?​svc=messages/​get_messages&​
 + params={
 + "​indexFrom":​8,​
 + "​indexTo":​9
 + }&​sid=<​your_sid>​
 +</​code>​
 +
 +Response:
 +<code javascript>​
 +[{
 +    "​t":​ 1364762485,
 +    "​f":​ 3,
 +    "​tp":​ "​ud",​
 +    "​pos":​ {
 +        "​y":​ 53.8396992,
 +        "​x":​ 27.5609216,
 +        "​z":​ 223,
 +        "​s":​ 0,
 +        "​c":​ 45,
 +        "​sc":​ 7
 +    },
 +    "​i":​ 0,
 +    "​p":​ {
 +        "​param22":​ 3,
 +        "​adc1":​ 12.584,
 +        "​pwr_ext":​ 12.569,
 +        "​param199":​ 0,
 +        "​param241":​ 25701,
 +        "​battery_charge":​ 0
 +    }
 +}]
 +</​code>​
 +
 +===== Deleting messages =====
 +
 +Now we will try to delete the first message using the request [[../​apiref/​messages/​delete_message|messages/​delete_message]]:​
 +<​code>​
 +https://​hst-api.wialon.com/​wialon/​ajax.html?​svc=messages/​delete_message&​
 + params={
 + "​msgIndex":​0
 + }&​sid=<​your_sid>​
 +</​code>​
 +
 +Response:
 +<code javascript>​
 +{
 +    "​error":​ 7
 +}
 +</​code>​
 +
 +User "​wialon_test"​ has not enough rights for this action. However, if you check this example on your server you will get the following response:
 +<code javascript>​
 +{}
 +</​code>​
 +
 +===== Clear message loader =====
 +
 +If you want to load messages for other interval or unit, [[../​apiref/​messages/​unload|clear]] the message loader first:
 +<​code>​
 +https://​hst-api.wialon.com/​wialon/​ajax.html?​svc=messages/​unload&​params={}&​sid=<​your_sid>​
 +</​code>​
 +
 +Response:
 +<code javascript>​
 +{}
 +</​code>​
 +
 +If you try to query messages from empty loader, the following error code will be returned:
 +<​code>​
 +https://​hst-api.wialon.com/​wialon/​ajax.html?​svc=messages/​get_messages&​
 + params={
 + "​indexFrom":​0,​
 + "​indexTo":​1
 + }&​sid=<​your_sid>​
 +</​code>​
 +
 +Response:
 +<code javascript>​
 +{"​error":​4}
 +</​code>​
 +
 +===== Rendering track layer =====
 +
 +If loaded messages contain geographic coordinates,​ a track can be built on their basis. To do this, you should load messages into a special graphic layer. Track layer can be used in the same way as the message loader. The only difference between them is graphics.
 +
 +Let's create a track layer for our messages between 01.01.2013 and 20.01.2013. We can do it using the request [[../​apiref/​render/​create_messages_layer|render/​create_messages_layer]]:​
 +
 +<​code>​
 +https://​hst-api.wialon.com/​wialon/​ajax.html?​svc=render/​create_messages_layer&​
 + params={
 + "​layerName":"​messages",​
 + "​itemId":​34868,​
 + "​timeFrom":​1357938000,​
 + "​timeTo":​1358715599,​
 + "​tripDetector":​1,​
 + "​trackColor":​cc713cff,​
 + "​trackWidth":​5,​
 + "​arrows":​1,​
 + "​points":​0,​
 + "​pointColor":​0,​
 + "​annotations":​0
 + }&​sid=<​your_sid>​
 +</​code>​
 +
 +Response:
 +<code javascript>​
 +{
 +    "​name":​ "​messages",​
 +    "​bounds":​ [53.8326976,​ 27.2796096, 53.9644416, 27.6123168],​
 +    "​units":​ [{
 +        "​id":​ 34868,
 +        "​msgs":​ {
 +            "​count":​ 5951,
 +            "​first":​ {
 +                "​time":​ 1356984476,
 +                "​lat":​ 53.9077377319,​
 +                "​lon":​ 27.5011463165
 +            },
 +            "​last":​ {
 +                "​time":​ 1358538957,
 +                "​lat":​ 53.8397254944,​
 +                "​lon":​ 27.5608959198
 +            }
 +        },
 +        "​mileage":​ 699169.703025,​
 +        "​max_speed":​ 118
 +    }]
 +}
 +</​code>​
 +
 +Besides, you can get the tiles of a track layer using the request [[../​apiref/​requests/​avl_render|avl_render]]:​
 +<​code>​
 +https://​hst-api.wialon.com/​avl_render/​590_329_7/<​your_sid>​.png
 +</​code>​
 +
 +Response:
 +
 +{{/​remote_ex/​messages.png?​nolink}}
Follow us on Facebook Gurtam Wialon Twitter Gurtam Wialon info@gurtam.com   |   Copyright © 2002-2024 Gurtam