Mengirim Data Sederhana ke Antares dengan Protokol HTTP
Pendahuluan
Pada project ini Anda akan diarahkan untuk mengirim data sederhana dari ESP8266 ke Antares IoT Platform menggunakan konektivitas WiFi dengan protokol HTTP.

Prasyarat
Material yang dibutuhkan mengikuti Prasyarat Umum pada laman sebelumnya. Jika Anda belum menyiapkan kebutuhan pada laman tersebut, maka Anda dapat mengunjungi laman berikut.
Prasyarat Umum ESP8266 Wi-FiAdapun tambahan material yang spesifik untuk project ini adalah sebagai berikut.
Library Antares ESP HTTP. Pada dokumentasi ini menggunakan library Antares ESP HTTP versi 1.6.0.
Langkah Kerja
1. Jalankan Aplikasi Arduino IDE
2. Membuka Contoh Program
Berikut adalah kode program contoh AntaresStoreData.
/*
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> // Include the AntaresESP32HTTP library
#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-project-name" // Antares project name
#define deviceName "your-project-name" // Name of the device
AntaresESPHTTP antares(ACCESSKEY); // Initialize AntaresESP32HTTP with the access key
void setup() {
Serial.begin(115200); // Initialize serial communication
antares.setDebug(true); // Enable Antares library debug mode
antares.wifiConnection(WIFISSID, PASSWORD); // Connect to WiFi using provided SSID and password
}
void loop() {
// Variables
int temp = random(25,30) ; //Create a random integer value for temperature
int hum = random(75,90); // Create a random integer value for humidity
float windsp = float(random(20, 30))/3.33; //Create a random float value for windspeed
float rainlv = float(random(0, 20))/6.99; //Create a random float value for rainlevel
String lat = "-6.8718189"; //Create a string value for latitude
String lon = "107.5872477"; //Create a string value for longitude
// Add variable data to storage buffer
antares.add("temperature", temp); // Add temperature data to the Antares payload
antares.add("humidity", hum); // Add humidity data to the Antares payload
antares.add("wind_speed", windsp); // Add wind_speed data to the Antares payload
antares.add("rain_level", rainlv); // Add rain_level data to the Antares payload
antares.add("location", "latitude", lat); // Add location latitude data to the Antares payload
antares.add("location", "longitude", lon); // Add location longitude data to the Antares payload
// Send from buffer to Antares
antares.send(projectName, deviceName); // Send data to Antares
delay(10000); // Transfer data for every 10 seconds
}
3. Set Credential WiFi dan Credential Antares pada Kode Program
Ubah parameter Protokol HTTP pada variabel berikut *ACCESSKEY, *WIFISSID, *PASSWORD, *projectName, dan *deviceName. Sesuaikan dengan parameter di console Antares.
#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-project-name" // Antares project name
#define deviceName "your-project-name" // Name of the device




4. Compile dan Upload Program
Hubungkan ESP8266 WEMOS D1R2 dengan komputer Anda dan pastikan Communication Port terbaca.

Atur board ESP8266 WEMOS D1R2 dengan klik Tools > Board > esp8266 pada Arduino IDE, kemudian pastikan yang digunakan adalah LOLIN(WEMOS) D1 R2 & mini. Pilih port sesuai communication port yang terbaca (dalam kasus ini COM4). Hasilnya akan terlihat seperti gambar berikut.

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

Jika upload program berhasil maka akan terlihat seperti gambar berikut.

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

Atur serial baud rate menjadi 115200 dan pilih BothNL & CR. Hasilnya akan terlihat seperti gambar berikut.
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.

5. Periksa Data di Antares
Setelah upload program berhasil, selanjutnya buka halaman device antares kemudian lihat apakah data sudah berhasil dikirim.


Last updated