Hello List,
I continue on my quest to control a YUN via my ipad/iphone with the TouchOSC app. I am making good progress with help from the forum and the web and can now do this well but the information flow between the python script and the YUN is one way and I would to make it two way. A screen shot of the controller is attached and it is all fine exept I want to show when the pulse generator is ready to run with a ready light and running with a busy light.
Python deals with the interaction with the Ipad and YUN using the following structure:
from OSC import OSCServer,OSCClient, OSCMessage
import sys
from time import sleep
import types
sys.path.insert(0, '/usr/lib/python2.7/bridge/') # make sure python can see the tcp module
from tcp import TCPJSONClient
#set up the json client and the osc client and server. The server should have the ip of your Yun.
#The client.connect should have the ip address of you phone.
json = TCPJSONClient('127.0.0.1', 5700)
server = OSCServer( ("192.168.0.21", 8000) ) #this is the address of the YUN
client = OSCClient()
client.connect( ("192.168.0.19", 9000) ) #this is the address of the phone
In order to send information to the YUN, I use the following code defined within a python function:
global faderDefault
faderDefault = 0
json.send({'command':'put', 'key':'F01', 'value':'%.2f' % (faderDefault)})
Then, in the arduino sketch:
Bridge.get("F01",F01value,3); // read the state of the fader
int F01int = atoi(F01value);
where F01value is defined as a global
char F01value[3];
So far so good but I want to be able to send information from the Arduino sketch to the python script and then adjust the control on the ipad accordingly.
Bridge.put("LD1", "0"); // sends a key of "LD1" with a value of 0
What I don't know is how to read this from within the python script and have failed to find anything on the internet that deals with this precise issue.
Any suggestions?
Thanks,
Nick