1

Error :4 on Import WLP with php wialon master

Topic: Error :4 on Import WLP with php wialon master

I started to developed my own app with PHP Wialon master, I’m trying to import a WLP to the platform but I’m getting Error:4 for every time I trying to execute.
I generate the WLP automatically and I get a file with all the configuration, I leave a part below (It’s well-formed because I prove to import directly to the platform and ain’t getting any problem).

Unfortunately, you are not allowed to view this text


However when I try to import through php code I getting error:4, I know that my code is wrong but maybe you can help to see how to do it. I leave it below.

I will really appreciate all your opinion and tips.
Thanks in advance


<?php
include('wialon.php');

$wialon= new Wialon();

date_default_timezone_set('America/Mexico_City');
$token="token number";
$result= $wialon->login($token);
$json=json_decode($result, true);

$hash="";
$hash.='Request Method: POST\n';
$hash.='Connection: keep-alive \n';
$hash.='Content-Length: 1901 \n';
$hash.='Cache-Control: no-cache\n';
$hash.='Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryhAXcAjtvh1D61XpC\n';
$hash.='Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\n';
$hash.='Accept-Charset: windows-1251,utf-8;q=0.7,*;q=0.3\n';
$hash.='Accept-Encoding: gzip,deflate,sdch\n';
$hash.='Accept-Language: ru,en-US;q=0.8,en;q=0.6\n';

$hash.='------WebKitFormBoundaryhAXcAjtvh1D61XpC\n';
$hash.='Content-Disposition: form-data; name="params"\n';
$hash.='{"eventHash":"jUploadForm1372772377019"}\n';
$hash.='------WebKitFormBoundaryhAXcAjtvh1D61XpC\n';
$hash.='Content-Disposition: form-data; name="eventHash"\n';
$hash.='jUploadForm1372772377019\n';
//Here I put directly the WLP formed
$hash.='------WebKitFormBoundaryhAXcAjtvh1D61XpC\n';
$hash.='Content-Disposition: form-data; name="import_file"; filename="file.zip"\n';
$hash.='Content-Type: application/x-zip-compressed\n';
$hash.='------WebKitFormBoundaryhAXcAjtvh1D61XpC--\n';

$params=array(
    "eventHash"=>$hash
);

$ejecucion=$wialon->svc_exchange_import_json(json_encode($params));
$ejex=json_decode($ejecucion,true);
echo $ejecucion;

?>
2

Error :4 on Import WLP with php wialon master

Re: Error :4 on Import WLP with php wialon master

Hi monitoreo2

Here's simple sample how to upload file to wialon.
Dont forget to change TOKEN and UNIT_ID to yours. Also create msgs.wln file
Hope this helps:)

<?
    $url = 'https://hst-api.wialon.com';
    $token = TOKEN;
    $unitId = UNIT_ID;
    $filename = 'msgs.wln';

    // Login request
    $params = array('token' => $token);
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url.'/wialon/ajax.html?svc=token/login');
    curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, 'params='.json_encode($params));
    $out = curl_exec($ch);
    curl_close($ch);
    $out = json_decode($out, true);

    // get sid from login response
    $sid = $out['eid'];

    // import_messages request (upload file)
    $params = array(
        'sid' => $sid,
        'itemId' => $unitId
    );
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url.'/wialon/ajax.html?svc=exchange/import_messages&sid='.$sid);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, array(
        'file' => '@'.realpath($filename),
        'params' => json_encode($params)
    ));
    $out = curl_exec($ch);
    curl_close($ch);

    echo $out;
?>
3

Error :4 on Import WLP with php wialon master

Re: Error :4 on Import WLP with php wialon master

Hi! Thanks for your help

I use your code and continued getting the error 4, I modify some lines and try of different ways but this error continued but with different reasons some are "WRONG_PARAMS" or "VALIDATION_PARAMS_ERROR: ItemId:long".

