messages_requests_examples
You can manage messages with the help of the message loader. First, you should load messages into the message loader using either of the two commands: messages/load_last or messages/load_interval. Then you can work with the messages. However, if you want to load other messages, you should clear the loader first, using the command messages/unload.
Loading messages
Let’s load data messages with location for the interval from 01.04.2013 to 20.04.2013 using the request messages/load_interval and get the first three of them. To request only data messages with location, use the mask 0xFF01 (65281). The mask 0xFF00 (65280) determines the message type, 0x0001 (1) detects the availability of location information in messages. Also, it is necessary to use the flag 0x0001 (1), which comes from the sum of the flag 0x0000 (0) for data messages and the flag 0x0001 (1) for messages with location.
https://hst-api.wialon.com/wialon/ajax.html?svc=messages/load_interval&
params={
"itemId":34868,
"timeFrom":1364760000,
"timeTo":1366487999,
"flags":1,
"flagsMask":65281,
"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 the messages, you can choose any number of them for further processing. For example, let’s choose the ninth message from the loader. To do 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 let’s 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:
{ }
Clearing message loader
If you want to load messages for another interval or unit, clear the message loader first:
https://hst-api.wialon.com/wialon/ajax.html?svc=messages/unload¶ms={}&sid=<your_sid>
Response:
{ }