Commit d59dd2eb authored by jair.canelo's avatar jair.canelo

Upload New File

parent c53a4904
import requests
ARDUINO_IP = "192.168.1.236"
ARDUINO_PORT = 80
try:
#send HTTP GET request
response = requests.get(f"http://{ARDUINO_IP}:{ARDUINO_PORT}")
if response.status_code == 200:
print("Response from Arduino:", response.text)
else:
print(f"Faied to connect. Status code: {response.status_code}")
except requests.exceptions.RequestException as e:
print(f"Error connecting to Arduino: {e}")
def conrol_buzzer(arduino_ip, soil_moisture_value, threshold):
"""
Sends a request to the Arduino to control the buzzer based on soil moisture levels.
:param arduino_ip: IP address of the Arduino
:param soil_moisture_value: Current soil moisture value
:param threshold: Threshold value for soil moisture
"""
url = f"http://{arduino_ip}/control_buzzer"
try:
if soil_moisture_value < threshold:
payload = {'state': 'on'}
print(f"Sending command to turn ON buzzer (Soil moisture: {soil_moisture_value})")
else:
payload = {'state': 'off'}
print(f"Sending command to turn OFF buzzer (Soil moisture: {soil_moisture_value})")
#Send HTTP reuest
response = requests.get(url, params=payload)
if response.status_code == 200:
print(f"Arduino reponse: {response.text}")
else:
print(f"Failed to communicate with Arduino. Status coe: {response.status_code}")
except requests.exceptions.RequestException as e:
print(f"Error: Unable to send request to Arduino. {e}")
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment