ATP, short for Automotive Telematics Platform, is an in-vehicle electronic service platform designed to offer intelligent connected car services. Baidu's ATP API allows vehicles to connect to the internet by providing a suite of APIs for real-time data upload, vehicle status monitoring, and data storage—empowering developers to implement smart automotive features.
Before using Baidu's ATP API, you need to create a Car Cloud account, an application, and API credentials (App ID, API Key, Secret Key) through Baidu AI Console. Save these credentials securely after creation.
The Baidu ATP PHP SDK can be installed via Composer, a dependency manager for PHP. Make sure Composer is installed on your local machine. Then run the following command to install the SDK:
composer require baidu/carlife-php-sdk
Once you've obtained the App ID, API Key, and Secret Key, you can start uploading vehicle data using Baidu ATP's API. Here's how to do it:
Before uploading, format your data in JSON according to the ATP specification. Below is an example format:
$data = array(
"carId" => "TEST001", // Vehicle ID
"time" => time(), // Timestamp
"gps" => array(
"longitude" => "116.403408",
"latitude" => "39.923201",
"satellite" => 12,
"speed" => 60
),
"obd" => array(
"vehicle_speed" => 50,
"engine_speed" => 3000,
"coolant_temp" => 50,
"air_flow_rate" => 100,
"throttle_position" => 50,
"intake_air_temp" => 30,
"mileage" => 100
)
);
Adjust the values as needed to match your real-world vehicle data.
To authenticate data uploads, generate a token using your App ID and Secret Key:
$appid = "YOUR_APPID_HERE";
$secret_key = "YOUR_APP_SECRET_KEY_HERE";
$token = \Baidu\CarLife\Token::getToken($appid, $secret_key);
Now use the SDK's `sendData` method to upload your data through the ATP API:
$client = new \Baidu\CarLife\Client($app_key, $secret_key, $token);
$client->sendData($data, "ATP_DEMO");
The `sendData` method takes the vehicle data and a vehicle identifier string (e.g., "ATP_DEMO") as parameters.
Baidu's ATP API also supports vehicle status queries, allowing you to monitor the real-time state of the vehicle. Here's how to do it:
To query vehicle status, provide the vehicle ID and a timestamp. Here's the data format:
$data = array(
"carId" => "TEST001", // Vehicle ID
"time" => time() // Query time
);
As with data upload, generate a token for authentication:
$appid = "YOUR_APPID_HERE";
$secret_key = "YOUR_APP_SECRET_KEY_HERE";
$token = \Baidu\CarLife\Token::getToken($appid, $secret_key);
Use the SDK's `getVehicleStatus` method to query vehicle data via the ATP API:
$client = new \Baidu\CarLife\Client($app_key, $secret_key, $token);
$result = $client->getVehicleStatus($data);
The `getVehicleStatus` method accepts the query data array as input.
This guide walked you through the full process of integrating Baidu's ATP API with PHP, from environment setup and SDK installation to uploading vehicle data and querying vehicle status. By leveraging Baidu's SDK, developers can efficiently connect their vehicles to intelligent data services for real-time monitoring and control.