[Solved] Devices  

  RSS

JBFelizberto
(@jbfelizberto)
Trusted Member
Joined: 2 months ago
Posts: 27
25/03/2019 1:10 am  

Hi James,

I have a doubt regarding to devices properties:

1) From gps::devices, I got the array:


[{"id":2,"attributes":{},"groupId":0,"name":"device01","uniqueId":"device01","status":"offline","lastUpdate":null,"positionId":0,"geofenceIds":[],"phone":"","model":"","contact":"","category":null,"disabled":false}]
''''
How I split this information? I mean, I would like to create a variable $IMEI = (uniqueid from this array). I am not know how ....

2) Today I use a combobox (type multiple) that ready the information using MySqli:
'''
<?php
$sql2 = "select * from tc_devices order by name asc";
$resultado2 = $MySQLi->query($sql2) OR trigger_error($MySQLi->error, E_USER_ERROR);
while ($retorno2 = $resultado2->fetch_object()) {
?><option value="<?php echo $retorno2->id;?>"><?php echo $retorno2->name . " (IMEI: " . $retorno2->uniqueid ." )";?></option><?php
}
$resultado2->free();
?>

How I convert it to use traccarAPI if I need to informe to gps::device($session, $id) id by id, if I do not know which id there are.

 

Can you help me?

Regards,  JB

This topic was modified 2 months ago 2 times by jaimzj

Quote
jaimzj
(@jaimzj)
Guru Admin
Joined: 11 months ago
Posts: 46
25/03/2019 1:40 am  

You need to read and look up on topics related to JSON and PHP

one example way of handling a JSON Object I can share

$json = '{"foo-bar": 12345}';

$obj = json_decode($json);
print $obj->{'foo-bar'}; // 12345

feel free to let me know if you get stuck with this, this example can be used as a starting point.

Also please if you could while posting on this forum, put codes in code tag (So it looks pretty and readable), I have been modifying all your posts to fix it.

Markers & maps are magical !!!


ReplyQuote
JBFelizberto
(@jbfelizberto)
Trusted Member
Joined: 2 months ago
Posts: 27
25/03/2019 5:54 pm  

Thank you for the help (clue). It is working using:

echo "<br> ID: " .$obj['0']['id'];

Please, how I do to list all devices? I mean, How I use the loop search all devices looking by connection PHP <=> API?

Regards,

 

JB


ReplyQuote
jaimzj
(@jaimzj)
Guru Admin
Joined: 11 months ago
Posts: 46
25/03/2019 8:22 pm  

You can google "JSON array loop in PHP" and will find lots of tutorials for it.

Markers & maps are magical !!!


ReplyQuote
JBFelizberto
(@jbfelizberto)
Trusted Member
Joined: 2 months ago
Posts: 27
25/03/2019 8:57 pm  

Please, I need just sharing a bit more detail specific to API. 

I found examples to  "JSON array loop in PHP", but  "loop through api  json" to create   [MY ARRAY FROM TRACCAR API] to only after proceed with such the loops, I don´t know how start - sorry. 

JB


ReplyQuote
JBFelizberto
(@jbfelizberto)
Trusted Member
Joined: 2 months ago
Posts: 27
25/03/2019 9:37 pm  

Sharing my current status:

After many trying , I only was able to move on after edited the file traccarApi.php, adding :

public static function devices2($sessionId){

return self::curl('/api/devices','GET',$sessionId,'',array());
}

I have the returns in array

 

[{"id":4,"attributes":{},"groupId":0,"name":"device01","uniqueId":"device01","status":"offline","lastUpdate":null,"positionId":0,"geofenceIds":[],"phone":"","model":"","contact":"","category":null,"disabled":false},{"id":5,"attributes":{},"groupId":0,"name":"devices02","uniqueId":"devices02","status":"offline","lastUpdate":null,"positionId":0,"geofenceIds":[],"phone":"","model":"","contact":"","category":null,"disabled":false}]

 

Now I will try use the PHP json loop.

JB


ReplyQuote
jaimzj
(@jaimzj)
Guru Admin
Joined: 11 months ago
Posts: 46
25/03/2019 9:52 pm  

I would recommend you to work step by step..

Your questions are now confusing. and not clear.

Also it has nothing to do with API or traccar, basically its all about JSON handling in PHP, you will have to spend some time learning.

Then ask me specific questions with proper details on what you are finding difficulty in. and I can try to help.

Markers & maps are magical !!!


ReplyQuote
jaimzj
(@jaimzj)
Guru Admin
Joined: 11 months ago
Posts: 46
25/03/2019 10:35 pm  

You need not modify the  traccarApi.php file, you might need to study about JSON Object and JSON Array difference as well.

Why dont you add more device and check.

Markers & maps are magical !!!


ReplyQuote
Share:
  
Working

Please Login or Register