Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
IoT Hackathon SS2021
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Andreas Kohler
IoT Hackathon SS2021
Commits
3514925a
Commit
3514925a
authored
3 years ago
by
Patrick Mohr
Browse files
Options
Downloads
Patches
Plain Diff
Upload New File
parent
9ebec0f9
No related branches found
No related tags found
1 merge request
!1
Upload Dozentenansicht
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
pro_view.py
+99
-0
99 additions, 0 deletions
pro_view.py
with
99 additions
and
0 deletions
pro_view.py
0 → 100644
+
99
−
0
View file @
3514925a
# Bibliotheken einbinden
import
RPi.GPIO
as
GPIO
import
time
import
math
import
gspread
from
oauth2client.service_account
import
ServiceAccountCredentials
import
requests
# Link zum GoogleSheet https://docs.google.com/spreadsheets/d/11N64tz0XctBRAJk4C9Pd4yC_J9pENiLCzZknrnzW1Hg/edit#gid=0
# Webhooks
data
=
'
https://maker.ifttt.com/trigger/dozent_clear/with/key/bhN1Omd1FWPjHsC3_akFzq
'
#Zweiter Webhook
# Autorisierung der Google Drive API
scope
=
[
'
https://www.googleapis.com/auth/drive
'
,
'
https://www.googleapis.com/auth/drive.file
'
]
file_name
=
'
iothackathon-423543aa9b7f.json
'
creds
=
ServiceAccountCredentials
.
from_json_keyfile_name
(
file_name
,
scope
)
client
=
gspread
.
authorize
(
creds
)
# GPIO Modus (BOARD / BCM)
GPIO
.
setmode
(
GPIO
.
BCM
)
# GPIO Pins zuweisen
GPIO_TRIGGER
=
23
GPIO_ECHO
=
24
OLD_STATUS
=
0
DISTANCE_THRESHOLD
=
80
# Richtung der GPIO-Pins festlegen (IN / OUT)
GPIO
.
setup
(
GPIO_TRIGGER
,
GPIO
.
OUT
)
GPIO
.
setup
(
GPIO_ECHO
,
GPIO
.
IN
)
# Messung der Distanz zur Ermittlung ob der Dozent vor dem Dashboard sitzt.
def
distanz
():
# setze Trigger nach 0.01ms auf LOW
GPIO
.
output
(
GPIO_TRIGGER
,
True
)
time
.
sleep
(
0.00001
)
GPIO
.
output
(
GPIO_TRIGGER
,
False
)
StartZeit
=
time
.
time
()
StopZeit
=
time
.
time
()
# speichere Startzeit
while
GPIO
.
input
(
GPIO_ECHO
)
==
0
:
StartZeit
=
time
.
time
()
# speichere Ankunftszeit
while
GPIO
.
input
(
GPIO_ECHO
)
==
1
:
StopZeit
=
time
.
time
()
# Zeit Differenz zwischen Start und Ankunft
TimeElapsed
=
StopZeit
-
StartZeit
# mit der Schallgeschwindigkeit (34300 cm/s) multiplizieren
# und durch 2 teilen, da hin und zurueck
distanz_n
=
(
TimeElapsed
*
34300
)
/
2
return
distanz_n
# Methode zur Erkennung und zum Loesen der gelesenen Eintraege im Google Sheet
def
mark_as_seen
():
list_of_cells
=
[]
sheet
=
client
.
open
(
'
Fragenuebersicht
'
).
sheet1
list_of_cells
=
sheet
.
findall
(
'
Ungelesen
'
)
len
(
list_of_cells
)
for
cell
in
list_of_cells
:
cell
.
value
=
'
Gelesen
'
sheet
.
update_cells
(
list_of_cells
)
# Main Methode, die bis zum Abbruch dauerhaft ausgefuehrt wird
if
__name__
==
'
__main__
'
:
try
:
while
True
:
neueDistanz
=
distanz
()
#mark_as_seen()
#time.sleep(500)
if
math
.
fabs
((
neueDistanz
-
OLD_STATUS
))
>=
DISTANCE_THRESHOLD
:
OLD_STATUS
=
neueDistanz
if
neueDistanz
>=
50
:
iso_time
=
time
.
strftime
(
"
%Y-%m-%d-T%H:%M:%S
"
)
else
:
iso_time
=
time
.
strftime
(
"
%Y-%m-%d-T%H:%M:%S
"
)
print
(
"
Dozent erkannt
"
)
webhook_dozent
=
requests
.
post
(
data
)
try
:
mark_as_seen
()
except
:
time
.
sleep
(
2
)
time
.
sleep
(
20
)
# Beim Abbruch durch STRG+C resetten
except
KeyboardInterrupt
:
print
(
"
Messung vom User gestoppt
"
)
GPIO
.
cleanup
()
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment