# Anyone mind checking how I am going with this code?

**URL:** https://discourse.nodered.org/t/anyone-mind-checking-how-i-am-going-with-this-code/66848
**Category:** General
**Created:** [24 August 2022 11:39 UTC](https://discourse.nodered.org/t/anyone-mind-checking-how-i-am-going-with-this-code/66848 "2022-08-24T11:39:02Z")
**Posts on this page:** 13
**Page:** 1

<div class="post-metadata">

### Author: ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)
#### Post date: [24 August 2022 11:39 UTC](https://discourse.nodered.org/t/anyone-mind-checking-how-i-am-going-with-this-code/66848/1 "2022-08-24T11:39:02Z")

</div>

This is my latest attempt to get a _block_ for train signals working.

This is a `tab` for now but will eventually be a sub-flow.

There is a lot of _extra_ stuff on the `tab`. Input simulation and `debug` stuff.

The idea is that this is a block of code that receives signals (inputs) and depending on how things are set, may send signals to the outputs.

One of the outputs is then sent to the _next_ block's input and the process is repeated.  
I'm also not 100% on the workings of the signals, but I think I am close.

FOREIGN NODE:  
[Sorry but it is sometimes handy to have](https://flows.nodered.org/node/node-red-contrib-fan)

The top part of the `tab` is the simulated input part.  
Whole lot of `inject` nodes.  
Lower part is the code.  
There are `debug` parts which I tried to keep away from the main code.

The `input` and `outputs` are `link-in` and `link-out` nodes with names explaining their functions.

There is also a `group` which is used between the output of a node on a _side track_ when it goes into a _node_ which represents points/junction on the track.  
Normally the blocks would just connect together - with a slight delay - and work.  
But if/when there is/are a set of _points_ (junction) the output of that block would go through the `group` before going to the next block's input.  
(Clear?)

There is an option to _HOLD_ a train at a section.  
Then _Release_ it to continue.

Between each _section_ I'd suggest a `delay` of a few seconds to better show you how the _train_ moves along.  
But that is if you get really interested.  
The other _Signal_ outputs go to `LED` nodes and I define the colours to be displayed by their names.  
(Keeps it easy)  
And there is an output that indicates the position/condition of the _points_ - if there is/are any on that block.

I've used the three main (ONLY?) colours: RED YELLOW and GREEN.  
There are other things which can be seen, but for now, I want to make sure I've got the mechanics of the idea working, and those other conditions are rare - at best.  
I've named some of the `inject` nodes with the colour code you should see on the panel (lights) when/if working.

Code:  
(Ok, _we_ have a problem. It's too big.)  
[json format file](https://anonfiles.com/J918h757y0/Train_block_tab_json)

I have a working model but the existing subflow fails to allow the _train_ to enter the block if the block is set to `hold`.  
As is, the _train_ is stopped one block before the hold - which is wrong.  
So I sat down and put this together. But I now fear/suspect I am blind to any problems with the workings.

Yes, it is a lot to ask. Only if you have a bit of free time.

I've tried to maintain some kind of constant structure. Maybe overkill at this stage, but I want to get the _muscle memory_ so when I do more in the future, the process is there.

Thanks again.

---

<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: [24 August 2022 12:37 UTC](https://discourse.nodered.org/t/anyone-mind-checking-how-i-am-going-with-this-code/66848/2 "2022-08-24T12:37:47Z")

</div>

> [@Trying\_to\_learn](#):
>
> FOREIGN NODE:  
> [Sorry but it is sometimes handy to have](https://flows.nodered.org/node/node-red-contrib-fan)

Or use node-red v3.x junction node...

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/a/8a0181f9da47bc42a666ec1020eb66f9e9785468.png)

---

<div class="post-metadata">

### Author: ![homeplayer](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/homeplayer/32/12388_2.png) [@homeplayer](https://discourse.nodered.org/u/homeplayer)
#### Post date: [24 August 2022 13:56 UTC](https://discourse.nodered.org/t/anyone-mind-checking-how-i-am-going-with-this-code/66848/3 "2022-08-24T13:56:15Z")

</div>

sorry

# 502 Bad Gateway

cant download

---

<div class="post-metadata">

### Author: ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)
#### Post date: [24 August 2022 21:42 UTC](https://discourse.nodered.org/t/anyone-mind-checking-how-i-am-going-with-this-code/66848/4 "2022-08-24T21:42:17Z")

</div>

Ok, thanks for trying.

I just checked and it works here.  
(I can get to the page and I click the "download" link....)

---

<div class="post-metadata">

### Author: ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)
#### Post date: [24 August 2022 21:43 UTC](https://discourse.nodered.org/t/anyone-mind-checking-how-i-am-going-with-this-code/66848/5 "2022-08-24T21:43:11Z")

</div>

Yes, and I shall - one day - get NR 3.x. But that is more _decorative_ than a functional difference.

---

<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: [24 August 2022 22:11 UTC](https://discourse.nodered.org/t/anyone-mind-checking-how-i-am-going-with-this-code/66848/6 "2022-08-24T22:11:26Z")

</div>

> [@Trying\_to\_learn](#):
>
> one day - get NR 3.x. But that is more _decorative_ than a functional difference

decorative?  
Hundreds of hours wasted fixing bugs and adding new features. Wasted 😭😭😭

---

<div class="post-metadata">

### Author: ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)
#### Post date: [24 August 2022 22:14 UTC](https://discourse.nodered.org/t/anyone-mind-checking-how-i-am-going-with-this-code/66848/7 "2022-08-24T22:14:13Z")

</div>

C'mon.... It was a bit of a dig. It wasn't meant to be serious.

I do like it.  
But I posted the flow with what I have and was looking for help on the workings of it.  
I can't post a flow in version 3.x if I only have 2.x

---

<div class="post-metadata">

### Author: ![tree-frog](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/tree-frog/32/89303_2.png) [@tree-frog](https://discourse.nodered.org/u/tree-frog)
#### Post date: [24 August 2022 23:09 UTC](https://discourse.nodered.org/t/anyone-mind-checking-how-i-am-going-with-this-code/66848/8 "2022-08-24T23:09:42Z")

</div>

A classic case of "Bigger fish to fry and I cannot be bothered by these whales".

---

<div class="post-metadata">

### Author: ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)
#### Post date: [24 August 2022 23:14 UTC](https://discourse.nodered.org/t/anyone-mind-checking-how-i-am-going-with-this-code/66848/9 "2022-08-24T23:14:49Z")

</div>

I sort of get it, but also sort of don't.

---

<div class="post-metadata">

### Author: ![tree-frog](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/tree-frog/32/89303_2.png) [@tree-frog](https://discourse.nodered.org/u/tree-frog)
#### Post date: [25 August 2022 00:22 UTC](https://discourse.nodered.org/t/anyone-mind-checking-how-i-am-going-with-this-code/66848/10 "2022-08-25T00:22:25Z")

</div>

I was totally being sarcastic about your comment on version 3.x. Yeah, if you don't need 3, Decorative? Its editor improvements when your knee deep in getting results you want from your work, the editor is not really your focus. Maybe "Bass" would be a better compare than the "whale"? Plus it probably fries up better!

---

<div class="post-metadata">

### Author: ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)
#### Post date: [25 August 2022 00:24 UTC](https://discourse.nodered.org/t/anyone-mind-checking-how-i-am-going-with-this-code/66848/11 "2022-08-25T00:24:31Z")

</div>

Yeah, and now I have just found an open can of worms with the `button` node not seeming to send the `topic` when I press it. (Other thread)

---

<div class="post-metadata">

### Author: ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)
#### Post date: [25 August 2022 04:15 UTC](https://discourse.nodered.org/t/anyone-mind-checking-how-i-am-going-with-this-code/66848/12 "2022-08-25T04:15:41Z")

</div>

# WOW!

I have made great headway with this.

(Sorry, gotta show off now and then)

This is a working example of the flow.  
_(and yes my favorite foreign node is in there too...)_

[Working example](https://anonfiles.com/5dreo356y3/Train_block_tab_json)

Load the flow, import the foreign node (or do that before you load it)  
Click the `start` button and watch the _train_ go from monitor right to monitor left.  
It is about 5 seconds between sections.

You can `hold` the train before it gets to a section and it will stop in there.  
`Release` it and it will continue.

## (update)

Sorry, you can only hold it where the `switch` button is also there.  
My bad. That is a _problem_ with what is mentioned below.

Wow!

Now I need to get it to understand points as well.  
That is going to be tricky, but hey.... It's fun.

---

<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: [24 October 2022 04:16 UTC](https://discourse.nodered.org/t/anyone-mind-checking-how-i-am-going-with-this-code/66848/13 "2022-10-24T04:16:28Z")

</div>

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