Convert Specific Gravity to Brix

I'm attempting to convert Specific Gravity to Brix coming in via a webhook from a Tilt Hydrometer. These numbers are used to monitor fermentation progress. I pulled the equation from Wikipedia and it's below but I'm trying to figure out how to use this equation in a function node. The number coming in from the webhook in specific gravity would look something like 1.07 but I'm not very familiar with how to work this into a javascript-based function. Any help available?

SG -> Brix Equation:
Brix = (((182.4601 * SG -775.6821) * SG +1262.7794) * SG -669.5622)
(Source: http://en.wikipedia.org/wiki/Brix)
Punching in 1.07 for SG in this equation equates to 17.055

let SG =1.07
msg.payload = (((182.4601 * SG - 775.6821) * SG + 1262.7794) * SG - 669.5622)
return msg;  // 17.05478999429988

Or if the sg is in msg.payload then replace first line with
let SG = msg.payload

Thanks for the help guys. I was able to get this working and build it into my flow. This flow splits up a few of the webhook variables that can be sent and sends them to a couple of charts and a dashboard status. The converts for brix are just converting a number out to one decimal point. There's probably another way of doing it but this was easy. This is for a RAPT Pill Tilt Hydrometer converting to Brix in Node-Red. Saying this because I wasn't able to find anything while searching so hopefully someone else finds this post useful.

    {
        "id": "68a1165390db4044",
        "type": "http in",
        "z": "15f71001.075b9",
        "name": "Pill 6",
        "url": "/pill-6",
        "method": "post",
        "upload": false,
        "swaggerDoc": "",
        "x": 110,
        "y": 880,
        "wires": [
            [
                "c0c1c1db3f8069a3",
                "daaa33cb4a8fa56f"
            ]
        ]
    },
    {
        "id": "c0c1c1db3f8069a3",
        "type": "http response",
        "z": "15f71001.075b9",
        "name": "",
        "statusCode": "200",
        "headers": {},
        "x": 100,
        "y": 840,
        "wires": []
    },
    {
        "id": "daaa33cb4a8fa56f",
        "type": "function",
        "z": "15f71001.075b9",
        "name": "Name",
        "func": "msg.payload.topic_root = msg.payload.name;\n//msg.topic = msg.payload.topic_root + \"brix\";\nmsg.payload = msg.payload;\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 270,
        "y": 880,
        "wires": [
            [
                "543f2d31812b55b5",
                "f0e6583a0ca0ba7e",
                "b5c416c6f714af0a"
            ]
        ]
    },
    {
        "id": "543f2d31812b55b5",
        "type": "function",
        "z": "15f71001.075b9",
        "name": "Publish Brix Status",
        "func": "msg.topic = msg.payload.topic_root;\nlet SG = msg.payload.gravity;\nmsg.payload = (((182.4601 * SG - 775.6821) * SG + 1262.7794) * SG - 669.5622);\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 430,
        "y": 880,
        "wires": [
            [
                "3818095ed56aa2d2"
            ]
        ]
    },
    {
        "id": "5f164a6fb52e5d8a",
        "type": "warp",
        "z": "15f71001.075b9",
        "name": "",
        "scope": [
            "4011ba66b55d0595"
        ],
        "destination": "selected",
        "x": 760,
        "y": 920,
        "wires": []
    },
    {
        "id": "f0e6583a0ca0ba7e",
        "type": "function",
        "z": "15f71001.075b9",
        "name": "Publish Temp Status",
        "func": "msg.topic = msg.payload.topic_root + \"/temperature\";\nmsg.payload = msg.payload.temperature;\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 440,
        "y": 840,
        "wires": [
            [
                "d9aa79e0045c40dc"
            ]
        ]
    },
    {
        "id": "4061154caa2df5e5",
        "type": "warp",
        "z": "15f71001.075b9",
        "name": "",
        "scope": [
            "c4ef5e08bc02bb40"
        ],
        "destination": "selected",
        "x": 760,
        "y": 840,
        "wires": []
    },
    {
        "id": "d9aa79e0045c40dc",
        "type": "unit-converter",
        "z": "15f71001.075b9",
        "category": "temperature",
        "inputUnit": "C",
        "outputUnit": "F",
        "inputField": "payload",
        "outputField": "payload",
        "inputFieldType": "msg",
        "outputFieldType": "msg",
        "roundOutputField": true,
        "outputFieldDecimals": "1",
        "statusType": "none",
        "name": "Convert",
        "x": 620,
        "y": 840,
        "wires": [
            [
                "4061154caa2df5e5"
            ]
        ]
    },
    {
        "id": "602647d9d0f62fdd",
        "type": "function",
        "z": "15f71001.075b9",
        "name": "Status",
        "func": "var text = context.get('text')|| [];\nmsg.topic_root = \"/name\"\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 750,
        "y": 880,
        "wires": [
            [
                "07bb632a4e2a7dce"
            ]
        ]
    },
    {
        "id": "3818095ed56aa2d2",
        "type": "unit-converter",
        "z": "15f71001.075b9",
        "category": "temperature",
        "inputUnit": "C",
        "outputUnit": "C",
        "inputField": "payload",
        "outputField": "payload",
        "inputFieldType": "msg",
        "outputFieldType": "msg",
        "roundOutputField": true,
        "outputFieldDecimals": "1",
        "statusType": "none",
        "name": "Convert",
        "x": 620,
        "y": 880,
        "wires": [
            [
                "602647d9d0f62fdd"
            ]
        ]
    },
    {
        "id": "b5c416c6f714af0a",
        "type": "function",
        "z": "15f71001.075b9",
        "name": "Publish Brix Chart",
        "func": "msg.topic = msg.payload.topic_root;\nlet SG = msg.payload.gravity\nmsg.payload = (((182.4601 * SG - 775.6821) * SG + 1262.7794) * SG - 669.5622)\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 430,
        "y": 920,
        "wires": [
            [
                "0b3057308687b275",
                "6ec634d2764ebf00"
            ]
        ]
    },
    {
        "id": "0b3057308687b275",
        "type": "unit-converter",
        "z": "15f71001.075b9",
        "category": "temperature",
        "inputUnit": "C",
        "outputUnit": "C",
        "inputField": "payload",
        "outputField": "payload",
        "inputFieldType": "msg",
        "outputFieldType": "msg",
        "roundOutputField": true,
        "outputFieldDecimals": "1",
        "statusType": "none",
        "name": "Convert",
        "x": 620,
        "y": 920,
        "wires": [
            [
                "5f164a6fb52e5d8a"
            ]
        ]
    },
    {
        "id": "6ec634d2764ebf00",
        "type": "debug",
        "z": "15f71001.075b9",
        "name": "debug 27",
        "active": false,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 640,
        "y": 960,
        "wires": []
    },
    {
        "id": "07bb632a4e2a7dce",
        "type": "ui_text",
        "z": "15f71001.075b9",
        "group": "29b96df2a16b9678",
        "order": 4,
        "width": 0,
        "height": 0,
        "name": "Tank-C3",
        "label": "Current Brix",
        "format": "{{msg.topic}}:  {{msg.payload}} Brix",
        "layout": "row-spread",
        "className": "",
        "style": false,
        "font": "",
        "fontSize": 16,
        "color": "#000000",
        "x": 960,
        "y": 940,
        "wires": []
    },
    {
        "id": "29b96df2a16b9678",
        "type": "ui_group",
        "name": "Tank C3",
        "tab": "75e2c4a4bae21b23",
        "order": 15,
        "disp": true,
        "width": "6",
        "collapse": false,
        "className": ""
    },
    {
        "id": "75e2c4a4bae21b23",
        "type": "ui_tab",
        "name": "Controls",
        "icon": "dashboard",
        "order": 2,
        "disabled": false,
        "hidden": false
    }
]

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