File: simple_client.py

package info (click to toggle)
python-lightblue 0.3.2-5
  • links: PTS, VCS
  • area: main
  • in suites: buster, stretch
  • size: 1,376 kB
  • ctags: 852
  • sloc: objc: 4,009; python: 2,641; ansic: 1,369; cpp: 818; makefile: 2
file content (25 lines) | stat: -rw-r--r-- 754 bytes parent folder | download | duplicates (3)
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
"""
Shows how to send "Hello world" over a RFCOMM client socket.
"""
import lightblue

# ask user to choose the device to connect to
hostaddr = lightblue.selectdevice()[0]        

# find the EchoService advertised by the simple_server.py example
echoservice = lightblue.findservices(addr=hostaddr, name="EchoService")[0]
serviceport = echoservice[1]

s = lightblue.socket()
s.connect((hostaddr, serviceport))
s.send("Hello world!")
print "Sent data, waiting for echo..."
data = s.recv(1024)
print "Got data:", data
s.close()


# Note:
# Instead of calling selectdevice() and findservices(), you could do:
#       hostaddr, serviceport, servicename = lightblue.selectservice()
# to ask the user to choose a service (instead of just choosing the device).