I might have an idea....
I've spent the last couple of days on the same problem. The goal is to have a Python script that listens to OSC messages from an application on my phone, and to pass on values retrieved from some of the messages to control PWM pins. Getting the Python script to run properly was surprisingly straightforward, given my (lack of) Linux and Python skills. So far, the script reads floats between -127 and +127 from two faders and sends the values back to the phone, where they're displayed in two text boxes as feedback.
All this works very fast and smooth. Excellent.
Then I tried to pass on the values to the Arduino sketch. I had been hoping that runShellCommandAsynchronously() would do the job, but apparently that's not possible. At least I couldn't get it to work.
After many, many hours of trying all kinds of things I found this thread. I managed to get it working, but, as mentioned above, the speed is simply unacceptable. However, using code from bridgeclient.py I was able to speed it up significantly. Adding
from bridgeclient import BridgeClient as bridgeclient
json = TCPJSONClient('127.0.0.1', 5700)
to the script, and replacing value.put('D13','%i' % (fader1Feedback))
with json.send({'command':'put', 'key':'D13', 'value':'%i' % (fader1Feedback)})
did the trick. Avoiding opening and closing a socket for every put is the key.
This will need a lot more testing and refining, but so far it looks promising.
Here's the relevant part of the script. Hope it's helpful.
#!/usr/bin/python
import OSC
import time, threading
import sys
sys.path.insert(0, '/usr/lib/python2.7/bridge/')
from bridgeclient import BridgeClient as bridgeclient
from tcp import TCPJSONClient
value = bridgeclient()
json = TCPJSONClient('127.0.0.1', 5700)
receive_address = ('192.168.1.144', 12345)
s = OSC.OSCServer(receive_address)
client = OSC.OSCClient()
s.addDefaultHandlers()
fader1Feedback = 0
# define a message-handler function for the server to call.
def printing_handler(addr, tags, stuff, source):
global fader1Feedback
global fader2Feedback
if addr=="/1/fader1":
fader1Feedback = int(stuff[0])
msg = OSC.OSCMessage("/1/label2")
msg.append('0')
msg.insert(0, fader1Feedback)
client.sendto(msg, ('192.168.1.109', 1234))
print "%i" % fader1Feedback
#value.put('D13','%i' % (fader1Feedback))
json.send({'command':'put', 'key':'D13', 'value':'%i' % (fader1Feedback)})