Hey there,
i am trying to receive OSC Messages and write these messages to the key value storage with Node.js on my Arduino Yun. I walked through this tutorial but instead of python I wanted to do it with Node.js. Adventures with Arduino Yun: Control your Yun from your mobile phone using TouchOSC
Receiving OSC Messages works fine and connecting to the TCPJSONServer at 127.0.0.1:5700 on the Linino side obviously works fine as well. But i can't write data to the key value storage. I'm not getting any errors, there is just no data in the storage. I've tried different Node.js packages (json-over-tcp, jsonsocket, json-socket, ...) but with no luck.
The python version from the tutorial works fine at all and is able to write data to the key value storage.
Maybe somebody good at python or Node.s who can help me along and see the difference or an error? That would be great. Thanks!
Node.js Code
var osc = require('node-osc');
var JsonSocket = require('jsonsocket');
var client = new osc.Client('192.168.178.35', 9000); //Smartphone, TouchOSC
var oscServer = new osc.Server(8000, '192.186.178.31'); //Arduino
console.log("trying to connect to TCPJSONSERVER...");
var socket = new JsonSocket(5700, '127.0.0.1');
socket.on('connect', function() {
console.log("connected");
});
oscServer.on("message", function (msg, rinfo) {
console.log(msg[1]);
client.send('/1/label1', msg[1], function () {});
socket.write({"value":msg[1],"key":"D13","command":"put"});
});
Python Code
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.178.31", 8000) )
client = OSCClient()
client.connect( ("192.168.178.35", 9000) )
#waits for slider change
def handle_timeout(self):
print ("Timeout")
server.handle_timeout = types.MethodType(handle_timeout, server)
# function to do the work. path refers to the fader name, args refers to the value of the slider
def fader_callback(path, tags, args, source):
global fader1Feedback
if path=="/1/fader1":
fader1Feedback = float(args[0])
msg = OSCMessage("/1/label1")
msg.insert(0, fader1Feedback)
print "%i" % fader1Feedback
json.send({'command':'put', 'key':'D13', 'value':'%i' % (fader1Feedback)})
client.send(msg)
#execute
server.addMsgHandler( "/1/fader1",fader_callback)
while True:
server.handle_request()
server.close()