OSC Integer Support / NodeRed Integer

I am new to NodeRED and highly very, very exited about all the possibilities!

So here is my problem:

I want to use nodeRED to convert Ember+ messages coming from LawoVSM to OSC messages to remote a yamaha DM7, but I fail in sending osc messages from NodeRED, that contain a "integer". My system is fine regarding any meassage as "string", but whenever i insert a number it is sent as a "float".
So i can send strings to rename a console channel but I cant change anything containing number because the OSC module is sending a "float" instead. The yamaha console needs integers for a lot of the parameters.

Is there anyone who can program a "function", so I can just copy and paste it between the insert and the OSC module? I failed with all exaples in the forum and chatGPT didnt help either.

Or is there a possibiliy to update the OSC module, so it will support integer?
THAT would be awesome!

Thanks in advance and best regards!

You can round the floating point number using this code in a function node

msg.payload = Math.round(msg.payload)
return msg

Or alternatively, a Jsonata expression in a change node

Unfortunately I don't know if your Yamaha device will accept the rounded number as an integer.

You can convert a number to the nearest integer string in a function node using something like
let strValue = someNumber.toString(0)
See JavaScript toFixed() Method

Hi !

Not sure exactly about your problem but happy to have a look on sample flow if you want to.

Fyi I m also in media broadcast business and mainly use NR to prototype different kind of workflows related to different media topics.

Would be happy to share some use cases and experiences with you if interested.

Jerome

Thx for the quick, but both dont work! Both versions have a number as payload - and a number is transformed by the OSC module to a float...and yamaha does not accept that as an integer.

What about this?

msg.payload = Math.round(msg.payload).toString()

Thx for the quick answer. I tried the code and I get the error message:

"ReferenceError: ReferenceError: someNumber is not defined (line 1, col 11)"

Any Ideas what I am doing wrong?

Thx for the quick answer. This makes it a string and i need an integer for yamaha.

Jerome, that would be nice! Just write a mail@ .de

You were supposed to put whatever variable you number is in where I used someNumber. So if you number is in msg.payload then
let strValue = msg.payload.toString(0)
Did you look at the link I posted in order to understand what the code does?

Hi, I just gave it a try and could see indeed that OSC node converts any number to FLOAT by default.
You can pass an object with data type to force the node to send INT32 instead of float , have a look here :

[
    {
        "id": "3039abf1.cfc654",
        "type": "inject",
        "z": "6557ea532e17328b",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": "",
        "topic": "/yamahatest",
        "payload": "{\"type\":\"i\",\"value\":12}",
        "payloadType": "json",
        "x": 470,
        "y": 500,
        "wires": [
            [
                "bf7a29be.4085d8"
            ]
        ]
    },
    {
        "id": "bf7a29be.4085d8",
        "type": "osc",
        "z": "6557ea532e17328b",
        "name": "",
        "path": "",
        "metadata": false,
        "x": 650,
        "y": 500,
        "wires": [
            [
                "fcc1e2bd.033e2"
            ]
        ]
    },
    {
        "id": "fcc1e2bd.033e2",
        "type": "udp out",
        "z": "6557ea532e17328b",
        "name": "",
        "addr": "127.0.0.1",
        "iface": "",
        "port": "3345",
        "ipv": "udp4",
        "outport": "",
        "base64": false,
        "multicast": "false",
        "x": 850,
        "y": 500,
        "wires": []
    }
]

Quick test in Protokol, we see the second try with the object is fine :

Colin, thanks so much - yes I did but it seems it didnt help (i guess because i dont get it).
I need the output to be an integer but not a string?

In javascript there are only numbers and strings (and objects, booleans etc). There is no such thing as float or integer. Others have told you how to make sure that the number is a whole number, not a fractional one. It seems that your problem is specific to the OSC node, so I suggest you look at the solutions offered by those who know about that node.

Jerome, thats a big step forward for me!!!
But i need a "function" or a "change", which makes the input (finally coming from Ember+) into the integer (for the DM7)

What would the code look like for that?

As discussed by mail, but still i put it here if useful for other people, here is a quick sample code that would do the job :

[
    {
        "id": "0eae815a5e3cac4a",
        "type": "inject",
        "z": "869e1fa67fd8309e",
        "name": "Channel 1 ON",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": "0",
        "topic": "/yamahatest",
        "payload": "1",
        "payloadType": "num",
        "x": 350,
        "y": 220,
        "wires": [
            [
                "1c8f9e9b4b1f757f"
            ]
        ]
    },
    {
        "id": "1c8f9e9b4b1f757f",
        "type": "function",
        "z": "869e1fa67fd8309e",
        "name": "assign integer Type",
        "func": "\nlet vsmMessage = msg.payload;\nlet yamahaMessage = {};\n\n// Do stuff only if msg is integer\nif (Number.isInteger(vsmMessage)) {\n\n    yamahaMessage = {\n        \"type\": \"i\",\n        \"value\": vsmMessage\n    }\n    msg.payload = yamahaMessage\n}\n// Otherwise pass msg.payload without modification\n\nreturn msg;",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 650,
        "y": 300,
        "wires": [
            [
                "ce830894e9682cca",
                "499f50c39198a0d6"
            ]
        ]
    },
    {
        "id": "ce830894e9682cca",
        "type": "osc",
        "z": "869e1fa67fd8309e",
        "name": "",
        "path": "",
        "metadata": false,
        "x": 850,
        "y": 300,
        "wires": [
            [
                "9ea7ea73eef103cf"
            ]
        ]
    },
    {
        "id": "b6eaf74c496a3003",
        "type": "inject",
        "z": "869e1fa67fd8309e",
        "name": "Channel 1 OFF",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": "0",
        "topic": "/yamahatest",
        "payload": "0",
        "payloadType": "num",
        "x": 360,
        "y": 280,
        "wires": [
            [
                "1c8f9e9b4b1f757f"
            ]
        ]
    },
    {
        "id": "bcc78b2f39b292ce",
        "type": "inject",
        "z": "869e1fa67fd8309e",
        "name": "test Float",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": "0",
        "topic": "/yamahatest",
        "payload": "1.25",
        "payloadType": "num",
        "x": 340,
        "y": 320,
        "wires": [
            [
                "1c8f9e9b4b1f757f"
            ]
        ]
    },
    {
        "id": "107f216a17959ddd",
        "type": "inject",
        "z": "869e1fa67fd8309e",
        "name": "test String",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": "0",
        "topic": "/yamahatest",
        "payload": "HelloWorld",
        "payloadType": "str",
        "x": 340,
        "y": 360,
        "wires": [
            [
                "1c8f9e9b4b1f757f"
            ]
        ]
    },
    {
        "id": "9ea7ea73eef103cf",
        "type": "udp out",
        "z": "869e1fa67fd8309e",
        "name": "",
        "addr": "127.0.0.1",
        "iface": "",
        "port": "3345",
        "ipv": "udp4",
        "outport": "",
        "base64": false,
        "multicast": "false",
        "x": 1040,
        "y": 300,
        "wires": []
    },
    {
        "id": "499f50c39198a0d6",
        "type": "debug",
        "z": "869e1fa67fd8309e",
        "name": "check Payload",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 880,
        "y": 340,
        "wires": []
    }
]