# Library PHP

### Install and Create an Application <a href="#install" id="install"></a>

#### **A. Requirements**

* Sudah terinstall aplikasi sublime, jika anda belum memiliki aplikasi sublime silahkan download pada link berikut: \
  [Ikuti tutorial ini.](https://www.sublimetext.com/download)
* Sudah terinstall aplikasi xampp, jika anda belum memiliki aplikasi xampp silahkan download pada link berikut:\
  [Ikuti tutorial ini.](https://www.apachefriends.org/download.html)

#### **B. Steps**

1. Silahkan download library antares php dan simpan pada lokal komputer anda dengan menekan tombol di bawah ini.

{% file src="<https://content.gitbook.com/content/rRkxjRLeqOm0pNhLfsus/blobs/XPGlstvSQvDNC7xY7g7g/antares-php-master.zip>" %}

2. pertama lakukan registrasi untuk membuat akun antares[ klik register now.](https://console.antares.id/)<br>

   <figure><img src="https://antares.id/assets/img/baru11.png" alt=""><figcaption></figcaption></figure>
3. Selanjutnya isi email, password lalu nama pada Antares dan klik tombol create account dan tunggu hingga ada pemberitahuan.<br>

   <figure><img src="https://antares.id/assets/img/baru13.png" alt=""><figcaption></figcaption></figure>
4. Selanjutnya buka email untuk verifikasi akun antares. <br>

   <figure><img src="https://antares.id/assets/img/baru14.png" alt=""><figcaption></figcaption></figure>
5. Setelah verikasi selesai, Login akun Antares yang telah anda buat <br>

   <figure><img src="https://antares.id/assets/img/baru3.png" alt=""><figcaption></figcaption></figure>
6. Setelah login akun Antares Langkah selanjutnya adalah klik account, contoh ditunjukan pada gambar di bawah ini <br>

   <figure><img src="https://antares.id/assets/img/baru4.png" alt=""><figcaption></figcaption></figure>
7. Setelah klik akun akan muncul Access Key lalu klik save access key untuk menlanjutkan ke Langkah berikutnya <br>

   <figure><img src="https://antares.id/assets/img/baru5.png" alt=""><figcaption></figcaption></figure>
8. Buat application, jika anda sudah membuat application, abaikan dan lanjutkan ke proses selanjutnya.&#x20;

   <figure><img src="https://antares.id/assets/img/baru22.png" alt=""><figcaption></figcaption></figure>
9. Selanjutnya klik add untuk mencreate application pada antares platfrom. <br>

   <figure><img src="https://antares.id/assets/img/baru23.png" alt=""><figcaption></figcaption></figure>
10. Buat device, jika anda sudah membuat device anda bisa mengabaikan proses ini dan melanjutkan ke langkah selanjutnya.&#x20;

    <figure><img src="https://antares.id/assets/img/baru30.png" alt=""><figcaption></figcaption></figure>
11. Buat terlebih dahulu nama device seperti pada gambar di bawah, pada tutorial kali ini device akan diberi nama **"sensorSignal".** lalu **Pilih juga salah satu paket aktif yang akan digunakan untuk device yang akan dibuat**. Pada tutorial kali menggunakan paket trial di mana paket tersebut hanya aktif selama tujuh hari. Jika sudah mengatur nama device dan memilih paket lalu klik **+Add**

<figure><img src="https://3995702122-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrRkxjRLeqOm0pNhLfsus%2Fuploads%2FuzgAQxfVD9MH1jTztMuR%2Flibrary%201.png?alt=media&#x26;token=32fc8161-1be3-445f-8c6f-332634c7e352" alt=""><figcaption></figcaption></figure>

Akan muncul tampilan dari device yang telah dibuat. Data dari device akan masuk dan ditampilkan dalam tabel yang sudah disediakan seperti gambar dibawah ini.

<figure><img src="https://3995702122-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrRkxjRLeqOm0pNhLfsus%2Fuploads%2FQ5QmhT80wzVyS2R5pwPB%2Flibrary%202.png?alt=media&#x26;token=b3ea7dbd-b5b0-4898-90d9-0406f0679eb1" alt=""><figcaption></figcaption></figure>

### **Start Apache on XAMPP**

1. Selanjutnya extract library php yang sudah di download lalu copy ke C:\xampp\htdocs, pada tutorial ini xampp di install pada direktori C.&#x20;

   <figure><img src="https://content.gitbook.com/content/rRkxjRLeqOm0pNhLfsus/blobs/4R8viCWfEBpjdrOumZyE/image.png" alt=""><figcaption></figcaption></figure>
2. Selanjutnya buka xampp lalu nyalakan module apache dan tunggu hingga module berwarna hijau, contoh gambar seperti dibawah ini.&#x20;

   <figure><img src="https://content.gitbook.com/content/rRkxjRLeqOm0pNhLfsus/blobs/sGz90334D3agZGedKzIh/image.png" alt=""><figcaption></figcaption></figure>

### **Get all Devices on Application with Latest Data**

1. Buka aplikasi sublime/visualcode/notepad++ lalu drag example.php dan Antares.php yang sudah di copy pada htdocs xampp.
2. Selanjutnya gunakan bagian script pada example.php dan juga isikan variable sesuai dengan contoh di bawah ini. Untuk line lainnya bisa di comment terlebih dahulu

   <pre class="language-php" data-line-numbers><code class="lang-php">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());
   }

   </code></pre>
3. Langkah selanjutnya buka <http://localhost/antares-php/example.php> (sesuai folder penyimpanan pada htdocs) pada browser, kemudian akan muncul hasil seperti berikut: <br>

   <figure><img src="https://content.gitbook.com/content/rRkxjRLeqOm0pNhLfsus/blobs/WSGDJneRgOKfQ1pMgSCd/image.png" alt=""><figcaption></figcaption></figure>

### **Get Data ID on Devices by Limit**

1. Buka aplikasi sublime/visualcode/notepad++ lalu drag example.php dan Antares.php yang sudah di copy pada htdocs xampp.
2. Selanjutnya gunakan bagian script pada example.php dan juga isikan variable sesuai dengan contoh di bawah ini. Untuk line lainnya bisa di comment terlebih dahulu

   <pre class="language-php" data-line-numbers><code class="lang-php">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 &#x26; 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());
   }
   </code></pre>
3. Langkah selanjutnya buka <http://localhost/antares-php/example.php> (sesuai folder penyimpanan pada htdocs) pada browser, kemudian akan muncul hasil seperti berikut:<br>

   <figure><img src="https://content.gitbook.com/content/rRkxjRLeqOm0pNhLfsus/blobs/KvfU711SHrHuOjJ67OrX/image.png" alt=""><figcaption></figcaption></figure>

### **Store Data to Devices**

1. Buka aplikasi sublime/visualcode/notepad++ lalu drag example.php dan Antares.php yang sudah di copy pada htdocs xampp.
2. Selanjutnya gunakan bagian script pada example.php dan juga isikan variable sesuai dengan contoh di bawah ini. Untuk line lainnya bisa di comment terlebih dahulu

   <pre class="language-php" data-line-numbers><code class="lang-php">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 &#x26; 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());
   }
   </code></pre>
3. Langkah selanjutnya buka <http://localhost/antares-php/example.php> (sesuai folder penyimpanan pada htdocs) pada browser, kemudian akan muncul hasil seperti berikut:&#x20;

   <figure><img src="https://content.gitbook.com/content/rRkxjRLeqOm0pNhLfsus/blobs/0NG4xFVvPPVR6QoJcPjq/image.png" alt=""><figcaption></figcaption></figure>
