# Mengirim Data Sederhana ke Antares dengan Protokol HTTP

## Pendahuluan

Pada project  ini Anda akan diarahkan untuk mengirim data sederhana dari **Development Board Lynx-32** ke **Antares IoT Platform** menggunakan konektivitas Wi-Fi dengan protokol HTTP.

<figure><img src="https://content.gitbook.com/content/rRkxjRLeqOm0pNhLfsus/blobs/C1jAfqWy5R2UFosNuGJH/Mengirim%20Data%20Sederhana%20ke%20Antares%20dengan%20Protokol%20HTTP.png" alt=""><figcaption><p>Gambar Ilustrasi Project</p></figcaption></figure>

## Prasyarat

Material yang dibutuhkan mengikuti **Prasyarat Umum** pada laman sebelumnya. Jika Anda belum menyiapkan kebutuhan pada laman tersebut, maka Anda dapat mengunjungi laman berikut.

{% content-ref url="../prasyarat-umum-esp32-wi-fi" %}
[prasyarat-umum-esp32-wi-fi](https://docs.antares.id/contoh-kode-dan-library/esp32-wi-fi/prasyarat-umum-esp32-wi-fi)
{% endcontent-ref %}

Adapun tambahan material yang spesifik untuk project ini adalah sebagai berikut.

1. Library Antares ESP HTTP. Pada dokumentasi ini menggunakan library **Antares ESP HTTP versi 1.6.0.**

{% hint style="info" %}
Jika anda belum menginstall **Antares ESP HTTP 1.6.0** dapat mengikuti langkah berikut.

[antares-wi-fi-http](https://docs.antares.id/pendahuluan/instalasi-library-arduino/antares-wi-fi-http "mention")
{% endhint %}

## Langkah Kerja

### **1. Jalankan Aplikasi Arduino IDE**

### **2. Membuka Contoh Program**

{% hint style="info" %}
Kode program dapat Anda buka pada Arduino IDE melalui **File > Examples > Antares ESP HTTP > AntaresStoreData.**
{% endhint %}

Berikut adalah kode program contoh AntaresStoreData.

```arduino
/*
  This code will deploy data to your Antares project device with the following structure:
  (Note that nesting the JSON object can only be done up to 2 levels using this library)
  {
    "temperature": random-int,
    "humidity": random-int,
    "wind_speed": random-float,
    "rain_level": random-float,
    "location" : {
      "latitude": "static-string",
      "longitude": "static-string"
    }
  }
  For more information please visit https://antares.id/id/docs.html
*/

#include <AntaresESPHTTP.h>

#define ACCESSKEY "YOUR-ACCESS-KEY"       // Replace with your Antares account access key
#define WIFISSID "YOUR-WIFI-SSID"         // Replace with your Wi-Fi SSID
#define PASSWORD "YOUR-WIFI-PASSWORD"     // Replace with your Wi-Fi password

#define projectName "YOUR-APPLICATION-NAME"   // Replace with the Antares application name that was created
#define deviceName "YOUR-DEVICE-NAME"     // Replace with the Antares device name that was created

AntaresESPHTTP antares(ACCESSKEY);

void setup() {
  Serial.begin(115200);
  antares.setDebug(true);
  antares.wifiConnection(WIFISSID, PASSWORD);
}

void loop() {
    // Variables
  int temp = random(25,30) ;
  int hum = random(75,90);
  float windsp = float(random(20, 30))/3.33;
  float rainlv = float(random(0, 20))/6.99;
  String lat = "-6.8718189";
  String lon = "107.5872477";

  // Add variable data to storage buffer
  antares.add("temperature", temp);
  antares.add("humidity", hum);
  antares.add("wind_speed", windsp);
  antares.add("rain_level", rainlv);
  antares.add("location", "latitude", lat);
  antares.add("location", "longitude", lon);

  // Send from buffer to Antares
  antares.send(projectName, deviceName);
  delay(10000);
}

```

### **3. Set HTTP Parameter pada Kode Program**

Ubah parameter Protokol HTTP pada variabel berikut **\*ACCESSKEY, \*WIFISSID, \*PASSWORD, \*projectName,** dan **\*deviceName.** Sesuaikan dengan parameter di console Antares.&#x20;

```arduino
#define ACCESSKEY "YOUR-ACCESS-KEY"       // Replace with your Antares account access key
#define WIFISSID "YOUR-WIFI-SSID"         // Replace with your Wi-Fi SSID
#define PASSWORD "YOUR-WIFI-PASSWORD"     // Replace with your Wi-Fi password

#define projectName "YOUR-APPLICATION-NAME"   // Replace with the Antares application name that was created
#define deviceName "YOUR-DEVICE-NAME"     // Replace with the Antares device name that was created
```

{% hint style="info" %}
Parameter **\*Access key** didapat dari laman akun Antares Anda.
{% endhint %}

<figure><img src="https://3995702122-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrRkxjRLeqOm0pNhLfsus%2Fuploads%2FOwjl0QLzoSAsGheYULv8%2Faccess%20key.png?alt=media&#x26;token=064f2e4c-ff48-43a2-a34a-bbf49cf0276c" alt=""><figcaption><p>Letak Access Key di Laman Akun Antares</p></figcaption></figure>

{% hint style="info" %}
Parameter **WIFISSID** didapat dari nama **Wi-Fi/Hotspot** yang nantinya akan digunakan oleh **Development Board Lynx-32**. Contohnya pada gambar di bawah ini.
{% endhint %}

<figure><img src="https://content.gitbook.com/content/rRkxjRLeqOm0pNhLfsus/blobs/rS5qyBQzbBxjYHC5zG8K/2_wifi.png" alt=""><figcaption><p>WIFISSID</p></figcaption></figure>

{% hint style="info" %}
Parameter **\*PASSWORD** didapat dari **password Wi-Fi** yang sedang anda gunakan.
{% endhint %}

{% hint style="info" %}
Parameter **\*projectName** dan **\*deviceName** didapat dari **Application Name** dan **Device Name** yang sudah dibuat dalam akun Antares.
{% endhint %}

<figure><img src="https://3995702122-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrRkxjRLeqOm0pNhLfsus%2Fuploads%2F3G3Pek1wflcHqrdfG5lp%2Flynx%2032%20app.png?alt=media&#x26;token=b580c2bc-544b-457f-99ca-d7ceea76fdad" alt=""><figcaption><p>Tampilan Application Name</p></figcaption></figure>

<figure><img src="https://3995702122-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrRkxjRLeqOm0pNhLfsus%2Fuploads%2FOH0ltufXnZb7GqIFJlro%2Fantares%20shield%20dev.png?alt=media&#x26;token=6fff53e5-8e27-4639-9ef9-c617ac535262" alt=""><figcaption><p>Tampilan Device Name</p></figcaption></figure>

### **4. Compile dan Upload Program**

Hubungkan **Lynx-32** dengan komputer Anda dan pastikan **Communication Port** terbaca.

{% hint style="info" %}
Pada sistem operasi Windows pengecekan dapat dilakukan melalui **Device Manager.** Jika **Lynx-32** Anda terbaca maka tampil **USB-Serial CH340** dengan port menyesuaikan ketersediaan port (pada kasus ini terbaca **COM4**).
{% endhint %}

<figure><img src="https://content.gitbook.com/content/rRkxjRLeqOm0pNhLfsus/blobs/9vD3gHWKgUn7ylVNCzBg/4_comport.PNG" alt=""><figcaption><p>Tampilan Device Manager</p></figcaption></figure>

Atur board **ESP32** dengan klik **Tools > Board > esp32** pada Arduino IDE, kemudian pastikan yang digunakan adalah **ESP32 Dev Module.** Pilih port sesuai communication port yang terbaca (dalam kasus ini COM4). Hasilnya akan terlihat seperti gambar berikut.

<figure><img src="https://content.gitbook.com/content/rRkxjRLeqOm0pNhLfsus/blobs/7FW4yxQq6LVrxZNOnly3/5_menu.png" alt="" width="464"><figcaption><p>Tampilan Spesifikasi Board dan Port yang Digunakan</p></figcaption></figure>

Setelah semua setup selesai, lakukan upload program dengan menekan icon panah seperti gambar berikut. Tunggu hingga selesai proses compile dan upload

<figure><img src="https://content.gitbook.com/content/rRkxjRLeqOm0pNhLfsus/blobs/gpDikvgBJEmWGggcf4N2/6_arduino.PNG" alt=""><figcaption><p>Ikon Compile untuk Centang dan Ikon Upload untuk Tanda Panah</p></figcaption></figure>

{% hint style="info" %}
**Icon Centang** pada Arduino IDE hanyalah proses verify. Biasanya digunakan untuk **Compile** program untuk mengetahui apakah terdapat error atau tidak.

**Icon Panah** pada Arduino IDE adalah proses verify dan upload. Biasanya digunakan untuk **Compile** program sekaligus **Flash Program** pada target board.
{% endhint %}

Jika upload program berhasil maka akan terlihat seperti gambar berikut.

<figure><img src="https://content.gitbook.com/content/rRkxjRLeqOm0pNhLfsus/blobs/qAwp9sVzGw79SeE8gKgo/7_result.PNG" alt=""><figcaption><p>Tampilan Keluaran Program Berhasil Di Upload</p></figcaption></figure>

Setelah selesai upload program, Anda dapat melihat **serial monitor** untuk melakukan debug program. Icon **serial monitor** terlihat pada gambar berikut.

<figure><img src="https://content.gitbook.com/content/rRkxjRLeqOm0pNhLfsus/blobs/ZYYSdn3rBrLg0NdkVGiJ/8_serial%20monitor.png" alt=""><figcaption><p>Ikon Serial Monitor</p></figcaption></figure>

Atur **serial baud rate** menjadi 115200 dan pilih BothNL & CR. Hasilnya akan terlihat seperti gambar berikut.

<figure><img src="https://content.gitbook.com/content/rRkxjRLeqOm0pNhLfsus/blobs/X5G3fCAxrmw1i57edVOH/9_serialmonitor.PNG" alt=""><figcaption><p>Tampilan Serial Monitor</p></figcaption></figure>

{% hint style="danger" %}
Pastikan **serial baud rate** sesuai dengan nilai yang terdefinisi di kode program. Jika **serial baud rate** tidak sama, antara **kode program** dan **serial monitor** maka karakter ASCII tidak akan terbaca dengan baik.
{% endhint %}

### **5. Periksa Data di Antares**

Setelah upload program berhasil, selanjutnya buka halaman device antares kemudian lihat apakah data sudah berhasil dikirim.

<figure><img src="https://3995702122-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrRkxjRLeqOm0pNhLfsus%2Fuploads%2FUNfUG4tfYJnxEDjx5RcT%2Fapp%20dev%20lynx%2032%20-%20antares%20shield.png?alt=media&#x26;token=e3bd13e7-648a-46df-86d3-e5623d59eea7" alt=""><figcaption></figcaption></figure>

<figure><img src="https://3995702122-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrRkxjRLeqOm0pNhLfsus%2Fuploads%2FjUtbwq6C5QQkod4Gj6Bs%2F146.png?alt=media&#x26;token=469c1d6f-c14d-4fec-9dd7-777e4a6cbe0c" alt=""><figcaption><p>Tampilan Antares Console</p></figcaption></figure>

{% hint style="info" %}
Data yang dikirimkan dari **Development Board Lynx-32** dengan protokol HTTP berupa variabel temperature, humidity, wind\_speed, rain\_level, dan location yang berisi latitude dan longitude.
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.antares.id/contoh-kode-dan-library/esp32-wi-fi/esp32-wi-fi-protokol-http/mengirim-data-sederhana-ke-antares-dengan-protokol-http.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
