1

Import latitude and longitude using RemoteAPI

Тема: Import latitude and longitude using RemoteAPI

Hi,

I need to Import  latitude and longitude using RemoteAPI. Please suggest

2

Import latitude and longitude using RemoteAPI

Re: Import latitude and longitude using RemoteAPI

If you need to set unit position, there is only two ways to achieve this: send message via hardware protocol of your unit or to use exchange/import_messages.

To see format of import_messages input data, you can export messages from some unit to WLN and open it in text editor.

3

Import latitude and longitude using RemoteAPI

Re: Import latitude and longitude using RemoteAPI

Thank you for Reply.

I have tested with a UNIT getting error messages.

https://forum.gurtam.com/viewtopic.php?id=12423

Please check my code and let me know if any working example.

4

Import latitude and longitude using RemoteAPI

(28/08/2018 11:34:17 отредактировано rual)

Re: Import latitude and longitude using RemoteAPI

Working example for NodeJS 8:

const https = require('https');

const SID = process.env.SID,
      ITEM_ID = parseInt(process.env.ITEM_ID);

let multipartBoundary = '-----WialonFormBoundary', // must do not encounter in payload
    multipartBoundarySplitter = '--' + multipartBoundary;

let eventHash = 'importMessage' + Date.now();

let content = [{
    name: 'params',
    content: JSON.stringify({ itemId: ITEM_ID, eventHash: eventHash })
}, {
    name: 'file',
    filename: 'file.wln',
    contentType: 'text/plain',
    content: 'REG;2000000000;27.456872;53.905826;60;180;ALT:0.0;SATS:255;;;;'
}].map(function(obj) {
    let lines = [multipartBoundarySplitter];

    let contentDispositionParams = [];

    contentDispositionParams.push('name="' + obj.name + '"');
    if (obj.filename) contentDispositionParams.push('filename="' + obj.filename + '"');

    lines.push('Content-Disposition: form-data; ' + contentDispositionParams.join('; '));

    if (obj.contentType) lines.push('Content-Type: ' + obj.contentType);

    lines.push(''); // newline

    lines.push(obj.content);

    return lines.join('\r\n');
});

content.push(multipartBoundarySplitter);

content = content.join('\r\n');

let contentBuffer = Buffer.from(content, 'utf-8');

let contentLength = contentBuffer.length;

let req = https.request({
    method: 'POST',
    host: 'hst-api.wialon.com',
    path: '/wialon/ajax.html?svc=exchange/import_messages&sid=' + SID,
    headers: {
        'Content-Length': '' + contentLength,
        'Content-Type': 'multipart/form-data; boundary=' + multipartBoundary
    }
}, function(res) {
    res.on('data', function(data) {
        console.log(data.toString('utf-8'));
    });
});

req.write(contentBuffer);

There is lon, lat, speed (60 km/h), course (180°), ALT, SATS:

REG;2000000000;27.456872;53.905826;60;180;ALT:0.0;SATS:255;;;;

2000000000 is a time in seconds. You can specify time in past, or if it will be in future (as in an example), wialon will use current time.

So, you need to send POST request with headers:

Content-Length: (number of bytes of body)
Content-Type: multipart/form-data; boundary=-----WialonFormBoundary

(beware of starting --, in body you will need to prepend two dashes to specified boundary in header)

And following body:

-------WialonFormBoundary
Content-Disposition: form-data; name="params"

{"itemId":15904200,"eventHash":"importMessage1535444018829"}
-------WialonFormBoundary
Content-Disposition: form-data; name="file"; filename="file.wln"
Content-Type: text/plain

REG;2000000000;27.456872;53.905826;60;180;ALT:0.0;SATS:255;;;;
-------WialonFormBoundary

(newline delimiters are \r\n)

Also, you can use your language library to send multipart/form-data requests and maybe make it more clear.

But if you have unit, that must be moved only programmatically, it is better to implement Wialon IPS and send messages as hardware.