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 – messages/load_last or 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 messages/unload.

:!: Attention! To launch this example at Wialon Kit, change https://hst-api.wialon.com for https://kit-api.wialon.com 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 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.

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>

Response:

{
    "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
        }
    }]
}

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 messages/get_messages:

https://hst-api.wialon.com/wialon/ajax.html?svc=messages/get_messages&
	params={
		"indexFrom":8,
		"indexTo":9
	}&sid=<your_sid>

Response:

[{
    "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
    }
}]

Deleting messages

Now we will try to delete the first message using the request messages/delete_message:

https://hst-api.wialon.com/wialon/ajax.html?svc=messages/delete_message&
	params={
		"msgIndex":0
	}&sid=<your_sid>

Response:

{
    "error": 7
}

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:

{}

Clear message loader

If you want to load messages for other interval or unit, clear the message loader first:

https://hst-api.wialon.com/wialon/ajax.html?svc=messages/unload&params={}&sid=<your_sid>

Response:

{}

If you try to query messages from empty loader, the following error code will be returned:

https://hst-api.wialon.com/wialon/ajax.html?svc=messages/get_messages&
	params={
		"indexFrom":0,
		"indexTo":1
	}&sid=<your_sid>

Response:

{"error":4}

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 render/create_messages_layer:

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>

Response:

{
    "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
    }]
}

Besides, you can get the tiles of a track layer using the request avl_render:

https://hst-api.wialon.com/avl_render/590_329_7/<your_sid>.png

Response:

Follow us on Facebook Gurtam Wialon Twitter Gurtam Wialon info@gurtam.com   |   Copyright © 2002-2024 Gurtam