-
Notifications
You must be signed in to change notification settings - Fork 0
/
robo_pi.py
executable file
·60 lines (44 loc) · 1.47 KB
/
robo_pi.py
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
"""
This python script will receive the data sent
from Android "Bluetooth Pi3 Terminal" app.
To run the program just open a terminal and type
sudo python btpi3_receiver.py
Then go to your Android app, connect to your Pi3
To get your Pi3 MAC Address, go to terminal and type
hciconfig
And any character you type will be send to the Pi3 via Bluetooth
If you send letter e, this will end the script.
Note you need to install Blue on your Pi3, it should be installed by
default.
Rgds
Marco
"""
import bluetooth
print "Bluetooth Terminal with Voice"
print "Follow instructions on app to connect"
print "Waiting for connection..."
server_sock=bluetooth.BluetoothSocket( bluetooth.RFCOMM )
port=bluetooth.PORT_ANY
server_sock.bind(("",port))
server_sock.listen(1)
""" Robot input and answer definition """
def reply_hello(): client_sock.send("Hi, welcome!!")
def reply_bye(): client_sock.send("Bye, see you soon ;-)")
def errhandler(): client_sock.send("Your input has not been recognized")
takeaction = {
"hello": reply_hello,
"bye": reply_bye}
client_sock,address = server_sock.accept()
print "Accepted connection from",address
while True:
data = client_sock.recv(1024)
print "received: %s" % data
client_sock.send(data)
if (data == "exit"):
client_sock.send("Stopped by android app")
print ("Exit")
break
else:
takeaction.get(data,errhandler)()
client_sock.close()
server_sock.close()