From c3953d75230fd0a3d20920eb119856764a4d93a5 Mon Sep 17 00:00:00 2001 From: Muhammad Izza Alfiansyah Date: Mon, 6 May 2024 12:24:28 +0700 Subject: [PATCH] fixed website and microcontroller --- .../sketch_apr22a/sketch_apr22a.ino | 10 +++-- website/src/App.tsx | 10 +++-- website/src/pages/Histori.tsx | 11 +++-- website/src/pages/Index.tsx | 41 +++++++++++++++++-- 4 files changed, 57 insertions(+), 15 deletions(-) diff --git a/microcontroller/sketch_apr22a/sketch_apr22a.ino b/microcontroller/sketch_apr22a/sketch_apr22a.ino index 7731bfe..83e9031 100644 --- a/microcontroller/sketch_apr22a/sketch_apr22a.ino +++ b/microcontroller/sketch_apr22a/sketch_apr22a.ino @@ -274,14 +274,16 @@ void cekKegagalan() { for (int i = 0; i < dataPengujian.length(); i++) { int epochTime = (int) dataPengujian[i]["created_time"]; int epochTimeDiff = epochTime - epochTimeAwal; - int jam = epochTimeDiff / 3600; + int lamaJam = epochTimeDiff / 3600; float kadarGas = (double) dataPengujian[i]["kadar_gas"]; - float regresiKadarGas = 0.0025 * pow(jam, 2.0) - 0.0397 * jam - 0.1222; + float regresiKadarGas = 0.0025 * pow(lamaJam, 2.0) - 0.0397 * lamaJam - 0.1222; float nilaiPerempat = regresiKadarGas / 4.0; - if (kadarGas > (regresiKadarGas + nilaiPerempat) || kadarGas < (regresiKadarGas - nilaiPerempat)) { - status = "Gagal"; + if (lamaJam > 12) { + if (kadarGas > (regresiKadarGas + nilaiPerempat) || kadarGas < (regresiKadarGas - nilaiPerempat)) { + status = "Gagal"; + } } } diff --git a/website/src/App.tsx b/website/src/App.tsx index f55aea5..a3c0755 100644 --- a/website/src/App.tsx +++ b/website/src/App.tsx @@ -86,7 +86,7 @@ export default function (props: JSX.HTMLAttributes) { .limit(1); setTimeout(() => { res(data); - }, 5000); + }, 10000); }); const { data: lastData2 } = await supabase @@ -95,11 +95,13 @@ export default function (props: JSX.HTMLAttributes) { .order("created_time", { ascending: false }) .limit(1); - if (lastData1![0].created_time == lastData2![0].created_time) { - alert("Device offline!"); + if (lastHistori()?.selesai) { + if (lastData1![0].created_time == lastData2![0].created_time) { + alert("Device offline!"); + } } - // await checkStatusDevice(); + await checkStatusDevice(); }; onMount(async () => { diff --git a/website/src/pages/Histori.tsx b/website/src/pages/Histori.tsx index 3d4feed..47f0894 100644 --- a/website/src/pages/Histori.tsx +++ b/website/src/pages/Histori.tsx @@ -29,14 +29,19 @@ export default function () { Menampilkan hasil fermentasi yang telah dilakukan.