Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
I
IOT Soil Moisture Level Reader code
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
jair.canelo
IOT Soil Moisture Level Reader code
Commits
d59dd2eb
Commit
d59dd2eb
authored
Jan 16, 2025
by
jair.canelo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Upload New File
parent
c53a4904
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
42 additions
and
0 deletions
+42
-0
Buzzer3.0.py
Buzzer3.0.py
+42
-0
No files found.
Buzzer3.0.py
0 → 100644
View file @
d59dd2eb
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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment