Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
Fast Smart Parking
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
Rodion Kraft
Fast Smart Parking
Commits
26e3c223
Unverified
Commit
26e3c223
authored
3 years ago
by
Rodeta
Committed by
GitHub
3 years ago
Browse files
Options
Downloads
Patches
Plain Diff
add end file
parent
ebfef71c
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
big.py
+106
-0
106 additions, 0 deletions
big.py
with
106 additions
and
0 deletions
big.py
0 → 100644
+
106
−
0
View file @
26e3c223
import
RPi.GPIO
as
GPIO
import
os
,
time
import
threading
import
requests
receiver_pin_1
=
18
receiver_pin_2
=
23
lock
=
threading
.
Lock
()
car_count
=
0
def
increase_parking_row_space
(
rowId
):
with
lock
:
request_try
=
0
update_path
=
'
https://192.168.0.94:44378/api/parkingrow/
'
+
str
(
rowId
)
data
=
{
"
increasing
"
:
True
}
patch_request
=
requests
.
patch
(
update_path
,
json
=
data
,
verify
=
False
)
print
(
patch_request
.
status_code
)
if
patch_request
.
status_code
!=
200
:
while
(
patch_request
.
status_code
!=
200
or
request_try
<
3
):
time
.
sleep
(
3
)
patch_request
=
requests
.
patch
(
update_path
,
json
=
data
,
verify
=
False
)
request_try
=
request_try
+
1
else
:
print
(
"
[{}]Space in parking row
"
.
format
(
current_time_ms
())
+
str
(
rowId
)
+
"
succesfully increased
"
)
def
decrease_parking_row_space
(
rowId
):
with
lock
:
request_try
=
0
update_path
=
'
https://192.168.0.94:44378/api/parkingrow/
'
+
str
(
rowId
)
data
=
{
"
increasing
"
:
False
}
patch_request
=
requests
.
patch
(
update_path
,
json
=
data
,
verify
=
False
)
if
patch_request
.
status_code
!=
200
:
while
(
patch_request
.
status_code
!=
200
or
request_try
<
3
):
time
.
sleep
(
3
)
patch_request
=
requests
.
patch
(
update_path
,
json
=
data
,
verify
=
False
)
request_try
=
request_try
+
1
else
:
print
(
"
[{}]Space in parking row
"
.
format
(
current_time_ms
())
+
str
(
rowId
)
+
"
succesfully decreased
"
)
def
current_time_ms
():
return
round
(
time
.
time
()
*
1000
)
# def callback(channel):
# if GPIO.input(channel) == GPIO.LOW:
# # Lichtschranke misst Laser, kein Detection-Event
# callback_connect(channel)
# else:
# # Lichtschranke misst Laser NICHT, Detection-Event
# callback_disconnect(channel)
def
update_car_count
(
channel
):
if
channel
is
receiver_pin_1
:
decrease_parking_row_space
(
1
)
if
channel
is
receiver_pin_2
:
increase_parking_row_space
(
1
)
# def callback_disconnect(channel):
# ldr = -1
# if channel is receiver_pin_1:
# ldr = 1
# # print("Ein KfZ ist auf den Parkplatz aufgefahren.")
# if channel is receiver_pin_2:
# ldr = 2
# # print("Ein KfZ ist von dem Parkplatz abgefahren.")
# print("[{}] Lichtschranke {} wurde unterbrochen".format(current_time_ms(), ldr))
# time.sleep(0.01)
# def callback_connect(channel):
# ldr = -1
# if channel is receiver_pin_1:
# ldr = 1
# if channel is receiver_pin_2:
# ldr = 2
# print("[{}] Lichtschranke {} wurde verbunden".format(current_time_ms(), ldr))
# time.sleep(0.01)
def
main
():
GPIO
.
setmode
(
GPIO
.
BCM
)
GPIO
.
setwarnings
(
False
)
GPIO
.
setup
(
receiver_pin_1
,
GPIO
.
IN
)
GPIO
.
setup
(
receiver_pin_2
,
GPIO
.
IN
)
GPIO
.
add_event_detect
(
receiver_pin_1
,
GPIO
.
RISING
,
callback
=
update_car_count
,
bouncetime
=
200
)
GPIO
.
add_event_detect
(
receiver_pin_2
,
GPIO
.
RISING
,
callback
=
update_car_count
,
bouncetime
=
200
)
try
:
while
True
:
time
.
sleep
(
0.5
)
except
:
# Event wieder entfernen mittels:
GPIO
.
remove_event_detect
(
receiver_pin_1
)
GPIO
.
remove_event_detect
(
receiver_pin_2
)
if
__name__
==
'
__main__
'
:
main
()
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