Sending Simple Data to Antares with HTTP Protocol
Prerequisites
General Prerequisites ESP8266 Wi-FiFollow These Steps
1. Launch the Arduino IDE application
2. Opening Sample Programme
/*
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 WiFi Credential and Antares Credential in Program Code




4. Compile and Upload Program






5. Check Data in Antares


PreviousESP8266 (Wi-Fi) HTTP ProtocolNextRetrieve the Last Data from Antares Server with HTTP Protocol
Last updated