I'm using PyBluez to connect to a device through bluetooth. It is working just fine. The device is using SPP and I connect using a BluetoothSocket (RFCOMM).
Basic interaction is: Send init command -> receive confirmation; send start command -> receive continuous data; send stop command -> ...
I need to be able to control the application from another app: starting, stopping ... I was thinking ZeroMQ or maybe Tornado and a HTTP/REST ifc.
I'm not very keen on making this a multi-threaded app, as I believe it to be a bit over-kill. I've worked a lot with threads and pools of them in C#/.NET, but I have a hunch it is not really necessary here. On the contrary, I think it will be quite messy.
However, I need to be able to process commands (e.g. "start", "stop") via ZeroMQ/REST/ ... while continosly receiving data and sending the occasional packet.
As I am very new to Python I am not sure how to implement this. I have a few ideas: Can the BluetoothSocket be hooked up to the ZeroMQ/Tornado IOLoop?
I assume I can accomplish almost anything using Twisted, but I don't really need everything that Twisted provides. If I need to pull in Twisted, I'll do it. I've actually found a Twisted implementation of BluetoothSocket. But again, do I need Twisted?
I've tried using the Tornado IOLoop. No exceptions are thrown, but on the other hand no data is being received or sent:
def eventhandler(s, events, error = None):
if events & ioloop.IOLoop.READ:
print 'Socket read: %r' % s.recv(1024)
elif events & ioloop.IOLoop.ERROR:
print 'Socket error!'
events = ioloop.IOLoop.READ | ioloop.IOLoop.ERROR
self._loop.add_handler(self._socket.fileno(), eventhandler, events)
I don't really know what I'm doing right now. I'll find a way eventually, but need a hint on which direction to go.
Extensive Google-fu hasn't turned up much useful information, so I'm asking here now.
Edit: I'm currently looking at "gevent". Seems simpler than Twisted at least.