Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
I
IoT soil moisture project
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
ryan.whiteley
IoT soil moisture project
Commits
5e6b743f
Commit
5e6b743f
authored
Nov 29, 2021
by
ryan.whiteley
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Thinkspeak updates now back working
parent
b2998462
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
8 deletions
+12
-8
soil_moisture.py
soil_moisture.py
+12
-8
No files found.
soil_moisture.py
View file @
5e6b743f
...
@@ -5,8 +5,8 @@ from ADCDevice import *
...
@@ -5,8 +5,8 @@ from ADCDevice import *
adc
=
ADCDevice
()
adc
=
ADCDevice
()
ts_channel_id
=
1
234
ts_channel_id
=
1
564450
ts_write_key
=
''
ts_write_key
=
'
JK4S0XWAC8YK9GDU
'
mqtt_soil_server
=
"192.168.0.25"
mqtt_soil_server
=
"192.168.0.25"
mqtt_soil_path_one
=
"soil_one"
mqtt_soil_path_one
=
"soil_one"
...
@@ -28,15 +28,15 @@ def adc_setup():
...
@@ -28,15 +28,15 @@ def adc_setup():
exit
(
-
1
)
exit
(
-
1
)
#main driver for measurments and MQTT
#main driver for measurments and MQTT
def
main_loop
():
#insert channel variable when setting up thingspeak
def
main_loop
(
channel
):
#insert channel variable when setting up thingspeak
try
:
try
:
#get sensor reading and percentage conversions
#get sensor reading and percentage conversions
soil_one
=
adc
.
analogRead
(
0
)
soil_one
=
adc
.
analogRead
(
0
)
soil_one_percent
=
((
soil_one
-
one_
wet
_reading
)
*
100
)
/
(
one_wet_reading
-
one_dry_reading
)
soil_one_percent
=
((
soil_one
-
one_
dry
_reading
)
*
100
)
/
(
one_wet_reading
-
one_dry_reading
)
soil_two
=
adc
.
analogRead
(
1
)
soil_two
=
adc
.
analogRead
(
1
)
soil_two_percent
=
((
soil_two
-
two_
wet
_reading
)
*
100
)
/
(
two_wet_reading
-
two_dry_reading
)
soil_two_percent
=
((
soil_two
-
two_
dry
_reading
)
*
100
)
/
(
two_wet_reading
-
two_dry_reading
)
soil_avg
=
(
soil_one_percent
+
soil_two_percent
)
/
2
soil_avg
=
(
soil_one_percent
+
soil_two_percent
)
/
2
print
(
soil_one
)
print
(
soil_one
)
...
@@ -50,6 +50,10 @@ def main_loop():#insert channel variable when setting up thingspeak
...
@@ -50,6 +50,10 @@ def main_loop():#insert channel variable when setting up thingspeak
#publish.single(mqtt_soil_path_one, stuff, hostname= mqtt_soil_server)
#publish.single(mqtt_soil_path_one, stuff, hostname= mqtt_soil_server)
#send to thingspeak
test
=
5
response
=
channel
.
update
({
'field1'
:
soil_one_percent
,
'field2'
:
soil_two_percent
,
'field3'
:
soil_avg
,
'field4'
:
test
})
#print to the LCD display
#print to the LCD display
except
:
except
:
print
(
'failed'
)
print
(
'failed'
)
...
@@ -60,12 +64,12 @@ def destroy_all():
...
@@ -60,12 +64,12 @@ def destroy_all():
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
#thingspeak channel settings here
#thingspeak channel settings here
channel
=
thingspeak
.
Channel
(
id
=
ts_channel_id
,
api_key
=
ts_write_key
)
try
:
try
:
while
True
:
while
True
:
adc_setup
()
adc_setup
()
main_loop
()
main_loop
(
channel
)
time
.
sleep
(
1
0
)
time
.
sleep
(
1
5
)
except
KeyboardInterrupt
:
except
KeyboardInterrupt
:
destroy_all
()
destroy_all
()
...
...
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