python\bluetooth / wsgi / apache 2.2


B

Barry Dick

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 ([email protected])
# 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..
 
Ad

Advertisements


Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top