Skip to content

Commit

Permalink
catch empty result from ovms server
Browse files Browse the repository at this point in the history
  • Loading branch information
TrystanLea committed Jul 13, 2019
1 parent 161b3df commit c1d5f2f
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions demandshaper-module/demandshaper_controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -277,22 +277,23 @@ function demandshaper_controller()
$csv_str = http_request("GET","https://dexters-web.de/api/call?fn.name=ovms/export&fn.vehicleid=$vehicleid&fn.carpass=$carpass&fn.format=csv&fn.types=D,S&fn.last=1",array());
$csv_lines = explode("\n",$csv_str);

$headings1 = explode(",",$csv_lines[1]);
$data1 = explode(",",$csv_lines[2]);
$data = array("soc"=>20);
if (count($csv_lines)>6) {
$headings1 = explode(",",$csv_lines[1]);
$data1 = explode(",",$csv_lines[2]);

$headings2 = explode(",",$csv_lines[4]);
$data2 = explode(",",$csv_lines[5]);
$headings2 = explode(",",$csv_lines[4]);
$data2 = explode(",",$csv_lines[5]);

$data = array();

for ($i=0; $i<count($headings1); $i++) {
if (is_numeric($data1[$i])) $data1[$i] *= 1;
$data[$headings1[$i]] = $data1[$i];
}
for ($i=0; $i<count($headings1); $i++) {
if (is_numeric($data1[$i])) $data1[$i] *= 1;
$data[$headings1[$i]] = $data1[$i];
}

for ($i=0; $i<count($headings2); $i++) {
if (is_numeric($data2[$i])) $data2[$i] *= 1;
$data[$headings2[$i]] = $data2[$i];
for ($i=0; $i<count($headings2); $i++) {
if (is_numeric($data2[$i])) $data2[$i] *= 1;
$data[$headings2[$i]] = $data2[$i];
}
}

return $data;
Expand Down

0 comments on commit c1d5f2f

Please sign in to comment.