×

Discussion Board

Results 1 to 2 of 2
  1. #1
    Registered User
    Join Date
    Dec 2010
    Posts
    7

    Python script error, please help.

    Hi,
    I'm attempting to run a program on a Nokia N97 using python that will connect to a micro controller board through Bluetooth and switch an LED on/off. The code is directly copied from an example in the book Mobile Python: Rapid Prototyping of Applications on the Mobile Platform so should, in theory, work.
    It is as follows:

    import socket, e32, appuifw

    def choose_service(services):
    names = []
    channels = []
    for name, channel in services.items():
    names.append(name)
    channels.append(channel)
    index = appuifw.popup_menu(names, u"Choose service")
    return channels[index]

    def connect():
    global sock
    address, services =socket.bt_discover()
    channel = choose_service(services)
    sock = socket.socket(socket.AF_BT, socket.SOCK_STREAM)
    sock.connect((address, channel))

    def receive():
    global sock
    data = sock.recv(1)
    if data == "1":
    appuifw.note(u"LED on ", "info")
    elif data == "0":
    appuifw.note(u"LED off ", "info")

    def bt_send_data1():
    global sock
    sock.send("1")
    receive()

    def bt_send_data2():
    global sock
    sock.send("0")
    receive()

    def exit_key_handler():
    print "socket closed"
    sock.close()
    app_lock.signal()

    app_lock = e32.Ao_lock()

    appuifw.app.menu = [(u"LED on", bt_send_data1),
    (u"LED off", bt_send_data2),
    (u"Connect", connect)]

    appuifw.app.exit_key_handler = exit_key_handler
    app_lock.wait()

    The error I am getting on the phone when I attempt to select connect is "Traceback (most recent call last): File "e:\python\example119.py", line 14, in connect address, services =socket.bt_discover() AttributeError: 'module' object has no attribute 'bt_discover'.

    I'm really struggling to see what I'm doing wrong here and any help from a more experienced user of python would be greatly appreciated, thanks

  2. #2
    Nokia Developer Moderator
    Join Date
    Oct 2007
    Location
    Deva, Romania
    Posts
    3,471

    Re: Python script error, please help.

    Hi,

    Are you using PyS60 2.0? If so, you need to use the btsocket module; that one has bt_discover. The book was written around the time of PyS60 1.4.5; there, the socket module does indeed have the bt_discover function.

Similar Threads

  1. Action Script / Flash help please?
    By girlbunny in forum General Development Questions
    Replies: 5
    Last Post: 2009-06-03, 12:50
  2. Can a Python script call a Perl script?
    By xhsoldier in forum Symbian
    Replies: 1
    Last Post: 2009-02-11, 10:04
  3. Python Script Installation Help
    By shamilton4 in forum Symbian
    Replies: 9
    Last Post: 2008-07-29, 10:27
  4. help me write a python script
    By psychologe in forum Symbian
    Replies: 10
    Last Post: 2008-01-17, 11:12
  5. Replies: 3
    Last Post: 2007-05-30, 13:04

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •