python\bluetooth / wsgi / apache 2.2

Discussion in 'Python' started by Barry Dick, Dec 13, 2012.

  1. Barry Dick

    Barry Dick Guest

    I'm wanting to read from my bluetooth device (it just sends data/header with a checksum at the end, in a continuous mode "a biofeedback device") and I'm getting a weird error in my logs not allowing me to use multiple sockets.. I guess with wsgi, I'm creating a link/module between the two apis (apache / python), and then lets apache manage the socket / port communication onthe application layer. How ever, I'm not able to connect to my device. Is there something simple I'm missing? The test code is the following

    #!/usr/bin/python

    # Written by Yevgeniy Medynskiy ()
    # Date modified: December 2006
    #
    # No copyright. No warranty. Distributed as-is.
    #
    # http://www.gvu.gatech.edu/ccg/resources/wearableRFID.html

    import time
    import bluetooth
    import sys

    class MyWriter:

    def __init__(self, stdout, filename):
    #self.stdout = stdout
    self.logfile = file(filename, 'a')

    def write(self, text):
    #self.stdout.write(text)
    self.logfile.write(text)

    def close(self):
    #self.stdout.close()
    self.logfile.close()

    writer = MyWriter(sys.stdout, 'logging.txt')
    sys.stdout = writer

    #
    ## Change to your device's Bluetooth address
    #
    device = "10:00:E8:AC:4D:D0"

    port = 1

    #
    ## Read command and request for acknowledgement.
    #

    socket = bluetooth.BluetoothSocket(bluetooth.RFCOMM)

    #print "Attempting to connect to " + device + ":" + str(port) + "...",
    socket.connect((device, port))
    #print "done."

    #print "Receiving data..."


    data = ""
    try:
    while True:
    try:
    data = socket.recv(255)
    except bluetooth.BluetoothError, b:
    print "Bluetooth Error: ", b

    if len(data) > 0: print data

    except KeyboardInterrupt:
    #print "Closing socket...",
    socket.close()
    #print "done."

    [Wed Dec 12 17:00:31 2012] [error] [client 127.0.0.1] mod_wsgi (pid=2780): Target WSGI script 'C:/Project/index.py' cannot be loaded as Python module.
    [Wed Dec 12 17:00:31 2012] [error] [client 127.0.0.1] mod_wsgi (pid=2780): Exception occurred processing WSGI script 'C:/Project/index.py'.
    [Wed Dec 12 17:00:31 2012] [error] [client 127.0.0.1] Traceback (most recent call last):
    [Wed Dec 12 17:00:31 2012] [error] [client 127.0.0.1] File "C:/Project/index.py", line 45, in <module>
    [Wed Dec 12 17:00:31 2012] [error] [client 127.0.0.1] socket.connect((device, port))
    [Wed Dec 12 17:00:31 2012] [error] [client 127.0.0.1] File "C:\\Python26\\lib\\site-packages\\bluetooth\\msbt.py", line 53, in connect
    [Wed Dec 12 17:00:31 2012] [error] [client 127.0.0.1] bt.connect (self._sockfd, addr, port)
    [Wed Dec 12 17:00:31 2012] [error] [client 127.0.0.1] IOError: Only one usage of each socket address (protocol/network address/port) is normally permitted.\r
    [Wed Dec 12 17:00:31 2012] [error] [client 127.0.0.1]

    I realize that in order for me to feed information back to apache and then onto my client, is I need to def application().... but I wanted to make sure it was just that, and not something that I don't know about using sockets..
     
    Barry Dick, Dec 13, 2012
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ben Finney

    Python, WSGI, legacy web application

    Ben Finney, Nov 22, 2006, in forum: Python
    Replies:
    7
    Views:
    295
    Graham Dumpleton
    Nov 23, 2006
  2. Phillip Sitbon

    Python in IIS + WSGI

    Phillip Sitbon, Jan 12, 2008, in forum: Python
    Replies:
    3
    Views:
    343
    Phillip Sitbon
    Jan 15, 2008
  3. Replies:
    1
    Views:
    407
    Paul Rudin
    Oct 7, 2009
  4. izzahmeor
    Replies:
    0
    Views:
    805
    izzahmeor
    Feb 3, 2010
  5. Sebastian Bassi

    Re: Converting Python CGI to WSGI scripts

    Sebastian Bassi, Mar 17, 2010, in forum: Python
    Replies:
    2
    Views:
    675
Loading...

Share This Page