# Elementary math, how to solve this?

**URL:** <https://discourse.nodered.org/t/elementary-math-how-to-solve-this/74231>\
**Category:** General\
**Created:** [26 January 2023 21:07 UTC](https://discourse.nodered.org/t/elementary-math-how-to-solve-this/74231 "2023-01-26T21:07:50Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![devifast](https://avatars.discourse-cdn.com/v4/letter/d/43a26b/32.png) [@devifast](https://discourse.nodered.org/u/devifast)\
**Post date:** [26 January 2023 21:07 UTC](https://discourse.nodered.org/t/elementary-math-how-to-solve-this/74231/1 "2023-01-26T21:07:50Z")

</div>

```auto
var real_pH = "real pH";
var pHSlope = msg.payload.pHSlope;
var pH_current = msg.payload.current;
real_pH =pHSlope - pH_current;
msg.topic = "pH";
return real_pH;

```

function do nothing return., sorry for my english.  
Some is missing, Thanks.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [26 January 2023 21:28 UTC](https://discourse.nodered.org/t/elementary-math-how-to-solve-this/74231/2 "2023-01-26T21:28:36Z")

</div>

You must always return a message. Probably at the end you want

```auto
msg.payload = real_pH
return msg

```

---

<div class="post-metadata">

**Author:** ![Paul-Reed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/paul-reed/32/66906_2.png) [@Paul-Reed](https://discourse.nodered.org/u/Paul-Reed)\
**Post date:** [26 January 2023 21:34 UTC](https://discourse.nodered.org/t/elementary-math-how-to-solve-this/74231/3 "2023-01-26T21:34:18Z")

</div>

In addition to Colin's reply...

> [@devifast](#):
>
> ```auto
> var real_pH = "real pH";
> var pHSlope = msg.payload.pHSlope;
> var pH_current = msg.payload.current;
> real_pH =pHSlope - pH_current;
> 
> ```

Couldn't that be -

```auto
var pHSlope = msg.payload.pHSlope;
var pH_current = msg.payload.current;
var real_pH = pHSlope - pH_current;

```

or preferably -

```auto
const pHSlope = msg.payload.pHSlope;
const pH_current = msg.payload.current;
const real_pH = pHSlope - pH_current;

```

---

<div class="post-metadata">

**Author:** ![devifast](https://avatars.discourse-cdn.com/v4/letter/d/43a26b/32.png) [@devifast](https://discourse.nodered.org/u/devifast)\
**Post date:** [26 January 2023 21:50 UTC](https://discourse.nodered.org/t/elementary-math-how-to-solve-this/74231/4 "2023-01-26T21:50:55Z")

</div>

```auto
var real_pH = "real pH";
var pHSlope = msg.payload.pHSlope;
var pH_current = msg.payload.current;
real_pH =pHSlope - pH_current;
msg.payload = real_pH
//msg.topic = "pH";
//msg.payload = real_pH
return msg
//return msg
//return real_pH;

```

NaN

---

<div class="post-metadata">

**Author:** ![devifast](https://avatars.discourse-cdn.com/v4/letter/d/43a26b/32.png) [@devifast](https://discourse.nodered.org/u/devifast)\
**Post date:** [26 January 2023 21:56 UTC](https://discourse.nodered.org/t/elementary-math-how-to-solve-this/74231/5 "2023-01-26T21:56:37Z")

</div>

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/f/9f00f2edb2aa0ab774b497b764b2e162e26dd53d.png)

---

<div class="post-metadata">

**Author:** ![Paul-Reed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/paul-reed/32/66906_2.png) [@Paul-Reed](https://discourse.nodered.org/u/Paul-Reed)\
**Post date:** [26 January 2023 22:01 UTC](https://discourse.nodered.org/t/elementary-math-how-to-solve-this/74231/7 "2023-01-26T22:01:27Z")

</div>

I don't think that the paths are correct for retrieving the values in your function node for `pHSlope` and `current`.

There’s a great page in the docs ([Working with messages : Node-RED](https://nodered.org/docs/user-guide/messages)) that will explain how to use the debug panel to find the right path to any data item.

Pay particular attention to the part about the buttons that appear under your mouse pointer when you over hover a debug message property in the sidebar.

![BX00Cy7yHi](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/d/bd1f333a9e043b061b39917c328b0094d3e52d30.gif)

---

<div class="post-metadata">

**Author:** ![gerry](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gerry/32/21604_2.png) [@gerry](https://discourse.nodered.org/u/gerry)\
**Post date:** [27 January 2023 02:59 UTC](https://discourse.nodered.org/t/elementary-math-how-to-solve-this/74231/9 "2023-01-27T02:59:12Z")

</div>

Holy cats! Dude, chill out. We are all here to help as we can.

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [27 January 2023 03:09 UTC](https://discourse.nodered.org/t/elementary-math-how-to-solve-this/74231/10 "2023-01-27T03:09:21Z")

</div>

If you put a flag of the Russian Federation on your avatar, would we even recognise it as a flag, unless you drew our attention to it?

(For the benefit of anyone like me who doesn't know without googling, it's horizontal stripes, white, blue, red)

---

<div class="post-metadata">

**Author:** ![devifast](https://avatars.discourse-cdn.com/v4/letter/d/43a26b/32.png) [@devifast](https://discourse.nodered.org/u/devifast)\
**Post date:** [27 January 2023 07:22 UTC](https://discourse.nodered.org/t/elementary-math-how-to-solve-this/74231/11 "2023-01-27T07:22:42Z")

</div>

Thanks very much.

---

<div class="post-metadata">

**Author:** ![devifast](https://avatars.discourse-cdn.com/v4/letter/d/43a26b/32.png) [@devifast](https://discourse.nodered.org/u/devifast)\
**Post date:** [27 January 2023 07:29 UTC](https://discourse.nodered.org/t/elementary-math-how-to-solve-this/74231/12 "2023-01-27T07:29:52Z")

</div>

What am I, to associate two colors with something! And I thought higher mathematics was complicated 🙂 greetings.

---

<div class="post-metadata">

**Author:** ![devifast](https://avatars.discourse-cdn.com/v4/letter/d/43a26b/32.png) [@devifast](https://discourse.nodered.org/u/devifast)\
**Post date:** [27 January 2023 10:17 UTC](https://discourse.nodered.org/t/elementary-math-how-to-solve-this/74231/13 "2023-01-27T10:17:53Z")

</div>

```auto
[
    {
        "id": "7a04b08e2eab1a33",
        "type": "tab",
        "label": "Flow 1",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "c46a5c92f29f3709",
        "type": "join",
        "z": "7a04b08e2eab1a33",
        "name": "",
        "mode": "custom",
        "build": "object",
        "property": "payload",
        "propertyType": "msg",
        "key": "topic",
        "joiner": "\\n",
        "joinerType": "str",
        "accumulate": true,
        "timeout": "",
        "count": "2",
        "reduceRight": false,
        "reduceExp": "",
        "reduceInit": "",
        "reduceInitType": "",
        "reduceFixup": "",
        "x": 570,
        "y": 320,
        "wires": [
            [
                "19d8a890e7db135c",
                "aba6e607dc568136"
            ]
        ]
    },
    {
        "id": "aba6e607dc568136",
        "type": "function",
        "z": "7a04b08e2eab1a33",
        "name": "function 4",
        "func": "var real_pH = real_pH;\nvar pHSlope = msg.payload.pHSlope;\nvar current = msg.payload.current;\nreal_pH = pHSlope - current ;\nmsg.topic = \"pH\";\nmsg.payload = real_pH;\nreturn msg;\n",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 720,
        "y": 320,
        "wires": [
            [
                "94b65cd2bebab7f9"
            ]
        ]
    },
    {
        "id": "94b65cd2bebab7f9",
        "type": "debug",
        "z": "7a04b08e2eab1a33",
        "name": "debug 6",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 880,
        "y": 320,
        "wires": []
    },
    {
        "id": "edd70a9c95a7cbd3",
        "type": "inject",
        "z": "7a04b08e2eab1a33",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "current",
        "payload": "200",
        "payloadType": "num",
        "x": 430,
        "y": 340,
        "wires": [
            [
                "c46a5c92f29f3709"
            ]
        ]
    },
    {
        "id": "19d8a890e7db135c",
        "type": "debug",
        "z": "7a04b08e2eab1a33",
        "name": "debug 8",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 720,
        "y": 280,
        "wires": []
    },
    {
        "id": "fafbb4ad3c50113c",
        "type": "inject",
        "z": "7a04b08e2eab1a33",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": true,
        "onceDelay": 0.1,
        "topic": "pHSlope",
        "payload": "60",
        "payloadType": "num",
        "x": 430,
        "y": 300,
        "wires": [
            [
                "c46a5c92f29f3709"
            ]
        ]
    }
]

```

That's how it works. I just went the wrong way to solve the task. Thanks to everyone who took the time to resolve this issue. I apologize that I was misunderstood earlier in the topic. I didn't mean to offend anyone in any way. Once again, I offer my apologies.
