This commit is contained in:
2026-04-21 10:33:20 +07:00
parent 70c61f2ede
commit 72c82d5389
4 changed files with 52 additions and 2 deletions
+25
View File
@@ -47,6 +47,8 @@ DETIK_ANTAR_KARUNG = 30
RELAY_KIRI_ON = "http://192.168.192.26:5001/relay_on"
RELAY_KIRI_OFF = "http://192.168.192.26:5001/relay_off"
RELAY_KANAN_ON = "http://192.168.192.26:5002/relay_on"
RELAY_KANAN_OFF = "http://192.168.192.26:5002/relay_off"
def init_database():
"""Initialize the SQLite database with the required table"""
@@ -166,6 +168,25 @@ def relay_kiri_on():
except requests.exceptions.RequestException as e:
print(e)
def relay_kanan_off():
global RELAY_KANAN_ON, RELAY_KANAN_OFF
try:
requests.get(RELAY_KANAN_OFF, timeout=1)
print(f"Relay Kanan OFF")
except requests.exceptions.RequestException as e:
print(e)
def relay_kanan_on():
global DETIK_ANTAR_KARUNG
try:
requests.get(RELAY_KANAN_ON, timeout=1)
threading.Timer(DETIK_ANTAR_KARUNG, relay_kanan_off).start()
print(f"Relay Kanan ON -> Start Counter Kanan: {DETIK_ANTAR_KARUNG} seconds")
except requests.exceptions.RequestException as e:
print(e)
# =====================
# RESET HARIAN
# =====================
@@ -335,6 +356,9 @@ def on_message(client, userdata, msg):
if camera == "kandang_atas_feeder_kiri":
relay_kiri_on()
if camera == "kandang_bawah_feeder_kanan":
relay_kanan_on()
except Exception as e:
print("Error parsing message:", e)
@@ -373,6 +397,7 @@ schedule_reset()
#schedule_reset_masuk()
# Pastikan Relay OFF
relay_kiri_off()
relay_kanan_off()
client_publish.loop_start()
print(f"MQTT Publish Counter berjalan di {PUBLISH_BROKER}")