bluetooth
index
/home/epx/python-sdk/pybluez/pybluez/build/lib.linux-i686-2.4/bluetooth.py

bluetooth module

 
Modules
       
_bluetooth
array
_bluetooth
fcntl
struct

 
Classes
       
BluetoothSocket
DeviceDiscoverer
exceptions.IOError(exceptions.EnvironmentError)
BluetoothError

 
class BluetoothError(exceptions.IOError)
    
Method resolution order:
BluetoothError
exceptions.IOError
exceptions.EnvironmentError
exceptions.StandardError
exceptions.Exception

Methods inherited from exceptions.EnvironmentError:
__init__(...)
__str__(...)

Methods inherited from exceptions.Exception:
__getitem__(...)

 
class BluetoothSocket
    BluetoothSocket(proto=RFCOMM) -> bluetooth socket object
 
Open a socket of the given protocol.  proto must be one of
HCI, L2CAP, RFCOMM, or SCO.  SCO sockets have
not been tested at all yet.
 
BluetoothSocket object represents one endpoint of a bluetooth connection.
 
Methods of BluetoothSocket objects (keyword arguments not allowed):
 
accept() -- accept a connection, returning new socket and client address
bind(addr) -- bind the socket to a local address
close() -- close the socket
connect(addr) -- connect the socket to a remote address
connect_ex(addr) -- connect, return an error code instead of an exception
dup() -- return a new socket object identical to the current one
fileno() -- return underlying file descriptor
getpeername() -- return remote address
getsockname() -- return local address
getsockopt(level, optname[, buflen]) -- get socket options
gettimeout() -- return timeout or None
listen(n) -- start listening for incoming connections
makefile([mode, [bufsize]]) -- return a file object for the socket
recv(buflen[, flags]) -- receive data
recvfrom(buflen[, flags]) -- receive data and sender's address
sendall(data[, flags]) -- send all data
send(data[, flags]) -- send data, may not send all of it
sendto(data[, flags], addr) -- send data to a given address
setblocking(0 | 1) -- set or clear the blocking I/O flag
setsockopt(level, optname, value) -- set socket options
settimeout(None | float) -- set or clear the timeout
shutdown(how) -- shut down traffic in one or both directions
 
  Methods defined here:
__init__(self, proto=3, _sock=None)
accept(self)
accept() -> (socket object, address info)
 
Wait for an incoming connection.  Return a new socket representing the
connection, and the address of the client.  For L2CAP sockets, the address
is a (host, psm) tuple.  For RFCOMM sockets, the address is a (host, channel)
tuple.  For SCO sockets, the address is just a host.
bind(self, *args, **kwargs)
bind(address)
 
Bind the socket to a local address.  address must always be a tuple.
  HCI sockets:    ( device number, )
                  device number should be 0, 1, 2, etc.
  L2CAP sockets:  ( host, psm )
                  host should be an address e.g. "01:23:45:67:89:ab"
                  psm should be an unsigned integer
  RFCOMM sockets: ( host, channel )
  SCO sockets:    ( host )
close(self, *args, **kwargs)
close()
 
Close the socket.  It cannot be used after this call.
connect(self, *args, **kwargs)
connect(address)
 
Connect the socket to a remote address. For L2CAP sockets, the address is a 
(host,psm) tuple.  For RFCOMM sockets, the address is a (host,channel) tuple.
For SCO sockets, the address is just the host.
connect_ex(self, *args, **kwargs)
connect_ex(address) -> errno
 
This is like connect(address), but returns an error code (the errno value)
instead of raising an exception when an error occurs.
dup(self, *args, **kwargs)
dup() -> socket object
 
Return a new socket object connected to the same system resource.
fileno(self, *args, **kwargs)
fileno() -> integer
 
Return the integer file descriptor of the socket.
getpeername(self, *args, **kwargs)
getpeername() -> address info
 
Return the address of the remote endpoint.  For HCI sockets, the address is a
device number (0, 1, 2, etc).  For L2CAP sockets, the address is a 
(host,psm) tuple.  For RFCOMM sockets, the address is a (host,channel) tuple.
For SCO sockets, the address is just the host.
getsockname(self, *args, **kwargs)
getsockname() -> address info
 
Return the address of the local endpoint.
getsockopt(self, *args, **kwargs)
getsockopt(level, option[, buffersize]) -> value
 
