-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclientHome.py
More file actions
34 lines (24 loc) · 1.59 KB
/
clientHome.py
File metadata and controls
34 lines (24 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/usr/bin/python
#^Indicates which interpreter to use
from time import sleep
from gpiozero import LED, Button, DistanceSensor
import socket # Import socket module
s = socket.socket() # Create a socket object for communication
port = 4 #Reserved a port for communcation.
serverIP = '192.168.1.108' #static local IP I assigned for my Beaglebone that is acting as a server
s.connect((serverIP, port)) #establish connection to socket on server side
led = LED(12) # LED to indicate when script is complete
stopButton = Button(15, pull_up=False) #button to stop script
hcSr = DistanceSensor(echo=13, trigger=7, threshold_distance=0.1) # threshold distance of 0.1m tells the wait_for()'s
# what distance range (.328in) to pause the script at
while !(stopButton.when_pressed):
hcSr.wait_for_out_of_range() #pause script until the change in distance exceeds .328in indicating door is open
c.send('door open') #send packet indicating door is open
time(2) #delay to to allow door motion to finish
hcSr.wait_for_in_range() #pause script until distance is back in range indicating door is closed
c.send('door closed') #send packet indicating door is closed
time(2)
s.close # Close socket when finished
led.on() #temporarily turn LED off to indicate socket communication is done and script is finished
sleep(5)
led.off()