Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Ege Meriç Erdoğan
rpi_myroom
Commits
a65eddaa
Commit
a65eddaa
authored
5 years ago
by
Ege Meriç Erdoğan
Browse files
Options
Download
Email Patches
Plain Diff
first commit
parent
a7677584
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
README.md
+1
-0
README.md
button.py
+41
-0
button.py
php/relay/off.php
+7
-0
php/relay/off.php
php/relay/on.php
+5
-0
php/relay/on.php
server.py
+28
-0
server.py
with
82 additions
and
0 deletions
+82
-0
README.md
View file @
a65eddaa
# rpi_myroom
my first socket app in python it locks my gnome desktop and turn off my room lights when i press the button with raspberry pis
This diff is collapsed.
Click to expand it.
button.py
0 → 100755
View file @
a65eddaa
#! /usr/bin/env python3
import
time
import
requests
import
RPi.GPIO
as
GPIO
import
socket
def
get_call
(
url
):
headers
=
{
'User-Agent'
:
'Mozilla/5.0 (Linux python) AppleWebKit/537.36 (KHTML, like Gecko)'
'Chrome/41.0.2227.1 Safari/537.36'
}
response
=
requests
.
get
(
url
,
headers
=
headers
)
print
(
"Ok"
)
def
get_lock
():
s
=
socket
.
socket
()
s
.
connect
((
'10.1.1.2'
,
12345
))
str
=
"bye"
s
.
send
(
str
.
encode
());
res
=
s
.
recv
(
5
)
print
(
res
)
s
.
close
()
GPIO
.
setwarnings
(
False
)
GPIO
.
setmode
(
GPIO
.
BOARD
)
GPIO
.
setup
(
12
,
GPIO
.
IN
,
pull_up_down
=
GPIO
.
PUD_DOWN
)
URL
=
"http://10.1.1.10:8080/relay/off.php"
URL2
=
"http://10.1.1.10:8080/relay/on.php"
while
True
:
if
GPIO
.
input
(
12
)
==
GPIO
.
HIGH
:
get_call
(
URL
)
(
URL
,
URL2
)
=
(
URL2
,
URL
)
time
.
sleep
(
2
)
if
URL2
==
"http://10.1.1.10:8080/relay/off.php"
:
st
=
1
#statement control
if
st
==
1
:
st
=
0
if
st
==
0
:
try
:
get_lock
()
except
:
continue
time
.
sleep
(
0.01
)
This diff is collapsed.
Click to expand it.
php/relay/off.php
0 → 100644
View file @
a65eddaa
<?php
system
(
"gpio mode 7 out"
);
system
(
"gpio write 7 1"
);
?>
This diff is collapsed.
Click to expand it.
php/relay/on.php
0 → 100644
View file @
a65eddaa
<?php
system
(
"gpio mode 7 out"
);
system
(
"gpio write 7 0"
);
?>
This diff is collapsed.
Click to expand it.
server.py
0 → 100755
View file @
a65eddaa
#!/usr/bin/python3
import
socket
import
os
while
True
:
s
=
socket
.
socket
()
s
.
setsockopt
(
socket
.
SOL_SOCKET
,
socket
.
SO_REUSEADDR
,
1
)
port
=
12345
s
.
bind
((
'0.0.0.0'
,
port
))
s
.
listen
(
5
)
c
,
addr
=
s
.
accept
()
print
(
"success:"
,
addr
)
while
True
:
rcvdData
=
c
.
recv
(
5
).
decode
()
chack
=
rcvdData
if
(
chack
[
0
:
3
]
==
"BYE"
or
chack
[
0
:
3
]
==
"bye"
):
#secret code :D
os
.
system
(
'dbus-send --type=method_call --dest=org.gnome.ScreenSaver /org/gnome/ScreenSaver org.gnome.ScreenSaver.Lock'
)
#lock gnome
response
=
'ok'
c
.
send
(
response
.
encode
())
c
.
close
()
break
else
:
c
.
close
()
print
(
"closed"
)
break
This diff is collapsed.
Click to expand it.
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
Menu
Projects
Groups
Snippets
Help