Skip to content
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
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,50 @@
#include <CoreX.h>
#include "Connection.h"
#include <Wire.h>
#include "HX711.h"

const int LOADCELL_DOUT_PIN = 13;
const int LOADCELL_SCK_PIN = 12;

HX711 scale;

// Ubah nilai auth_token dan device anda.
const char* AUTH_TOKEN = "Syt2vaJ2EPh14p0";
const char* DEVICE_ID = "5TTi2vTpQ";

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);
scale.begin(LOADCELL_DOUT_PIN, LOADCELL_SCK_PIN);
scale.set_scale(230); // Set the scale factor
scale.tare(); // Reset the scale
corex.begin(net);
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() {
float weight = scale.get_units(10);
Serial.print("Weight: ");
Serial.println(weight, 1);
scale.power_down(); // set ADC to sleep mode
delay(1000);
scale.power_up();
int weightInt = static_cast<int>(weight);
corex.send("UNASTFMeb1st", weightInt);
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.