×

Discussion Board

Results 1 to 7 of 7
  1. #1
    Registered User
    Join Date
    May 2007
    Posts
    12

    Question LightBlue API and Raccoon Python scripting

    I wonder if i can import lightBlue API in web page by using Python for S60 inside the Raccoon web server?

    http://lightblue.sourceforge.net/

    Acturally we try to create a socket connection to connect to another Bluetooth device by RFCOMM virtual serial port.


    The code similar as below:
    To use RFCOMM socket objects:

    # client socket
    >>> s = socket()
    >>> s.connect(("00:12:2c:45:8a:7b", 5))
    >>> s.send("hello")
    5
    >>> s.close()

    # server socket
    >>> s = socket()
    >>> s.bind(("", 0)) # bind to 0 to bind to dynamically assigned port
    >>> s.listen(1)
    >>> advertise("My RFCOMM Service", s, RFCOMM)
    >>> conn, addr = s.accept()
    >>> print "Connected by", addr
    Connected by ('00:0D:93:19:C8:68', 5)
    >>> conn.recv(1024)
    "hello"
    >>> conn.close()
    >>> s.close()




  2. #2
    Nokia Developer Expert
    Join Date
    Mar 2003
    Posts
    457

    Re: LightBlue API and Raccoon Python scripting

    Yes, you should be able to connect to another Bluetooth device from within an Apache request handler. Check how they do it in Raccoon on Map: http://raccoon.openlaboratory.net/Ra.../raccoonloc.py

    Johan

  3. #3
    Registered User
    Join Date
    May 2007
    Posts
    12

    Question Re: LightBlue API and Raccoon Python scripting

    Johan

    Thanks for the fast response!

    I mean , can these python script use in PSP, For instance, Create socket,open connection ... etc ?
    What it is the limitation python script in PSP compare with Python for S60?
    we knew we can NOT "import appuifw" in PSP,right?

    The PSP page would look like below:
    Should this python script work with PSP?
    Must PSP page been placed in .../mod_python/psp folder?

    <html>
    <body>

    # server socket
    <%
    import socket
    import e32
    s = socket()
    s.bind(("", 0)) # bind to 0 to bind to dynamically assigned port
    s.listen(1)
    advertise("My RFCOMM Service", s, RFCOMM)
    conn, addr = s.accept()
    print "Connected by", addr
    Connected by ('00:0D:93:19:C8:68', 5)
    conn.recv(1024)
    "hello"
    conn.close()
    s.close()
    %>

    </body>
    </html>

  4. #4
    Registered User
    Join Date
    May 2007
    Posts
    12

    Question Re: LightBlue API and Raccoon Python scripting

    Please advice how to implement LightBlue API in Raccoon (Apache for S60) web server .
    Should we modify the httpd.conf ?

  5. #5
    Nokia Developer Expert
    Join Date
    Mar 2003
    Posts
    457

    Re: LightBlue API and Raccoon Python scripting

    Quote Originally Posted by bruce2000
    I mean, can these python script use in PSP, For instance, Create socket,open connection ... etc ?
    Yes, you should be able to use socket functions under Apache.
    What it is the limitation python script in PSP compare with Python for S60?
    we knew we can NOT "import appuifw" in PSP,right?
    That's correct, you cannot use appuifw; it's a current limitation of PyS60. See also my other posting in the Camera access restrictions thread.
    The PSP page would look like below:
    Should this python script work with PSP?
    Must PSP page been placed in .../mod_python/psp folder?
    No, you can place it anywhere you like provided you modify httpd.conf. But why not start with having it in that directory and move it to its final location when you know that it otherwise works.
    Code:
    <html>
    <body>
    
    # server socket
    <% 
    import socket
    import e32
    ...
    I can't comment in detail since I don't know anything about the LightBlue API.
    But it seems to me that you intend to create a server socket inside a request handler. That's not likely to be a good idea. Namely, a request handler is supposed to execute fast, and if you create a server socket inside it, it's completely unbounded exactly how long the execution will take. Conceptually that's difficult and will in practice lead to number of problems - for instance, since Raccoon currently is single threaded, it will be completely blocked in that handler while waiting for someone to connect.

    A better approach would be to have a separate server listening for Bluetooth connections and then from within the request handler connect to that server and ask for the data. That is, the request handler would look like:
    Code:
    connect to server
    if succeeded
        ask for data
        print data
    else
        print error message
    endif
    Johan
    Last edited by jhnwkmn; 2007-05-30 at 16:08.

  6. #6
    Registered User
    Join Date
    May 2007
    Posts
    12

    Question Re: LightBlue API and Raccoon Python scripting

    Thanks of lot for the very valueable points!
    I wonder if we can use the own Symbian Bluetooth API for Python S60.(Not LightBlue)
    Insteal of create the socket connections, we may use another way?
    RaccoonMap Apps seems good socket Apps over Raccoon. So it avoids the issue you rise that threads and socket connection awaiting.
    Can we use the similar way (RaccoonMap) to access the device over Bluetooth? Sync or Async?
    And you mentioned that it can set a server to comminucate with it, would you provide more details.

  7. #7
    Nokia Developer Expert
    Join Date
    Mar 2003
    Posts
    457

    Re: LightBlue API and Raccoon Python scripting

    Quote Originally Posted by bruce2000
    ...
    RaccoonMap Apps seems good socket Apps over Raccoon. So it avoids the issue you rise that threads and socket connection awaiting.
    The RaccoonOnMap code is fine, since the script basically assumes that there is a GPS device within Bluetooth range and simply tries to connect to it, read the position and move on. There's no unbounded waiting anywhere - either the connection creation succeeds or it doesn't.

    In the code you posted, the situation was reversed. That is, the script (running under Apache) creates the server socket and waits for someone to connect. If nobody connects, the script waits and blocks until the end of time.

    Can we use the similar way (RaccoonMap) to access the device over Bluetooth? Sync or Async?
    It depends on what your setup is.

    If your case is such that you have a GPS device capable of Bluetooth communication, you have that device in the proximity of your phone, and you want, from within an Apache request handler, to contact that GPS device and read the coordinates and return them in some web page, then yes, absolutely, you can do things the same way as is done in the RaccoonOnMap script.

    And you mentioned that it can set a server to comminucate with it, would you provide more details.
    That was only for the case that you really want to create a server socket on the phone that someone is supposed to connect to. If that's the case, then you really need to do that in a separate application/server, since creating a server socket in a request handler leads to problems.

    Johan

Similar Threads

  1. Replies: 4
    Last Post: 2006-05-04, 09:22

Posting Permissions

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