OSC Error: Can't infer OSC argument type

I'm trying to parse a JSON and send it via OSC but get the error below. Do I need to format my data in another way to send it via osc?

Error: Can't infer OSC argument type for value: {
  "symbol": "POWRUSDT",
  "price": "0.71010000"
}

This is my function:

for (var i = 0; i < msg.payload.length; i++) {
    var newMsg = {};
    newMsg.payload = {
        symbol: msg.payload[i].symbol,
        price: msg.payload[i].lastPrice
    }
    node.send(newMsg);
}
return null;

Schermafbeelding 2021-11-17 om 17.45.14

Hi @warddem

can you share a link to what osc nodes you are using? It isn't one I'm familiar with, so hard to suggest anything from the name alone.

Thanks @knolleary ,

I used node-red-contrib-osc and added a "/test" path.

(my 1st project in node red so very open if you have an alternative way ...)

osc is used for open sound control and typically uses a format like:

 {
   address: msg.topic, 
   args: {   // args can be an array of type+value
        "type": "type",    //string
        "value": value   //float
   }
}

thanks @bakman2,

I updated my function:

for (var i = 0; i < msg.payload.length; i++) {
    var newMsg = {};
    newMsg.payload = {
        address: "/mysymbol", 
   args: {   // args can be an array of type+value
        "value": msg.payload[i].symbol   //float
   }
        //price: msg.payload[i].lastPrice
    }
    node.send(newMsg);
}
return null;

It passes the object and args to the debug node but the OSC node still gives this error:

Error: Can't infer OSC argument type for value: {
  "address": "/mysymbol",
  "args": {
    "value": "POWRUSDT"
  }
}

Debug:

object
address: "/mysymbol"
args: object
value: "POWRBUSD"

I am very curious why you use a node that is meant for music/sound interfacing projects to inject cryptocurrency data.

Note that the word float means a number, not a string.

@bakman2 , I'm working on a Audio-visual installation. The idea is to load and parse live data (crypto price, weather data ...) in node red and send it via OSC to max/touchdesigner where i turn the data into visuals and sound.

Changed the function to parse "lastprice" so it returns a float but still gives me the " can't infer " OSC error.

Ah cool. I use VCV Rack with OSC and actually had node-red retrieve the BTC price and converted the difference into control voltage which produced self generating music :wink:

The way I used it in node-red is basically use a change node to set the msg.topic and adding a value in msg.payload and inject those into the osc node, ie only a single payload value.

eg:

Screenshot 2021-11-18 at 06.12.58

Sounds like a great project @bakman2. I'll try your single payload value solution.

How do you add the json value in the msg.payload? Here my change node:

OSC format still throws an error.

Instead of using the args, just set msg.payload to the value. (and make sure to convert it into a number first).

Example flow

[{"id":"1f72d32a49767a16","type":"osc","z":"8aa85d80400c0533","name":"","path":"","metadata":false,"x":722,"y":288,"wires":[[]]},{"id":"3dad1c4660752002","type":"function","z":"8aa85d80400c0533","name":"","func":"key = Object.keys(msg.payload)[0]\ntopic = `/${key}`\npayload = msg.payload[key].usd\nreturn {topic:topic,payload:payload};","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":564,"y":312,"wires":[["4c9b305142fd2c5c","1f72d32a49767a16"]]},{"id":"8f8557af3524373f","type":"http request","z":"8aa85d80400c0533","name":"","method":"GET","ret":"obj","paytoqs":"ignore","url":"https://api.coingecko.com/api/v3/simple/price?ids=bitcoin&vs_currencies=usd","tls":"","persist":false,"proxy":"","authType":"","senderr":false,"x":406,"y":312,"wires":[["3dad1c4660752002","76985b8a8558c181"]]},{"id":"e125e032da3a0e98","type":"inject","z":"8aa85d80400c0533","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":252,"y":312,"wires":[["8f8557af3524373f"]]},{"id":"4c9b305142fd2c5c","type":"debug","z":"8aa85d80400c0533","name":"osc formatted","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":752,"y":360,"wires":[]},{"id":"76985b8a8558c181","type":"debug","z":"8aa85d80400c0533","name":"request","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":564,"y":384,"wires":[]}]