<?php 
    $url = 'https://hst-api.wialon.com';
    $token =TOKEN;
    $unitId = 16374707;
    $filename = 'filename.wln';

    // Login request
    $params = array('token' => $token);
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); //Added this line because I'm using windows operating system and without this doesn´t work
    curl_setopt($ch, CURLOPT_URL, $url.'/wialon/ajax.html?svc=token/login');
    curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, 'params='.json_encode($params));
    $out = curl_exec($ch);
    curl_close($ch);
    $result = json_decode($out, true);
    // get sid from login response
    $sid = $result['eid'];
   // import_messages request (upload file)

    $params = array(
     
        'itemId' => $unitId
    );

    $params2 = array(
        'file' => '@'.realpath($filename),
        'params' => json_encode($params)
    );
    $ch = curl_init();
  
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);                
    curl_setopt($ch, CURLOPT_URL, $url.'/wialon/ajax.html?svc=exchange/import_messages&sid='.$sid);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, 'params='.json_encode($params));
    $out = curl_exec($ch);
    curl_close($ch);



   /* $args = array(
        //'sid' => $sid,*/        

    /*$params = array(
            'svc' => "exchange/import_messages",
            'sid' => $sid,
            'params' =>array('itemId' => $unitId),
            'file' => '@'.$filename
        );
//$params['messages_filter_import_file'] = '@'.$filename;

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_URL, $url.'/wialon/ajax.html?'.json_encode($params));
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    /*curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($params));
    $out = curl_exec($ch);
    curl_close($ch);*/


    echo $out;
?>

And I got a question about it, This works with WLP files or only with WLN files? like the option https://sdk.wialon.com/wiki/en/kit/remo … mport_json

I will really appreciate if you continued helping me smile

4

Error :4 on Import WLP with php wialon master

Re: Error :4 on Import WLP with php wialon master

The code above shows how to upload file to Wialon using Remote API. Extension and svc doesn't matter.

Also note that exchange/import_json request doen't actually import anything. Just parse JSON and return parsed result back in *avl_evts*

Here's working sample with .wlp (replace TOKEN and place unit.wlp in folder)

<?
    $url = 'https://hst-api.wialon.com';
    $token = 'TOKEN';
    $filename = 'unit.wlp';

    // Login request
    $params = array('token' => $token);
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url.'/wialon/ajax.html?svc=token/login');
    curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, 'params='.json_encode($params));
    $out = curl_exec($ch);
    curl_close($ch);
    $out = json_decode($out, true);

    // get sid from login response
    $sid = $out['eid'];

    // import_messages request (upload file)
    $params = array(
        'sid' => $sid,
        'eventHash' => 'any_random_string_you_like'
    );
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url.'/wialon/ajax.html?svc=exchange/import_json&sid='.$sid);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, array(
        'file' => '@'.realpath($filename),
        'params' => json_encode($params)
    ));
    $out = curl_exec($ch);
    curl_close($ch);

    echo "exchange/import_json: $out<br/>";

    // wait while file parsing
    sleep(3);

    // get events
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url.'/avl_evts?sid='.$sid);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
    curl_setopt($ch, CURLOPT_POST, true);
    $out = curl_exec($ch);
    curl_close($ch);

    // In response you'll see event with hash 'any_random_string_you_like'
    // This is result of parsing uploaded file
    echo "avl_evts: $out<br/>";

?>
5

Error :4 on Import WLP with php wialon master

Re: Error :4 on Import WLP with php wialon master

I try with both (exchange/import_json,exchange/import_messages ) but the error continued, I modify some lines and try of  differents ways but always get error:4

I leave my code below.

<?php 
    $url = 'https://hst-api.wialon.com';
    $token =TOKEN;
    $unitId = 16374707;
    $filename = 'filename.wln';

    // Login request
    $params = array('token' => $token);
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); //Added this line because I'm using windows operating system and without this doesn´t work
    curl_setopt($ch, CURLOPT_URL, $url.'/wialon/ajax.html?svc=token/login');
    curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, 'params='.json_encode($params));
    $out = curl_exec($ch);
    curl_close($ch);
    $result = json_decode($out, true);
    // get sid from login response
    $sid = $result['eid'];
   // import_messages request (upload file)

    $params = array(
     
        'itemId' => $unitId
    );

    $params2 = array(
        'file' => '@'.realpath($filename),
        'params' => json_encode($params)
    );
    $ch = curl_init();
  
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);                
    curl_setopt($ch, CURLOPT_URL, $url.'/wialon/ajax.html?svc=exchange/import_messages&sid='.$sid);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, 'params='.json_encode($params));
    $out = curl_exec($ch);
    curl_close($ch);

//The code below is another way that I try but get the same error

   /* $args = array(
        //'sid' => $sid,*/        

    $params = array(
            'svc' => "exchange/import_messages",
            'sid' => $sid,
            'params' =>array('itemId' => $unitId),
            'file' => '@'.$filename
        );
