Skip to content

MenampilkanNilaiPartikelDebuDiCoreX #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: production
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions MenampilkanNilaiPartikelDebuDiCoreX/Connection.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
WiFiClient net;
CoreX corex;

void setupCorex() {
Serial.println("CoreX IoT https://corex.id");
Serial.println("Menghubungkan ke WiFi");
while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
delay(1000);
}

Serial.println("\nTerhubung ke WiFi!");
Serial.print("Menghubungkan ke server");
while (!corex.connect()) {
Serial.print(".");
delay(1000);
}

Serial.println("\nTerhubung ke server!");
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#include <CoreX.h>
#include "Connection.h"
#include <GP2YDustSensor.h>

const uint8_t SHARP_LED_PIN = 14; // Sharp Dust/particle sensor Led Pin
const uint8_t SHARP_VO_PIN = A0; // Sharp Dust/particle analog out pin used for reading

GP2YDustSensor dustSensor(GP2YDustSensorType::GP2Y1014AU0F, SHARP_LED_PIN, SHARP_VO_PIN);

// Ubah nilai auth_token dan device anda.
const char* AUTH_TOKEN = "Hzt3O2EYO0gXeJU";
const char* DEVICE_ID = "CX4us6feg";

CoreXTimer timer; // Gunakan timer agar dapat mengeksekusi perintah setiap sekian milidetik tanpa blocking.

// Ubah nilai berikut sesuai jaringan Anda.
const char ssid[] = "Wokwi-GUEST";
const char pass[] = "";

void setup() {
Serial.begin(115200);
WiFi.begin(ssid, pass);
corex.begin(net);
dustSensor.begin();
timer.setInterval(1000, send); // Lakukan send setiap 1000 milidetik.

setupCorex();
}

void loop() {
timer.run();
delay(10);

// Periksa apakah perangkat masih terhubung.
if (!corex.connected()) {
setupCorex();
}
}

void send() {
corex.send("TeknikFisikaUniversitasNasional", dustSensor.getDustDensity());
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.