Exemple #1
0
def connect(device_address):
    d = bluetooth.find_service(address=device_address, uuid="1130")
    if not d:
        logging.error('No Phonebook service found.')
        raise Exception('No Phonebook service found.')

    port = d[0]["port"]
    # Use the generic Client class to connect to the phone.
    c = client.Client(device_address, port)
    uuid = b'\x79\x61\x35\xf0\xf0\xc5\x11\xd8\x09\x66\x08\x00\x20\x0c\x9a\x66'
    # result = c.connect(header_list=[headers.Target(uuid)])
    try:
        c.connect(header_list=[headers.Target(uuid)])
        return c
    except:
        logging.error('Failed to connect to phone.')
        raise Exception('Failed to connect to phone.')
Exemple #2
0
def connect(device_address):
    d = bluetooth.find_service(address=device_address, uuid="1134")
    if not d:
        sys.stderr.write("No message access service found.\n")
        sys.exit(1)

    port = d[0]["port"]

    # Use the generic Client class to connect to the phone.
    c = client.Client(device_address, port)
    uuid = b'\xbb\x58\x2b\x40\x42\x0c\x11\xdb\xb0\xde\x08\x00\x20\x0c\x9a\x66'
    result = c.connect(header_list=[headers.Target(uuid)])

    if not isinstance(result, responses.ConnectSuccess):
        sys.stderr.write("Failed to connect to phone.\n")
        sys.exit(1)

    return c
Exemple #3
0
# Released under GPLv3, a full copy of which can be found in COPYING.
#

import bluetooth, os, struct, sys
from nOBEX import client, headers, responses

if __name__ == "__main__":

    if len(sys.argv) != 4:

        sys.stderr.write("Usage: %s <device address> <port> <file name>\n" %
                         sys.argv[0])
        sys.exit(1)

    device_address = sys.argv[1]
    port = int(sys.argv[2])
    file_name = sys.argv[3]

    c = client.Client(device_address, port)
    r = c.connect(
        header_list=())  # header_list=(headers.Target(b"OBEXObjectPush")

    if not isinstance(r, responses.ConnectSuccess):
        sys.stderr.write("Failed to connect.\n")
        sys.exit(1)

    c.put(file_name, open(file_name, 'rb').read())
    c.disconnect()

    sys.exit()
Exemple #4
0
 def loadPhonebook(self):
     device_address=self.getConnectedDevice()
     encoding = locale.getdefaultlocale()[1]
     service = self.findService("Phonebook")
     if service:
         port = find_service("pbap", device_address)
         c = client.Client(device_address, port)
         uuid = b"\x79\x61\x35\xf0\xf0\xc5\x11\xd8\x09\x66\x08\x00\x20\x0c\x9a\x66"
         c.connect(header_list=[headers.Target(uuid)]) 
         prefix = ""
         database="/media/pi/pyCar/Phone/Phonebooks/" + device_address.replace(":", "_") + ".db"
         ### delete database ###
         if os.path.exists(database):
             os.remove(database)
         ### create the database ###
         conn = sqlite3.connect(database)
         cursor = conn.cursor()
         cursor.execute("""CREATE TABLE names (uid text, first_name text, surname text)""")
         cursor.execute("""CREATE TABLE numbers (uid text, number text, type text)""")
         cursor = conn.cursor()
             
             
         
         # Access the list of vcards in the phone's internal phone book.
         hdrs, cards = c.get(prefix+"telecom/pb", header_list=[headers.Type(b"x-bt/vcard-listing")])
         
         # Parse the XML response to the previous request.
         root = ElementTree.fromstring(cards)
         
         
         # Examine each XML element, storing the file names we find in a list, and
         # printing out the file names and their corresponding contact names.
         names = []
         for card in root.findall("card"):
             try:
                 names.append(card.attrib["handle"])
             except:
                 pass
         
         
         # Request all the file names obtained earlier.
         c.setpath(prefix + "telecom/pb")
         
         uid=1
         for name in names:
             hdrs, card = c.get(name, header_list=[headers.Type(b"x-bt/vcard")])
             #print(card)
             parsed=self.parse(card)
             gotNumber=False
             if len(parsed["phone"])>0:
                 for value in parsed["phone"]:
                     try:
                         number=parsed["phone"][value]["number"]
                         cursor.execute("INSERT INTO numbers VALUES ('" + str(uid) +"', '"+ number +"', '"+ parsed["phone"][value]["type"] +"')")
                         conn.commit()
                         if number[:1]=="0":
                             number="+49"+number[1:]
                             cursor.execute("INSERT INTO numbers VALUES ('" + str(uid) +"', '"+ number +"', '"+ parsed["phone"][value]["type"] +"')")
                             conn.commit()
                         gotNumber=True
                     except:
                         pass
                 if(gotNumber):
                     print("INSERT INTO names VALUES ('" + str(uid) +"', '"+ parsed["first_name"] +"', '"+ parsed["surname"] +"')")
                     cursor.execute("INSERT INTO names VALUES ('" + str(uid) +"', '"+ parsed["first_name"] +"', '"+ parsed["surname"] +"')")
                     conn.commit()
                 
                 uid+=1
     
         
         c.disconnect()