PHP Library

Install and Create an Application

A. Requirements

  • Already installed the sublime application, if you don't have the sublime application please download it at the following link. Follow this tutorial.

  • Already installed the xampp application, if you don't have the xampp application please download it at the following link. Follow this tutorial.

B. Steps

  1. Please download the antares php library and save it on your local computer by clicking the button below.

  1. Firstly, register to create an antares account by clicking register now.

  2. Next, fill in the email, password and name on Antares and click the create account button and wait for the notification.

  3. Next, open the email to verify your Antares account.

  4. After verification is complete, login to the Antares account that you have created

  5. After logging into the Antares account, the next step is to click account, an example is shown in the image below

  6. After clicking the account, the Access Key will appear and then click save access key to proceed to the next step.

  7. Create application, if you have already created an application, ignore it and continue to the next process.

  8. Next, click add to create an application on the Antares platform.

  9. Create device, if you have already created the device you can ignore this process and proceed to the next step.

  10. First create a device name as shown below, in this tutorial the device will be named "sensorSignal". then also select one of the active packages that will be used for the device to be created. In this tutorial using a trial package where the package is only active for seven days. If you have set the device name and selected the package then click +AddFirst create a device name as shown below, in this tutorial the device will be named "sensorSignal". then also select one of the active packages that will be used for the device to be created. In this tutorial using a trial package where the package is only active for seven days. If you have set the device name and selected the package then click +Add

A display of the device that has been created will appear. Data from the device will be entered and displayed in the table provided as shown below.

Start Apache on XAMPP

  1. Next extract the php library that has been downloaded and then copy it to C: \xampp\htdocs, in this tutorial xampp is installed in the C directory.

  1. Next, open xampp then turn on the apache module and wait until the module is green, for example the image as below.

Get all Devices on Application with Latest Data

  1. Open the sublime/visualcode/notepad++ application then drag the example.php and Antares.php that have been copied to the xampp htdocs.

  2. Next, use the script section in example.php and also fill in the variables according to the example below. For other lines, you can comment firs

require_once('./Antares.php');

Antares::init([
  "PLATFORM_URL" => 'https://platform.antares.id:8443', // TODO: Change this to your platform URL
  "ACCESS_KEY" => '{{accesskey}}' // TODO: Change this to your access key
]);
try {
  // RETRIEVE DATA
  echo "============================ Retrieve data =================================\n";
  echo "";
  // get application
  // application name example '/antares-cse/antares-id/example'
  $resp = Antares::getInstance()->get('/antares-cse/antares-id/{{applicationname}}'); // TODO: Change this to your application uri
  if ($resp instanceof AE) {
    echo nl2br("AE: " . $resp->getName() . "\n");
    
    // list all application's devices
    $cntUris = $resp->listContainerUris();
    echo "Containers: " . count($cntUris) . "\n";
    echo "";
    
    foreach ($cntUris as $cntUri) {
      echo "  " . $cntUri . "\n";
      echo "";

      // get device
      $cnt = Antares::getInstance()->get($cntUri);
      echo "    " . $cnt->getName() . "\n";
      echo "";

      try {
        // get latest data
        $la = $cnt->getLatestContentInstace();
        echo "      [$la->ct]:$la->rn $la->con\n";
        echo "";
      } catch (Exception $e) {
        echo "      last data: " . $e->getMessage() . "\n";
        echo "";
      }
    }
  }
} catch (Exception $e) {
  echo($e->getMessage());
}
  1. The next step is to open http://localhost/antares-php/example.php (according to the storage folder in htdocs) in the browser, then the following results will appear:

Get Data ID on Devices by Limit

  1. Open the sublime/visualcode/notepad++ application then drag the example.php and Antares.php that have been copied to the xampp htdocs.

  2. Next, use the script section in example.php and also fill in the variables according to the example below. For other lines, you can comment first

    require_once('./Antares.php');
    
    Antares::init([
      "PLATFORM_URL" => 'https://platform.antares.id:8443', // TODO: Change this to your platform URL
      "ACCESS_KEY" => '{{accesskey}}' // TODO: Change this to your access key
    ]);
    try {
      // DISCOVERY LIMIT AND OFFSET
      echo "\n\n";
      echo "";
      echo "============================ Discovery =================================\n";
      echo "";
      // application name & device name example '/antares-cse/antares-id/example/example'
      $cnt = Antares::getInstance()->get('/antares-cse/antares-id/{{applicationame}}/{{devicename}}'); // TODO: Change this to your container uri
      $first10 = $cnt->listContentInstanceUris(10);
      
      // print first10
      foreach ($first10 as $uri) {
        echo $uri . "\n";
        echo "";
      }
      echo "==============================\n";
      echo "";
      $next10 = $cnt->listContentInstanceUris(10, count($first10));
      // print next10
      foreach ($next10 as $uri) {
        echo $uri . "\n";
        echo "";
      }
      
      $inc = 1;
      echo "==============================\n";
      echo "";
      $next10 = $cnt->listContentInstanceUris(10, count($first10) * $inc++ + count($next10));
      // print next10
      foreach ($next10 as $uri) {
        echo $uri . "\n";
        echo "";
      }
    
      echo "==============================\n";
      echo "";
      $next10 = $cnt->listContentInstanceUris(10, count($first10) * $inc++ + count($next10));
      // print next10
      foreach ($next10 as $uri) {
        echo $uri . "\n";
        echo "";
      }
      
      
      echo "==============================\n";
      echo "";
      $next10 = $cnt->listContentInstanceUris(10, count($first10) * $inc++ + count($next10));
      // print next10
      foreach ($next10 as $uri) {
        echo $uri . "\n";
        echo "";
      }
    } catch (Exception $e) {
      echo($e->getMessage());
    }
  3. The next step is to open http://localhost/antares-php/example.php (according to the storage folder in htdocs) in the browser, then the following results will appear:

Store Data to Devices

  1. Open the sublime/visualcode/notepad++ application then drag the example.php and Antares.php that have been copied to the xampp htdocs.

  2. Next, use the script section in example.php and also fill in the variables according to the example below. For other lines, you can comment first

    require_once('./Antares.php');
    
    Antares::init([
      "PLATFORM_URL" => 'https://platform.antares.id:8443', // TODO: Change this to your platform URL
      "ACCESS_KEY" => '{{accesskey}}' // TODO: Change this to your access key
    ]);
    try {
      // STORE DATA
      echo "\n\n";
      echo "============================ Insert data =================================\n";
      echo "";
      try {
        // application name & device name example '/antares-cse/antares-id/example/example'
        $cnt = Antares::getInstance()->get('/antares-cse/antares-id/{{applicationame}}/{{devicename}}'); // TODO: Change this to your container uri
        $lastCin = $cnt->getLatestContentInstace();
        echo "Last CIN: [$lastCin->ct]:$lastCin->rn $lastCin->con\n";
        echo "";
      } catch (Exception $e) {
        echo "Last CIN: " . $e->getMessage() . "\n";
        echo "";
      }
      try {
        $cnt->insertContentInstance('{"help":2.0}', 'application/json');
        $lastCin = $cnt->getLatestContentInstace();
        echo "Current Last CIN: [$lastCin->ct]:$lastCin->rn $lastCin->con\n";
        echo "";
      } catch (Exception $e) {
        echo "Inserting CIN: " . $e->getMessage() . "\n";
        echo "";
      }
    } catch (Exception $e) {
      echo($e->getMessage());
    }
  3. The next step is to open http://localhost/antares-php/example.php (according to the storage folder in htdocs) in the browser, then the following results will appear:

Last updated