Problem sending slider value to OSC

Hello,
I have problem sending variable data (moved by a dashboard slider) by OSC.
If I send
{"type": "i", "value": 4096}, it work
if I send
{"type": "i", "value": "{{payload}}"}, it doen't work.
I tried all the combination of quote and curls…
How can I replace the value by the message payload received from the slider?
Thank you in advance,
Jacques

It would be nice if you explained what OIC is, what nodes you are using, maybe export your flow and paste it to a reply, because you haven’t given enough information.

And OSC :wink:

Hello,
Thank you for your answer. OSC is Open Sound Control, a protocol to send data through UDP and there is a node-red node transforming json to OSC.
Here is the flow

[
    {
        "id": "f77fbd8e15e87f4e",
        "type": "tab",
        "label": "Dynamixel",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "9bbde0876f3a3a70",
        "type": "inject",
        "z": "f77fbd8e15e87f4e",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "/goal",
        "payload": "{\"type\":\"i\",\"value\":4096}",
        "payloadType": "json",
        "x": 240,
        "y": 380,
        "wires": [
            [
                "87757859285292bd",
                "04f98530e5b9af33"
            ]
        ]
    },
    {
        "id": "87757859285292bd",
        "type": "osc",
        "z": "f77fbd8e15e87f4e",
        "name": "",
        "path": "",
        "metadata": false,
        "x": 830,
        "y": 460,
        "wires": [
            [
                "ce292a98dc2ecaa2"
            ]
        ]
    },
    {
        "id": "ce292a98dc2ecaa2",
        "type": "udp out",
        "z": "f77fbd8e15e87f4e",
        "name": "",
        "addr": "localhost",
        "iface": "",
        "port": "7001",
        "ipv": "udp4",
        "outport": "",
        "base64": false,
        "multicast": "false",
        "x": 1130,
        "y": 460,
        "wires": []
    },
    {
        "id": "9e1cfc96dea4164e",
        "type": "inject",
        "z": "f77fbd8e15e87f4e",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "/goal",
        "payload": "{\"type\":\"i\",\"value\":0}",
        "payloadType": "json",
        "x": 230,
        "y": 420,
        "wires": [
            [
                "87757859285292bd"
            ]
        ]
    },
    {
        "id": "37cf2fe1f81d595e",
        "type": "inject",
        "z": "f77fbd8e15e87f4e",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "/speed",
        "payload": "{\"type\":\"i\",\"value\":10}",
        "payloadType": "json",
        "x": 280,
        "y": 560,
        "wires": [
            [
                "87757859285292bd"
            ]
        ]
    },
    {
        "id": "dc2c2c36bbca3fe1",
        "type": "osc",
        "z": "f77fbd8e15e87f4e",
        "name": "",
        "path": "",
        "metadata": false,
        "x": 490,
        "y": 880,
        "wires": [
            [
                "f33579b4754d0dfa"
            ]
        ]
    },
    {
        "id": "f33579b4754d0dfa",
        "type": "debug",
        "z": "f77fbd8e15e87f4e",
        "name": "debug 5",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 720,
        "y": 880,
        "wires": []
    },
    {
        "id": "a79beafe7a788f14",
        "type": "inject",
        "z": "f77fbd8e15e87f4e",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "/speed",
        "payload": "{\"type\":\"i\",\"value\":150}",
        "payloadType": "json",
        "x": 280,
        "y": 600,
        "wires": [
            [
                "87757859285292bd"
            ]
        ]
    },
    {
        "id": "2fe11019ee3327c7",
        "type": "udp in",
        "z": "f77fbd8e15e87f4e",
        "name": "",
        "iface": "",
        "port": "7000",
        "ipv": "udp4",
        "multicast": "false",
        "group": "",
        "datatype": "buffer",
        "x": 240,
        "y": 880,
        "wires": [
            [
                "dc2c2c36bbca3fe1"
            ]
        ]
    },
    {
        "id": "250c2faa7aa1e98e",
        "type": "inject",
        "z": "f77fbd8e15e87f4e",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "/go",
        "payload": "{\"type\":\"i\",\"value\":0}",
        "payloadType": "json",
        "x": 270,
        "y": 640,
        "wires": [
            [
                "87757859285292bd"
            ]
        ]
    },
    {
        "id": "203c261a0e329239",
        "type": "pythonshell in",
        "z": "f77fbd8e15e87f4e",
        "name": "dynamixel",
        "pyfile": "/home/jhoepffner/dynamixel/pythonDynamixelOSC.py",
        "virtualenv": "/home/jhoepffner/dynamixel/env",
        "continuous": false,
        "stdInData": false,
        "x": 510,
        "y": 80,
        "wires": [
            []
        ]
    },
    {
        "id": "9580f57966c96d24",
        "type": "ui_button",
        "z": "f77fbd8e15e87f4e",
        "name": "",
        "group": "67d118469feea802",
        "order": 0,
        "width": 0,
        "height": 0,
        "passthru": false,
        "label": "start",
        "tooltip": "",
        "color": "",
        "bgcolor": "",
        "className": "",
        "icon": "",
        "payload": "",
        "payloadType": "date",
        "topic": "topic",
        "topicType": "msg",
        "x": 250,
        "y": 40,
        "wires": [
            [
                "203c261a0e329239"
            ]
        ]
    },
    {
        "id": "694f744feaec2ba5",
        "type": "ui_button",
        "z": "f77fbd8e15e87f4e",
        "name": "",
        "group": "67d118469feea802",
        "order": 1,
        "width": 0,
        "height": 0,
        "passthru": false,
        "label": "goal 4096",
        "tooltip": "",
        "color": "",
        "bgcolor": "",
        "className": "",
        "icon": "",
        "payload": "{\"type\":\"i\",\"value\":4096}",
        "payloadType": "json",
        "topic": "/goal",
        "topicType": "str",
        "x": 500,
        "y": 280,
        "wires": [
            [
                "87757859285292bd"
            ]
        ]
    },
    {
        "id": "a8e075ede97464cd",
        "type": "ui_button",
        "z": "f77fbd8e15e87f4e",
        "name": "",
        "group": "67d118469feea802",
        "order": 1,
        "width": 0,
        "height": 0,
        "passthru": false,
        "label": "goal 0",
        "tooltip": "",
        "color": "",
        "bgcolor": "",
        "className": "",
        "icon": "",
        "payload": "{\"type\":\"i\",\"value\":0}",
        "payloadType": "json",
        "topic": "/goal",
        "topicType": "str",
        "x": 490,
        "y": 340,
        "wires": [
            [
                "87757859285292bd"
            ]
        ]
    },
    {
        "id": "b806a2c327a1aa6f",
        "type": "ui_button",
        "z": "f77fbd8e15e87f4e",
        "name": "",
        "group": "67d118469feea802",
        "order": 1,
        "width": 0,
        "height": 0,
        "passthru": false,
        "label": "speed 150",
        "tooltip": "",
        "color": "",
        "bgcolor": "",
        "className": "",
        "icon": "",
        "payload": "{\"type\":\"i\",\"value\":150}",
        "payloadType": "json",
        "topic": "/speed",
        "topicType": "str",
        "x": 490,
        "y": 460,
        "wires": [
            [
                "87757859285292bd"
            ]
        ]
    },
    {
        "id": "a4334153b9c928fe",
        "type": "ui_button",
        "z": "f77fbd8e15e87f4e",
        "name": "",
        "group": "67d118469feea802",
        "order": 1,
        "width": 0,
        "height": 0,
        "passthru": false,
        "label": "speed 10",
        "tooltip": "",
        "color": "",
        "bgcolor": "",
        "className": "",
        "icon": "",
        "payload": "{\"type\":\"i\",\"value\":10}",
        "payloadType": "json",
        "topic": "/speed",
        "topicType": "str",
        "x": 480,
        "y": 500,
        "wires": [
            [
                "87757859285292bd"
            ]
        ]
    },
    {
        "id": "99e67b583ba34f4d",
        "type": "arduino out",
        "z": "f77fbd8e15e87f4e",
        "name": "servo 8",
        "pin": "8",
        "state": "SERVO",
        "arduino": "5ff2cc38773219c0",
        "x": 480,
        "y": 1080,
        "wires": []
    },
    {
        "id": "91f54cce34821179",
        "type": "inject",
        "z": "f77fbd8e15e87f4e",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "servo",
        "payload": "0",
        "payloadType": "num",
        "x": 170,
        "y": 1020,
        "wires": [
            [
                "99e67b583ba34f4d"
            ]
        ]
    },
    {
        "id": "90a5b546afd8e228",
        "type": "inject",
        "z": "f77fbd8e15e87f4e",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "servo",
        "payload": "180",
        "payloadType": "num",
        "x": 180,
        "y": 1140,
        "wires": [
            [
                "99e67b583ba34f4d"
            ]
        ]
    },
    {
        "id": "ccb9548bc416f6d0",
        "type": "ui_slider",
        "z": "f77fbd8e15e87f4e",
        "name": "",
        "label": "slider",
        "tooltip": "",
        "group": "67d118469feea802",
        "order": 6,
        "width": 0,
        "height": 0,
        "passthru": true,
        "outs": "end",
        "topic": "/goal",
        "topicType": "str",
        "min": 0,
        "max": "4096",
        "step": 1,
        "className": "",
        "x": 130,
        "y": 220,
        "wires": [
            [
                "e82f3d051776f086",
                "ed3d84f66ecda862"
            ]
        ]
    },
    {
        "id": "04f98530e5b9af33",
        "type": "debug",
        "z": "f77fbd8e15e87f4e",
        "name": "debug 7",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 840,
        "y": 340,
        "wires": []
    },
    {
        "id": "e82f3d051776f086",
        "type": "function",
        "z": "f77fbd8e15e87f4e",
        "name": "function 1",
        "func": "var newmsg = { \"type\": \"i\", \"value\": 4096 }\nreturn newmsg;",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 500,
        "y": 220,
        "wires": [
            [
                "04f98530e5b9af33"
            ]
        ]
    },
    {
        "id": "ed3d84f66ecda862",
        "type": "change",
        "z": "f77fbd8e15e87f4e",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "{\"type\": \"i\", \"value\": \"{{payload}}\"}",
                "tot": "json"
            },
            {
                "t": "set",
                "p": "topic",
                "pt": "msg",
                "to": "/goal",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 540,
        "y": 160,
        "wires": [
            [
                "04f98530e5b9af33",
                "87757859285292bd"
            ]
        ]
    },
    {
        "id": "67d118469feea802",
        "type": "ui_group",
        "name": "start",
        "tab": "6269638b855099fb",
        "order": 1,
        "disp": false,
        "width": "6",
        "collapse": false,
        "className": ""
    },
    {
        "id": "5ff2cc38773219c0",
        "type": "arduino-board",
        "device": "/dev/ttyACMO"
    },
    {
        "id": "6269638b855099fb",
        "type": "ui_tab",
        "name": "dynamixel",
        "icon": "dashboard",
        "disabled": false,
        "hidden": false
    }
]