//$params['messages_filter_import_file'] = '@'.$filename;

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_URL, $url.'/wialon/ajax.html?'.json_encode($params));
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($params));
    $out = curl_exec($ch);
    curl_close($ch);


    echo $out;
?>

I don´t know what is wrong with that , this should work but it isn´t.

6

Error :4 on Import WLP with php wialon master

Re: Error :4 on Import WLP with php wialon master

monitoreo2
error:4 for this requests means that wialon didn't get files
Please check your code

   // you set $params2 
    $params2 = array(
        'file' => '@'.realpath($filename),
        'params' => json_encode($params)
    );
    // and then use $params
    curl_setopt($ch, CURLOPT_POSTFIELDS, 'params='.json_encode($params));
$params = array(
            'svc' => "exchange/import_messages",
            'sid' => $sid,
            'params' =>array('itemId' => $unitId),
            'file' => '@'.$filename
);
// http://php.net/manual/en/function.curl-setopt.php
// CURLOPT_POSTFIELDS - This parameter can either be passed as a urlencoded string like 'para1=val1&para2=val2&...' or as an array with the field name as key and field data as value.
// NOT JSON string
 curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($params));
7

Error :4 on Import WLP with php wialon master

Re: Error :4 on Import WLP with php wialon master

This is exactly the code that I´m using but I continued getting error:4, as you can see it´s the same that you passed me the first time, only declare the params outside of CURLOPT_POSTFIELDS add the avl_evts to see what I got but the result its actually nothing.

<?php 
    $url = 'https://hst-api.wialon.com';
    $token = 'token';
    $unitId = 1111111; //I try with a string too
    $filename = 'prueba.wlp'; //This file is in the same place that the code file

    // Login request
    $params = array('token' => $token);
    $ch = curl_init();

    curl_setopt($ch, CURLOPT_URL, $url.'/wialon/ajax.html?svc=token/login');
    curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, 'params='.json_encode($params));
    $out = curl_exec($ch);
    curl_close($ch);
    $result = json_decode($out, true);
    // get sid from login response
    $sid = $result['eid'];
   // import_messages request (upload file)
    $params = array(
        'sid' => $sid,
        'itemId' => $unitId
    );

    $params2 = array(
        'file' => '@'.realpath($filename),
        'params' => json_encode($params)
    );

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url.'/wialon/ajax.html?svc=exchange/import_messages&sid='.$sid);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $params2);
    $out = curl_exec($ch);
    curl_close($ch);
    echo $out;

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_URL, $url.'/avl_evts?sid='.$sid);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
    curl_setopt($ch, CURLOPT_POST, true);
    $out = curl_exec($ch);
    curl_close($ch);
    echo "<br><br>avl_evts: $out<br/>";
?>

And leave an image with the result.

8

Error :4 on Import WLP with php wialon master

Re: Error :4 on Import WLP with php wialon master

Sorry , I forget the image in the above post

9

Error :4 on Import WLP with php wialon master

Re: Error :4 on Import WLP with php wialon master

In last sample you send file with exchange/import_messages request, so i believe prueba.wlp should be .wln or .wlb file with messages inside. Please try your code with messages.wln file from attachment

Post's attachments

Attachment icon messages.wln 838 b, 469 downloads since 2017-12-15 

10

Error :4 on Import WLP with php wialon master

Re: Error :4 on Import WLP with php wialon master

I continued getting the same error even with the file that you attach in the previous response, I try it local and in a server with different ways and files but the result is always the same.

How could be this possible?

11

Error :4 on Import WLP with php wialon master

Re: Error :4 on Import WLP with php wialon master

Hi monitoreo2!
You can try your query again via beta and check field "reason" in answer

12

Error :4 on Import WLP with php wialon master

Re: Error :4 on Import WLP with php wialon master

Hi! I have a wlp file  exported from the web plattform, i want import this wlp in others units. I've dont see how pass the unit id, in the code above does not pass any itemId, if i try to run this code whats happens? In wich unit will be import the file wlp.


shmi wrote:

The code above shows how to upload file to Wialon using Remote API. Extension and svc doesn't matter.

Also note that exchange/import_json request doen't actually import anything. Just parse JSON and return parsed result back in *avl_evts*

Here's working sample with .wlp (replace TOKEN and place unit.wlp in folder)