Get a socket option.  See the Unix manual for level and option.
If a nonzero buffersize argument is given, the return value is a
string of that length; otherwise it is an integer.
gettimeout(self, *args, **kwargs)
gettimeout() -> timeout
 
Returns the timeout in floating seconds associated with socket 
operations. A timeout of None indicates that timeouts on socket 
operations are disabled.
listen(self, *args, **kwargs)
listen(backlog)
 
Enable a server to accept connections.  The backlog argument must be at
least 1; it specifies the number of unaccepted connection that the system
will allow before refusing new connections.
makefile(self, *args, **kwargs)
makefile([mode[, buffersize]]) -> file object
 
Return a regular file object corresponding to the socket.
The mode and buffersize arguments are as for the built-in open() function.
recv(self, *args, **kwargs)
recv(buffersize[, flags]) -> data
 
Receive up to buffersize bytes from the socket.  For the optional flags
argument, see the Unix manual.  When no data is available, block until
at least one byte is available or until the remote end is closed.  When
the remote end is closed and all data is read, return the empty string.
recvfrom(self, *args, **kwargs)
recvfrom(buffersize[, flags]) -> (data, address info)
 
Like recv(buffersize, flags) but also return the sender's address info.
send(self, *args, **kwargs)
send(data[, flags]) -> count
 
Send a data string to the socket.  For the optional flags
argument, see the Unix manual.  Return the number of bytes
sent; this may be less than len(data) if the network is busy.
sendall(self, *args, **kwargs)
sendall(data[, flags])
 
Send a data string to the socket.  For the optional flags
argument, see the Unix manual.  This calls send() repeatedly
until all data is sent.  If an error occurs, it's impossible
to tell how much data has been sent.
sendto(self, *args, **kwargs)
sendto(data[, flags], address) -> count
 
Like send(data, flags) but allows specifying the destination address.
For IP sockets, the address is a pair (hostaddr, port).
setblocking(self, *args, **kwargs)
setblocking(flag)
 
Set the socket to blocking (flag is true) or non-blocking (false).
setblocking(True) is equivalent to settimeout(None);
setblocking(False) is equivalent to settimeout(0.0).
setsockopt(self, *args, **kwargs)
setsockopt(level, option, value)
 
Set a socket option.  See the Unix manual for level and option.
The value argument can either be an integer or a string.
settimeout(self, *args, **kwargs)
settimeout(timeout)
 
Set a timeout on socket operations.  'timeout' can be a float,
giving in seconds, or None.  Setting a timeout of None disables
the timeout feature and is equivalent to setblocking(1).
Setting a timeout of zero is the same as setblocking(0).
shutdown(self, *args, **kwargs)
shutdown(flag)
 
Shut down the reading side of the socket (flag == 0), the writing side
of the socket (flag == 1), or both ends (flag == 2).

 
class DeviceDiscoverer
    Skeleton class for finer control of the device discovery process.
 
To implement asynchronous device discovery (e.g. if you want to do 
something *as soon as* a device is discovered), subclass DeviceDiscoverer
and override device_discovered() and inquiry_complete()
 
  Methods defined here:
__init__(self)
cancel_inquiry(self)
Call this method to cancel an inquiry in process.  inquiry_complete 
will still be called.
device_discovered(self, address, device_class, name)
Called when a bluetooth device is discovered.
 
address is the bluetooth address of the device
 
device_class is the Class of Device, as specified in [1]
             passed in as a 3-byte string
 
name is the user-friendly name of the device if lookup_names was set
     when the inquiry was started.  otherwise None
 
This method exists to be overriden.
 
[1] https://www.bluetooth.org/foundry/assignnumb/document/baseband
fileno(self)
find_devices(self, lookup_names=True, duration=8, flush_cache=True)
start_inquiry( lookup_names=True, service_name=None, 
               duration=8, flush_cache=True )
 
Call this method to initiate the device discovery process
 
lookup_names - set to True if you want to lookup the user-friendly 
               names for each device found.
 
service_name - set to the name of a service you're looking for.
               only devices with a service of this name will be 
               returned in device_discovered() NOT YET IMPLEMENTED
 
 