You can use the JSONata type input
e.g.

[{"id":"ed3d84f66ecda862","type":"change","z":"f77fbd8e15e87f4e","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"{\"type\": \"i\", \"value\": $$.payload}","tot":"jsonata"},{"t":"set","p":"topic","pt":"msg","to":"/goal","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":540,"y":160,"wires":[["04f98530e5b9af33","87757859285292bd"]]}]

Is that the example flow which node-red-config-osc includes?

Does it work if you set msg.payload in a function node (I think this is what @E1cid suggested above)

msg.payload = {"type": "i", "value": msg.payload}
return msg

I am not sure what you mean by "If I send...". Exactly where are you using that mustache syntax?

Or you can do it without JSONata (which will use less processor overheads) using something like

Does it?
In a simple test, JSONata in this simple task was faster approx 70% of the time.


[edit add flow ]

[{"id":"30490eb550612c82","type":"inject","z":"d1395164b4eec73e","name":"JSONata","props":[{"p":"time","v":"","vt":"date"},{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"123","payloadType":"str","x":80,"y":1740,"wires":[["ed3d84f66ecda862"]]},{"id":"ed3d84f66ecda862","type":"change","z":"d1395164b4eec73e","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"{\"type\": \"i\", \"value\": $$.payload}","tot":"jsonata"},{"t":"set","p":"topic","pt":"msg","to":"/goal","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":260,"y":1740,"wires":[["e4b7c856aed1710e"]]},{"id":"e4b7c856aed1710e","type":"debug","z":"d1395164b4eec73e","name":"debug 2457","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"$millis()-$$.time","statusType":"jsonata","x":470,"y":1740,"wires":[]},{"id":"8cc5a5366e3fdcf0","type":"change","z":"d1395164b4eec73e","name":"","rules":[{"t":"set","p":"temp","pt":"msg","to":"{\"type\":\"i\",\"value\":\"123\"}","tot":"json"},{"t":"set","p":"temp.value","pt":"msg","to":"payload","tot":"msg"},{"t":"move","p":"temp","pt":"msg","to":"payload","tot":"msg"},{"t":"set","p":"topic","pt":"msg","to":"/goal","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":260,"y":1780,"wires":[["318d4e587f22f3db"]]},{"id":"feaf4cc73186c053","type":"inject","z":"d1395164b4eec73e","name":"json","props":[{"p":"time","v":"","vt":"date"},{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"123","payloadType":"str","x":70,"y":1780,"wires":[["8cc5a5366e3fdcf0"]]},{"id":"318d4e587f22f3db","type":"debug","z":"d1395164b4eec73e","name":"debug 2458","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"$millis()-$$.time","statusType":"jsonata","x":470,"y":1800,"wires":[]}]

Can you explain what the jsonata in the debug node does?
image

Thought it would be obvious. It takes the timestamp at beginning of flow and subtracts it from timestamp at end of flow.

1 Like

:joy::joy::joy: JSONata, Obvious? You crack me up.

Oh wait. You're serious? :face_with_peeking_eye:

3 Likes

Yes I am serious that the expression should be obvious to understand, i was not talking about JSONata as a whole.

Are you seriously suggesting you can not work out such a simple expression Steve. I understand you are not a JSONata fan, but the expression is really a simple one.

I will explain it for you seems you maybe having difficulty.

$millis() from change node editor

Returns the number of milliseconds since the Unix Epoch (1 January, 1970 UTC) as a number. All invocations of $millis() within an evaluation of an expression will all return the same value.and - another thing

- From most languages

The subtraction operator subtracts the RHS value from the LHS value to produce the numerical difference It is an error if either operand is not a number.

$$.time

The var set to a timestamp in milliseconds, in the initial inject node.

Hope that helps those who are having difficulty with such a simple expression.

Oh! sorry you where joking.

1 Like

I see now that "millis" enclosed between $ and () indicate a function built in to jsonata and which presumably takes no parameters, while $$ indicates a named property of the message to which the expression is applied, not a similarly built in function. msg.time of course is timestamp, the same measurement of milliseconds since that start time.

Probably I could have looked up $() and $$ or even guessed their meaning but I thought it useful to have an explanation in the forum where this interesting code was used, so I asked.

Thanks for taking the time to indulge me.

1 Like

Hello,
Thank you to everybody!
Unfortunately I just have a medical problem and for some days I am not in front of my computer.
When I am back, I will test your propositions and answer properly.
Have a nice day!

Hello,

msg.payload = {"type": "i", "value": msg.payload}
return msg

doesn't works, if I debug, I receive

{"type": "i", "value": "{{payload}}"}

but I need

{"type": "i", "value": 1096}

(the value sended by the slider)

I hope you are feeling better. :slightly_smiling_face:

The only way that a function node containing exactly this

msg.payload = {"type": "i", "value": msg.payload}
return msg

results in this, with "{{payload}}" as a string literal

{"type":"i","value":"{{payload}}"}

is if msg.payload had been corrupted by a node earlier in the flow.

Please export your flow, including the slider, function and debug and all steps between and paste it here so we can test it.

Hello,
Thank you! it works :=)
I am now able to command a dynamixel motor through a raspberry:

  • the raspberry pi is a wifi server, I can connect with wifi or RJ45
  • a python script inside a bash started by node-red with dynamixel and python-osc libraries
  • node-red send osc to python (/goal, /speed, /accel)
  • I can send OSC from my favourite software, TouchDesigner and receive the actual position of the motor.
    Have a nice sunday.
    Jacques
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.