# Help finding a bug in the Node-red thread

**URL:** <https://discourse.nodered.org/t/help-finding-a-bug-in-the-node-red-thread/63817>\
**Category:** General\
**Tags:** node-red-dashboard, function-node\
**Created:** [12 June 2022 10:15 UTC](https://discourse.nodered.org/t/help-finding-a-bug-in-the-node-red-thread/63817 "2022-06-12T10:15:02Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Eva01](https://avatars.discourse-cdn.com/v4/letter/e/278dde/32.png) [@Eva01](https://discourse.nodered.org/u/Eva01)\
**Post date:** [12 June 2022 10:15 UTC](https://discourse.nodered.org/t/help-finding-a-bug-in-the-node-red-thread/63817/1 "2022-06-12T10:15:02Z")

</div>

Hello!  
I was told to do a job in Node-red as my thesis. This is my first time using the program, so I don't understand anything about it. I made a thread, but it doesn't want to work. I don't understand where the error is. I will be very grateful for your help)  
Here is my JSON stream:

```auto
[{"id":"c303b4e99409c666","type":"ui_dropdown","z":"cb59f7c8f4c017c7","name":"","label":" Cabling","tooltip":"","place":"Select option","group":"346f3afd.14dd56","order":1,"width":0,"height":0,"passthru":true,"multiple":false,"options":[{"label":"open ","value":1,"type":"num"},{"label":"close","value":"0","type":"str"}],"payload":"","topic":"topic2","topicType":"str","className":"","x":180,"y":140,"wires":[["e657941b9716b9c3"]]},{"id":"836735bc82967e2e","type":"ui_form","z":"cb59f7c8f4c017c7","name":"","label":"Selection of cable section","group":"346f3afd.14dd56","order":3,"width":0,"height":0,"options":[{"label":"Pн","value":"Pн","type":"number","required":true,"rows":null},{"label":"Uн","value":"Uн","type":"number","required":true,"rows":null},{"label":"cosf","value":"cosf","type":"number","required":true,"rows":null},{"label":"kpd","value":"kpd","type":"number","required":true,"rows":null}],"formValue":{"Pн":"","Uн":"","cosf":"","kpd":""},"payload":"","submit":"submit","cancel":"cancel","topic":"topic1","topicType":"str","splitLayout":"","className":"","x":130,"y":80,"wires":[["e657941b9716b9c3"]]},{"id":"b58f4ef85dcba712","type":"ui_text","z":"cb59f7c8f4c017c7","group":"346f3afd.14dd56","order":4,"width":0,"height":0,"name":"","label":"Аluminum:","format":"{{msg.payload.result1}}","layout":"col-center","className":"","x":670,"y":120,"wires":[]},{"id":"9084d92b3c8f6ca7","type":"function","z":"cb59f7c8f4c017c7","name":"","func":"const Pн = msg.payload.topic1.Pн\nconst Uн = msg.payload.topic1.Uн;\nconst cosf = msg.payload.topic1.cosf;\nconst kpd = msg.payload.topic1.kpd;\n P = msg.payload.topic2.P;\n K = msg.payload.topic3.K;\n\nmsg.payload.result1 = Math.round((Pн*1000/(Math.sqrt(3) * Uн * cosf * kpd)));\n\nif (( msg.payload.result1<=22) && (P===1) && (K===2)) {\n \n msg.payload.result1 = 'АВВГ 1х2,5';\n} else if ((msg.payload.result1<=30) && (P===1) && (K===2)) {\n \n msg.payload.result1 = 'АВВГ 1х4';\n} else if ((msg.payload.result1<=37) && (P===1) && (K===2)) {\n \n msg.payload.result1 = 'АВВГ 1х6';\n} else if ((msg.payload.result1<=30) && (P===0) && (K===2)) {\n \n msg.payload.result1 = 'АВВГ 1х2,5';\n} else if ((msg.payload.result1<=39) && (P===0) && (K===2)) {\n \n msg.payload.result1 = 'АВВГ 1х4';\n} else if ((msg.payload.result1<=48) && (P===0) && (K===2)) {\n \n msg.payload.result1 = 'АВВГ 1х6';\n} else if ((msg.payload.result1<=21) && (P===1) && (K===3)) {\n \n msg.payload.result1 = 'АВВГ 3х2,5';\n} else if ((msg.payload.result1<=29) && (P===1) && (K===3)) {\n \n msg.payload.result1 = 'АВВГ 3х4';\n} else if ((msg.payload.result1<=37) && (P===1) && (K===3)) {\n \n msg.payload.result1 = 'АВВГ 3х6';\n} else if ((msg.payload.result1<=28) && (P===0) && (K===3)) {\n \n msg.payload.result1 = 'АВВГ 3х2,5';\n} else if ((msg.payload.result1<=37) && (P===0) && (K===3)) {\n \n msg.payload.result1 = 'АВВГ 3х4';\n} else if ((msg.payload.result1<=44) && (P===0) && (K===3)) {\n \n msg.payload.result1 = 'АВВГ 3х6';\n} else {\n msg.payload.result1 = 'not';\n \n}\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":560,"y":220,"wires":[["b58f4ef85dcba712"]]},{"id":"e657941b9716b9c3","type":"join","z":"cb59f7c8f4c017c7","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":true,"timeout":"","count":"3","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":370,"y":220,"wires":[["9084d92b3c8f6ca7","11592e1215695baa"]]},{"id":"11592e1215695baa","type":"function","z":"cb59f7c8f4c017c7","name":"","func":"const Pн = msg.payload.topic1.Pн;\nconst Uн = msg.payload.topic1.Uн;\nconst cosf = msg.payload.topic1.cosf;\nconst kpd = msg.payload.topic1.kpd;\nP = msg.payload.topic2;\nK = msg.payload.topic3;\n\nmsg.payload.result = Math.round((Pн*1000/(Math.sqrt(3) * Uн * cosf * kpd)));\n\nif (( msg.payload.result1<=22) && (P===1) && (K===2)) {\n \n msg.payload.result1 = 'АВВГ 1х1,5';\n} else if ((msg.payload.result1<=30) && (P===1) && (K===2)) {\n \n msg.payload.result1 = 'АВВГ 1х2,5';\n} else if ((msg.payload.result1<=39) && (P===1) && (K===2)) {\n \n msg.payload.result1 = 'АВВГ 1х4';\n} else if ((msg.payload.result1<=30) && (P===0) && (K===2)) {\n \n msg.payload.result1 = 'АВВГ 1х1,5';\n} else if ((msg.payload.result1<=39) && (P===0) && (K===2)) {\n \n msg.payload.result1 = 'АВВГ 1х2,5';\n} else if ((msg.payload.result1<=50) && (P===0) && (K===2)) {\n \n msg.payload.result1 = 'АВВГ 1х4';\n} else if ((msg.payload.result1<=21) && (P===1) && (K===3)) {\n \n msg.payload.result1 = 'АВВГ 3х1,5';\n} else if ((msg.payload.result1<=27) && (P===1) && (K===3)) {\n \n msg.payload.result1 = 'АВВГ 3х2,5';\n} else if ((msg.payload.result1<=36) && (P===1) && (K===3)) {\n \n msg.payload.result1 = 'АВВГ 3х4';\n} else if ((msg.payload.result1<=27) && (P===0) && (K===3)) {\n \n msg.payload.result1 = 'АВВГ 3х1,5';\n} else if ((msg.payload.result1<=36) && (P===0) && (K===3)) {\n \n msg.payload.result1 = 'АВВГ 3х2,5';\n} else if ((msg.payload.result1<=47) && (P===0) && (K===3)) {\n \n msg.payload.result1 = 'АВВГ 3х4';\n} else {\n msg.payload.result1 = 'not';\n \n}\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":560,"y":280,"wires":[["47acfee19968d659"]]},{"id":"47acfee19968d659","type":"ui_text","z":"cb59f7c8f4c017c7","group":"346f3afd.14dd56","order":5,"width":0,"height":0,"name":"","label":"Сopper :","format":"{{msg.payload.result2}}","layout":"col-center","className":"","x":660,"y":360,"wires":[]},{"id":"96580ce7f2507353","type":"ui_dropdown","z":"cb59f7c8f4c017c7","name":"","label":"Amount","tooltip":"","place":"Select option","group":"346f3afd.14dd56","order":2,"width":0,"height":0,"passthru":true,"multiple":false,"options":[{"label":"one","value":"2","type":"str"},{"label":"many","value":"3","type":"str"}],"payload":"","topic":"topic3","topicType":"str","className":"","x":160,"y":220,"wires":[["e657941b9716b9c3"]]},{"id":"346f3afd.14dd56","type":"ui_group","name":"Default","tab":"445e350b.bd700c","order":1,"disp":true,"width":"6","collapse":false},{"id":"445e350b.bd700c","type":"ui_tab","name":"Home","icon":"dashboard","order":6,"disabled":false,"hidden":false}]

```

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [12 June 2022 10:23 UTC](https://discourse.nodered.org/t/help-finding-a-bug-in-the-node-red-thread/63817/2 "2022-06-12T10:23:06Z")

</div>

Hi & welcome.

> [@Eva01](#):
>
> Here is my JSON stream:

These are called `flows` in node-red.

  

Most importantly, use DEBUG nodes to see what is happening.  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/0/3098b3e77614c3daea0d8fbd42a568621e62da58.png)

Also, you have JavaScript errors  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/1/d170240c9c713f5b68259e10e0f82afdf987facd.png)

> [@Eva01](#):
>
> This is my first time using the program, so I don't understand anything about it

You seem to be doing OK but it would be wise to spend a bit time with docs and videos. As a new user, I recommend watching this playlist: [Node-RED Essentials](https://www.youtube.com/playlist?list=PLyNBB9VCLmo1hyO-4fIZ08gqFcXBkHy-6). The videos are done by the developers of node-red. They're nice & short and to the point. You will understand a whole lot more in about 1 hour. A small investment for a lot of gain.

---

<div class="post-metadata">

**Author:** ![Eva01](https://avatars.discourse-cdn.com/v4/letter/e/278dde/32.png) [@Eva01](https://discourse.nodered.org/u/Eva01)\
**Post date:** [12 June 2022 10:39 UTC](https://discourse.nodered.org/t/help-finding-a-bug-in-the-node-red-thread/63817/3 "2022-06-12T10:39:50Z")

</div>

There is still an error. For some reason, "1" takes into account for me, but "0" does not, and the same thing with 'topic3'(

 ![ошибка](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/5/c59f1b3ee6347989ed84096b2f7541c472532d94.jpeg)

---

<div class="post-metadata">

**Author:** ![Landsailor](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/landsailor/32/62070_2.png) [@Landsailor](https://discourse.nodered.org/u/Landsailor)\
**Post date:** [12 June 2022 23:52 UTC](https://discourse.nodered.org/t/help-finding-a-bug-in-the-node-red-thread/63817/4 "2022-06-12T23:52:35Z")

</div>

https://www.youtube.com/embed/videoseries?list=PLyNBB9VCLmo1hyO-4fIZ08gqFcXBkHy-6&wmode=transparent&rel=0&autohide=1&showinfo=1&enablejsapi=1

Spend a few minutes watching these videos and you'll save yourself _hours_ of frustration.

---

<div class="post-metadata">

**Author:** ![Frida](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/frida/32/68250_2.png) [@Frida](https://discourse.nodered.org/u/Frida)\
**Post date:** [13 June 2022 08:00 UTC](https://discourse.nodered.org/t/help-finding-a-bug-in-the-node-red-thread/63817/5 "2022-06-13T08:00:42Z")

</div>

![pic00](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/a/cabf0a75a6be17aaf9138e15cfdac05106d02232.jpeg)

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [12 August 2022 08:00 UTC](https://discourse.nodered.org/t/help-finding-a-bug-in-the-node-red-thread/63817/6 "2022-08-12T08:00:51Z")

</div>

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