Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
2
21_22-J 21
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Charm Thiekshana Perera
21_22-J 21
Commits
0c942578
Commit
0c942578
authored
Dec 22, 2021
by
Charm Thiekshana Perera
💬
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Upload raspberry pi python file
parent
5ea00cdd
Pipeline
#4256
failed with stages
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
107 additions
and
0 deletions
+107
-0
dis.py
dis.py
+107
-0
No files found.
dis.py
0 → 100644
View file @
0c942578
#Libraries
import
RPi.GPIO
as
GPIO
import
time
import
pyrebase
import
distance
import
datetime
,
time
import
gspread
from
oauth2client.service_account
import
ServiceAccountCredentials
config
=
{
"apiKey"
:
"AIzaSyAhxxCf-KaxaFY3LvSipgZUOJYM_m1bmNA"
,
"authDomain"
:
"flood-data-905f4.firebaseapp.com"
,
"databaseURL"
:
"https://flood-data-905f4-default-rtdb.firebaseio.com"
,
"projectId"
:
"flood-data-905f4"
,
"storageBucket"
:
"flood-data-905f4.appspot.com"
,
"messagingSenderId"
:
"252644106216"
,
"appId"
:
"1:252644106216:web:72a89cd23231e12de80e5d"
,
"measurementId"
:
"G-GE2LTX5TTE"
};
scope
=
[
'https://spreadsheets.google.com/feeds'
,
'https://www.googleapis.com/auth/drive'
]
creds
=
ServiceAccountCredentials
.
from_json_keyfile_name
(
'mydata.json'
,
scope
)
#replace mydata.json with the name of your data file
client
=
gspread
.
authorize
(
creds
)
sheet
=
client
.
open
(
"Raspi_data"
)
.
sheet1
#GPIO Mode (BOARD / BCM)
GPIO
.
setmode
(
GPIO
.
BCM
)
#set GPIO Pins
GPIO_TRIGGER
=
4
GPIO_ECHO
=
17
#set GPIO direction (IN / OUT)
GPIO
.
setup
(
GPIO_TRIGGER
,
GPIO
.
OUT
)
GPIO
.
setup
(
GPIO_ECHO
,
GPIO
.
IN
)
def
distance
():
# set Trigger to HIGH
GPIO
.
output
(
GPIO_TRIGGER
,
True
)
# set Trigger after 0.01ms to LOW
time
.
sleep
(
1
)
GPIO
.
output
(
GPIO_TRIGGER
,
False
)
StartTime
=
time
.
time
()
StopTime
=
time
.
time
()
# save StartTime
while
GPIO
.
input
(
GPIO_ECHO
)
==
0
:
StartTime
=
time
.
time
()
# save time of arrival
while
GPIO
.
input
(
GPIO_ECHO
)
==
1
:
StopTime
=
time
.
time
()
# time difference between start and arrival
TimeElapsed
=
StopTime
-
StartTime
# multiply with the sonic speed (34300 cm/s)
# and divide by 2, because there and back
distance
=
(
TimeElapsed
*
34300
)
/
2
return
distance
if
__name__
==
'__main__'
:
try
:
while
True
:
dateandtime
=
datetime
.
datetime
.
now
()
.
strftime
(
'
%
Y-
%
m-
%
d
%
H:
%
M:
%
S.
%
f'
)
print
(
dateandtime
)
firebase
=
pyrebase
.
initialize_app
(
config
)
storage
=
firebase
.
storage
()
database
=
firebase
.
database
()
dist
=
(
round
(
distance
(),
1
))
print
(
"Water Level:"
,
dist
)
values
=
[
dateandtime
,
dist
]
sheet
.
append_row
(
values
)
print
(
"Firebase water level :"
,
dist
)
database
.
child
(
"River Current Water Level"
)
data
=
{
"key1"
:
dist
}
database
.
set
(
data
)
time
.
sleep
(
1
)
# Reset by pressing CTRL + C
except
KeyboardInterrupt
:
print
(
"Measurement stopped by User"
)
GPIO
.
cleanup
()
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