Di bawah ini adalah beberapa contoh kode yang dapat anda gunakan untuk mengirim data dari proyek yang telah anda buat ke ANTARES.
ESP8266(HTTP) ESP8266(MQTT) NODE JS PYTHON
Di bawah ini adalah video tutorial yang dapat anda gunakan untuk mengirim dan mendapatkan data dari ANTARES melalui ESP8266 (HTTP).
Harap install pada Arduino IDE.
Copy #include <AntaresESP8266HTTP.h>
#define ACCESSKEY "your-access-key"
#define WIFISSID "your-wifi-ssid"
#define PASSWORD "your-wifi-password"
#define applicationName "your-application-name"
#define deviceName "your-device-name"
AntaresESP8266HTTP antares(ACCESSKEY);
void setup() {
Serial.begin(115200);
antares.setDebug(true);
antares.wifiConnection(WIFISSID,PASSWORD);
}
void loop() {
int temp = random(25,30);
int hum = random(75,90);
antares.add("temperature", temp);
antares.add("humidity", hum);
antares.send(applicationName, deviceName);
delay(10000);
}
Selamat, anda telah mengirim data ke ANTARES.
Copy #include <AntaresESP8266MQTT.h>
#define ACCESSKEY "your-access-key"
#define WIFISSID "your-wifi-ssid"
#define PASSWORD "your-wifi-password"
#define applicationName "your-application-name"
#define deviceName "your-device-name"
AntaresESP8266MQTT antares(ACCESSKEY);
void setup() {
Serial.begin(115200);
antares.setDebug(true);
antares.wifiConnection(WIFISSID,PASSWORD);
antares.setMqttServer();
}
void loop() {
int temp = random(25,30) ;
int hum = random(75,90);
antares.add("temperature", temp);
antares.add("humidity", hum);
antares.publish(applicationName, deviceName);
delay(5000);
}
Selamat, anda telah mengirim data ke ANTARES.
Silahkan install antares-http
dengan npm terlebih dahulu, pastikan npm dan NodeJS terinstall pada CMD (Windows) atau Terminal (Linux):
Copy npm init
npm install antares-http --save
Copy const antares = require('antares-http');
data = {
temperature: 32,
humidity: 80,
}
antares.setAccessKey('your-access-key');
antares.send(data, 'your-project-name', 'your-device-name')
.then((response) => {
console.log(response);
});
Selamat, anda telah mengirim data ke ANTARES.
Silahkan install antares-http
dengan pip terlebih dahulu, pastikan pip dan Python terinstall pada CMD (Windows) atau Terminal (Linux):
Copy pip install antares-http
Copy from antares_http import antares
data = {
'temperature' : 32,
'humidity' : 80
}
antares.setAccessKey('your-access-key')
antares.send(data, 'your-project-name', 'your-device-name')
Selamat, anda telah mengirim data ke ANTARES.