ADVANCED PARAMETERS:  (don't change these unless you know what 
                    you're doing)
 
duration - the number of 1.2 second units to spend searching for
           bluetooth devices.  If lookup_names is True, then the 
           inquiry process can take a lot longer.
 
flush_cache - return devices discovered in previous inquiries
inquiry_complete(self)
Called when an inquiry started by start_inquiry has completed.
pre_inquiry(self)
Called just after start_inquiry is invoked, but just before the inquiry
is started.
 
This method exists to be overriden
process_event(self)
Waits for one event to happen, and proceses it.  The event will be
either a device discovery, or an inquiry completion.
process_inquiry(self)
Repeatedly calls process_event() until the device inquiry has 
completed.

 
Functions
       
advertise_service(sock, name, service_id='', service_classes=[], profiles=[], provider='', description='')
Advertises a service with the local SDP server.  sock must be a bound,
listening socket.  name should be the name of the service, and service_id 
(if specified) should be a string of the form 
"XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXX", where each 'X' is a hexadecimal digit.
 
service_classes is a list of service classes whose this service belongs to.
Each class service is a 16-bit UUID in the form "XXXX", where each 'X' is a
hexadecimal digit, or a 128-bit UUID in the form
"XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX". There are some constants for
standard services, e.g. SERIAL_PORT_CLASS that equals to "1101". Some class
constants:
 
SERIAL_PORT_CLASS        LAN_ACCESS_CLASS         DIALUP_NET_CLASS 
HEADSET_CLASS            CORDLESS_TELEPHONY_CLASS AUDIO_SOURCE_CLASS
AUDIO_SINK_CLASS         PANU_CLASS               NAP_CLASS
GN_CLASS
 
profiles is a list of service profiles that thie service fulfills. Each
profile is a tuple with ( uuid, version ). Most standard profiles use
standard classes as UUIDs. PyBluez offers a list of standard profiles,
for example SERIAL_PORT_PROFILE. All standard profiles have the same
name as the classes, except that _CLASS suffix is replaced by _PROFILE.
 
provider is a text string specifying the provider of the service
 
description is a text string describing the service
 
A note on working with Symbian smartphones:
    bt_discover in Python for Series 60 will only detect service records
    with service class SERIAL_PORT_CLASS and profile SERIAL_PORT_PROFILE
discover_devices(duration=8, flush_cache=True)
performs a bluetooth device discovery using the first available bluetooth
resource.
 
returns a list of bluetooth addresses.
 
duration=8 
    how long, in units of 1.28 seconds, to search for devices.  To find as
    many devices as possible, you should set this to at least 8.
flush_cache=True 
    if set to False, then discover_devices may return devices found during
    previous discoveries.
find_service(name=None, uuid=None, address=None)
find_service( name = None, uuid = None, address = None )
 
Searches for SDP services that match the specified criteria and returns
the search results.  If no criteria are specified, then returns a list of
all nearby services detected.  If more than one is specified, then
the search results will match all the criteria specified.  If uuid is
specified, it must be either a 16-bit UUID in the form "XXXX", where each
'X' is a hexadecimal digit, or as a 128-bit UUID in the form
"XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX".  A special case of address is
"localhost", which will search for services on the local machine.
 
The search results will be a list of dictionaries.  Each dictionary
represents a search match and will have the following key/value pairs:
 
  host          - the bluetooth address of the device advertising the
                  service
  name          - the name of the service being advertised
  description   - a description of the service being advertised
  provider      - the name of the person/organization providing the service
  protocol      - either 'RFCOMM', 'L2CAP', None if the protocol was not
                  specified, or 'UNKNOWN' if the protocol was specified but
                  unrecognized
  port          - the L2CAP PSM # if the protocol is 'L2CAP', the RFCOMM
                  channel # if the protocol is 'RFCOMM', or None if it
                  wasn't specified
  service-classes - a list of service class IDs (UUID strings).  possibly
                    empty
  profiles        - a list of profiles - (UUID, version) pairs - the
                    service claims to support.  possibly empty.
  service-id      - the Service ID of the service.  None if it wasn't set
                    See the Bluetooth spec for the difference between
                    Service ID and Service Class ID List
get_available_port(protocol)
finds and returns an available port for the specified protocol.  protocol 
must be either L2CAP or RFCOMM, and None if no available port is found.
 
It is possible that somebody will bind to the returned port in between the
time it is returned and the time you use it, so be careful.
 
This is a major hack.  In Linux kernel versions 2.6.7 and higher, you can
use PSM/channel 0 when binding a socket to be dynamically assigned a port
number (e.g.  sock.bind(("",0)) )
is_valid_address(address)
returns True if address is a valid bluetooth address
 
valid address are always strings of the form XX:XX:XX:XX:XX:XX
where X is a hexadecimal character.  For example,
    01:23:45:67:89:AB is a valid address, but
    IN:VA:LI:DA:DD:RE is not
is_valid_uuid(uuid)
is_valid_uuid(uuid) -> bool
 
returns True if uuid is a valid UUID.
 
valid UUIDs are always strings taking one of the following forms:
    XXXX
    XXXXXXXX
    XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
where each X is a hexadecimal digit (case insensitive)
lookup_name(address, timeout=10)
Tries to determine the friendly name (human readable) of the device with
the specified bluetooth address.  Returns the name on success, and None
on failure.
 
timeout=10   how many seconds to search before giving up.
set_l2cap_mtu(sock, mtu)
set_l2cap_mtu( sock, mtu )
 
Adjusts the MTU for the specified L2CAP socket.  This method needs to be
invoked on both sides of the connection for it to work!  The default mtu
that all L2CAP connections start with is 672 bytes.
 
mtu must be between 48 and 65535, inclusive.
set_packet_timeout(address, timeout)
Adjusts the ACL flush timeout for the ACL connection to the specified
device.  This means that all L2CAP and RFCOMM data being sent to that
device will be dropped if not acknowledged in timeout milliseconds (maximum
1280).  A timeout of 0 means to never drop packets.
 
Since this affects all Bluetooth connections to that device, and not just
those initiated by this process or PyBluez, a call to this method requires
superuser privileges.
 
You must have an active connection to the specified device before invoking
this method
stop_advertising(sock)
Instructs the local SDP server to stop advertising the service associated
with sock.  You should typically call this right before you close sock.

 
Data
        ADVANCED_AUDIO_CLASS = '110d'
ADVANCED_AUDIO_PROFILE = ('110d', 256)
AUDIO_SINK_CLASS = '110b'
AUDIO_SINK_PROFILE = ('110b', 256)
AUDIO_SOURCE_CLASS = '110a'
AUDIO_SOURCE_PROFILE = ('110a', 256)
AV_CLASS = '112c'
AV_PROFILE = ('112c', 256)
AV_REMOTE_CLASS = '110e'
AV_REMOTE_PROFILE = ('110e', 256)
AV_REMOTE_TARGET_CLASS = '110c'
AV_REMOTE_TARGET_PROFILE = ('110c', 256)
BASIC_PRINTING_CLASS = '1122'
BASIC_PRINTING_PROFILE = ('1122', 256)
BROWSE_GRP_DESC_CLASS = '1001'
BROWSE_GRP_DESC_PROFILE = ('1001', 256)
CIP_CLASS = '1128'
CIP_PROFILE = ('1128', 256)
CORDLESS_TELEPHONY_CLASS = '1109'
CORDLESS_TELEPHONY_PROFILE = ('1109', 256)
DIALUP_NET_CLASS = '1103'
DIALUP_NET_PROFILE = ('1103', 256)
DIRECT_PRINTING_CLASS = '1118'
DIRECT_PRINTING_PROFILE = ('1118', 256)
DIRECT_PRT_REFOBJS_CLASS = '1120'
DIRECT_PRT_REFOBJS_PROFILE = ('1120', 256)
FAX_CLASS = '1111'
FAX_PROFILE = ('1111', 256)
GENERIC_AUDIO_CLASS = '1203'
GENERIC_AUDIO_PROFILE = ('1203', 256)
GENERIC_FILETRANS_CLASS = '1202'
GENERIC_FILETRANS_PROFILE = ('1202', 256)
GENERIC_NETWORKING_CLASS = '1201'
GENERIC_NETWORKING_PROFILE = ('1201', 256)
GENERIC_TELEPHONY_CLASS = '1204'
GENERIC_TELEPHONY_PROFILE = ('1204', 256)
GN_CLASS = '1117'
GN_PROFILE = ('1117', 256)
HANDSFREE_AGW_CLASS = '111f'
HANDSFREE_AGW_PROFILE = ('111f', 256)
HANDSFREE_CLASS = '111e'
HANDSFREE_PROFILE = ('111e', 256)
HCI = 1
HCR_CLASS = '1125'
HCR_PRINT_CLASS = '1126'
HCR_PRINT_PROFILE = ('1126', 256)
HCR_PROFILE = ('1127', 256)
HCR_SCAN_CLASS = '1127'
HCR_SCAN_PROFILE = ('1127', 256)
HEADSET_AGW_CLASS = '1112'
HEADSET_AGW_PROFILE = ('1112', 256)
HEADSET_CLASS = '1108'
HEADSET_PROFILE = ('1108', 256)
HID_CLASS = '1124'
HID_PROFILE = ('1124', 256)
IMAGING_ARCHIVE_CLASS = '111c'
IMAGING_ARCHIVE_PROFILE = ('111c', 256)
IMAGING_CLASS = '111a'
IMAGING_PROFILE = ('111a', 256)
IMAGING_REFOBJS_CLASS = '111d'
IMAGING_REFOBJS_PROFILE = ('111d', 256)
IMAGING_RESPONDER_CLASS = '111b'
IMAGING_RESPONDER_PROFILE = ('111b', 256)
INTERCOM_CLASS = '1110'
INTERCOM_PROFILE = ('1110', 256)
IRMC_SYNC_CLASS = '1104'
IRMC_SYNC_CMD_CLASS = '1107'
IRMC_SYNC_CMD_PROFILE = ('1107', 256)
IRMC_SYNC_PROFILE = ('1104', 256)
L2CAP = 0
L2CAP_OPTIONS = 1
LAN_ACCESS_CLASS = '1102'
LAN_ACCESS_PROFILE = ('1102', 256)
NAP_CLASS = '1116'
NAP_PROFILE = ('1116', 256)
OBEX_FILETRANS_CLASS = '1106'
OBEX_FILETRANS_PROFILE = ('1106', 256)
OBEX_OBJPUSH_CLASS = '1105'
OBEX_OBJPUSH_PROFILE = ('1105', 256)
PANU_CLASS = '1115'
PANU_PROFILE = ('1115', 256)
PNP_INFO_CLASS = '1200'
PNP_INFO_PROFILE = ('1200', 256)
PRINTING_STATUS_CLASS = '1123'
PRINTING_STATUS_PROFILE = ('1123', 256)
PUBLIC_BROWSE_GROUP = '1002'
REFERENCE_PRINTING_CLASS = '1119'
REFERENCE_PRINTING_PROFILE = ('1119', 256)
REFLECTED_UI_CLASS = '1121'
REFLECTED_UI_PROFILE = ('1121', 256)
RFCOMM = 3
SAP_CLASS = '112d'
SAP_PROFILE = ('112d', 256)
SCO = 2
SDP_SERVER_CLASS = '1000'
SDP_SERVER_PROFILE = ('1000', 256)
SERIAL_PORT_CLASS = '1101'
SERIAL_PORT_PROFILE = ('1101', 256)
SOL_L2CAP = 6
SOL_RFCOMM = 18
UDI_MT_CLASS = '112a'
UDI_MT_PROFILE = ('112a', 256)
UDI_TA_CLASS = '112b'
UDI_TA_PROFILE = ('112b', 256)
UPNP_CLASS = '1205'
UPNP_IP_CLASS = '1206'
UPNP_IP_PROFILE = ('1206', 256)
UPNP_L2CAP_CLASS = '1302'
UPNP_L2CAP_PROFILE = ('1302', 256)
UPNP_LAP_CLASS = '1301'
UPNP_LAP_PROFILE = ('1301', 256)
UPNP_PAN_CLASS = '1300'
UPNP_PAN_PROFILE = ('1300', 256)
UPNP_PROFILE = ('1205', 256)
VIDEO_CONF_CLASS = '110f'
VIDEO_CONF_GW_CLASS = '1129'
VIDEO_CONF_GW_PROFILE = ('1129', 256)
VIDEO_CONF_PROFILE = ('110f', 256)
VIDEO_SINK_CLASS = '1304'
VIDEO_SINK_PROFILE = ('1304', 256)
VIDEO_SOURCE_CLASS = '1303'
VIDEO_SOURCE_PROFILE = ('1303', 256)
WAP_CLASS = '1113'
WAP_CLIENT_CLASS = '1114'
WAP_CLIENT_PROFILE = ('1114', 256)
WAP_PROFILE = ('1113', 256)