<?
    $url = 'https://hst-api.wialon.com';
    $token = 'TOKEN';
    $filename = 'unit.wlp';

    // Login request
    $params = array('token' => $token);
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url.'/wialon/ajax.html?svc=token/login');
    curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, 'params='.json_encode($params));
    $out = curl_exec($ch);
    curl_close($ch);
    $out = json_decode($out, true);

    // get sid from login response
    $sid = $out['eid'];

    // import_messages request (upload file)
    $params = array(
        'sid' => $sid,
        'eventHash' => 'any_random_string_you_like'
    );
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url.'/wialon/ajax.html?svc=exchange/import_json&sid='.$sid);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, array(
        'file' => '@'.realpath($filename),
        'params' => json_encode($params)
    ));
    $out = curl_exec($ch);
    curl_close($ch);

    echo "exchange/import_json: $out<br/>";

    // wait while file parsing
    sleep(3);

    // get events
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url.'/avl_evts?sid='.$sid);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
    curl_setopt($ch, CURLOPT_POST, true);
    $out = curl_exec($ch);
    curl_close($ch);

    // In response you'll see event with hash 'any_random_string_you_like'
    // This is result of parsing uploaded file
    echo "avl_evts: $out<br/>";

?>
13

Error :4 on Import WLP with php wialon master

Re: Error :4 on Import WLP with php wialon master

exchange/import_json method just parse file, not create any Items in Wialon.

If you have wlp file and want to create unit using it try these steps
- parse file with exchange/import_json (or you can do it on PHP side)
- get all needed data from parsed data (e.g. hw type, sensors or whatever you have in wlp file)
- using data from previous step create unit with core/create_unit request
- update other params with unit/unit requests

14

Error :4 on Import WLP with php wialon master

Re: Error :4 on Import WLP with php wialon master

I have tested with sample . But error code

exchange/import_json: {"error":4}
avl_evts: {"tm":1534858439,"events":[]}



wlp file : REG;1534857615;78.3502696;17.4070704;0;0;ALT:0.0,a:21.6520004272;SATS:9,b:42;p:"fused";mc:2;;
Please suggest.

wcauichr wrote:

Hi! I have a wlp file  exported from the web plattform, i want import this wlp in others units. I've dont see how pass the unit id, in the code above does not pass any itemId, if i try to run this code whats happens? In wich unit will be import the file wlp.


shmi wrote:

The code above shows how to upload file to Wialon using Remote API. Extension and svc doesn't matter.

Also note that exchange/import_json request doen't actually import anything. Just parse JSON and return parsed result back in *avl_evts*

Here's working sample with .wlp (replace TOKEN and place unit.wlp in folder)

<?
    $url = 'https://hst-api.wialon.com';
    $token = 'TOKEN';
    $filename = 'unit.wlp';

    // Login request
    $params = array('token' => $token);
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url.'/wialon/ajax.html?svc=token/login');
    curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, 'params='.json_encode($params));
    $out = curl_exec($ch);
    curl_close($ch);
    $out = json_decode($out, true);

    // get sid from login response
    $sid = $out['eid'];

    // import_messages request (upload file)
    $params = array(
        'sid' => $sid,
        'eventHash' => 'any_random_string_you_like'
    );
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url.'/wialon/ajax.html?svc=exchange/import_json&sid='.$sid);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, array(
        'file' => '@'.realpath($filename),
        'params' => json_encode($params)
    ));
    $out = curl_exec($ch);
    curl_close($ch);

    echo "exchange/import_json: $out<br/>";

    // wait while file parsing
    sleep(3);

    // get events
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url.'/avl_evts?sid='.$sid);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
    curl_setopt($ch, CURLOPT_POST, true);
    $out = curl_exec($ch);
    curl_close($ch);

    // In response you'll see event with hash 'any_random_string_you_like'
    // This is result of parsing uploaded file
    echo "avl_evts: $out<br/>";

?>
15

Error :4 on Import WLP with php wialon master

Re: Error :4 on Import WLP with php wialon master

venujakku

wlp file : REG;1534857615;78.3502696;17.4070704;0;0;ALT:0.0,a:21.6520004272;SATS:9,b:42;p:"fused";mc:2;;

It looks like WLN, WLP is JSON formatted

16

Error :4 on Import WLP with php wialon master

Re: Error :4 on Import WLP with php wialon master

shmi wrote:

WLP


Can you send me WLP sample example

17

Error :4 on Import WLP with php wialon master

Re: Error :4 on Import WLP with php wialon master

venujakku wrote:
shmi wrote:

WLP


Can you send me WLP sample example


Or Please advice me how can I generate WLP message from website or API with example. I am struct in middle