Need help optimising flow and Chart output


#6

Hi Steve,
and thank you so much. That is a lot more than expected!

Now I need to work my way through your nodes and see how you had things done. That will be the fun part :slight_smile:

Just deployed and noticed that you split into A/B in the chart. That is not necessary as I want the total amount of messages (A+B). In real life there are these two channels just for the purpose of providing more bandwidth. Imagine a main port like Hongkong or wherever with hundreds if not thousands of ships. Each one sending an AIS message every 3 to 30 seconds. For the receiver it doesn't matter whether it was from channel A or B.

Another thing I discovered is that both LEDs (red and green) stays lit with your flow. Not sure what's going on, but will look into it. edit: my fault. For debug purposes I disconnected the off function nodes...display works fine.


#7

Hi yeah - I was not 100% sure of your final intent (some assumptions were made) .

The changes I made were mostly academic & for showing you alternative methods.

Mainly I wanted to show you how the graph can be populated.

From what I've seen from you I am sure you can integrate what I did with your work & get it going pretty quickly & easily.

Key points I tried to make were...

  • using topics
  • use of flow context
  • use of function nodes with multiple outputs
  • how to populate graph

Let us know if you get stuck.


#8

oh and in case you dont know of it, check out the right hand side bar in particular the Context Data - here you can see what value things are.

nr-st3


#9

Thanks again very much!

The intent is only for learning. Sorry if I was not clear enough.
And no better way than to learn from others, how they do it or how they solve problems.

I must admit I've never heard of flow context, but I can see and understand how it works. When I discovered node-red I really thought it is all plug'n play. Wire a few nodes and there you go. How wrong I was :wink: But thats the fun of it. Finally I have a lot of ideas how to make real use of NR.


#10

Sorry I should have said 'set msg.reset to msg.payload' like this:
08%20AM


#11

zenofmud, not your fault. But a better understanding of this sure will help me.

When I set msg.reset to msg.payload per your example, it sends 0 (as was injected) to the output. The other way around is undefined.


#12

I've always found the SET confusing - it sets the top item to what ever the bottom item is. So it is setting msg.reset' to what evermsg.payload' contains. I probably should have set set msg.reset to 0 because - if you read the info on the node you will see:

Control
It's possible to control the counter with incoming msg properties:

  • msg.increment : counter will be incremented by the given value.
  • msg.decrement : counter will be decremented by the given value.
  • msg.reset : resets the counter to it's initial count, or to the given value, when it's a number.

#13

Indeed, very confusing with the change node. I read that too that msg.reset could be a number and so I accepted 0 to be valid. But is not. As soon as I set msg.reset to 1 or any other number, it works.

Ugh, hard bread. But we finally got there :slight_smile: Thanks very much, zenofmud!


#14

did you mke sure to send the number 0 and not the letter 0. i.e. This:
47%20PM

and not this:

47%20PM

Note the a/z vrs 0/9 for the type


#15

Of course, I did and always verified the output to be a number. It accepts 0, but 0 doesn't reset the counter node.

Here is how it will reset. Please notice that once it resets the counter, it starts counting 1 twice. Means the counter does not start at 0. I cannot explain this as I'm too much of a novice in these things. But sure someone can. Or maybe a bug in the counter node?

[{"id":"c3d38fe.78f58f","type":"inject","z":"5e4ca564.2d1b1c","name":"","topic":"","payload":"1","payloadType":"num","repeat":"15","crontab":"","once":false,"onceDelay":0.1,"x":230,"y":220,"wires":[["cb9075c0.e35628"]]},{"id":"6c0a456e.fb47ac","type":"counter","z":"5e4ca564.2d1b1c","name":"","init":"0","step":"1","lower":"","upper":"","mode":"increment","outputs":2,"x":640,"y":160,"wires":[["e59a770f.b2b8a"],[]]},{"id":"2def1ed.2724962","type":"inject","z":"5e4ca564.2d1b1c","name":"","topic":"","payload":"!AIVDM","payloadType":"str","repeat":"1","crontab":"","once":true,"onceDelay":0.1,"x":240,"y":160,"wires":[["6c0a456e.fb47ac"]]},{"id":"e59a770f.b2b8a","type":"debug","z":"5e4ca564.2d1b1c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":810,"y":200,"wires":[]},{"id":"cb9075c0.e35628","type":"change","z":"5e4ca564.2d1b1c","name":"","rules":[{"t":"set","p":"reset","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":420,"y":220,"wires":[["6c0a456e.fb47ac","e59a770f.b2b8a"]]}]

#16

Which counter node are you using (node-red-contrib-something probably)?


#17

It's the node-red-contrib-counter.


#18

About msg.reset the readme says " msg.reset : resets the counter to it's initial count, or to the given value, when it's a number." The emboldening is mine. Look at what value you have given for msg.reset. The counter is reset to that value.


#19

@colin - it looks like there is a bug when msg.reset is set to zero. In that case it doesn't reset the counter. I'm going to take a look at the node and see if I can see why


#20

Yup there is a bug! in the code it does this

            // handle reset
            if( msg.hasOwnProperty("reset") && msg.reset ) {
                node.count = typeof msg.reset === "number" ? msg.reset : node.init;
            }

the problem is that if msg.reset containg a zero the if statement will always fail because msg.reset evaluate to false. the code should be

            // handle reset
            if( msg.hasOwnProperty("reset") &&  typeof msg.reset === "number" ) {
                node.count = typeof msg.reset === "number" ? msg.reset : node.init;
            }

I will create a PR for this
@Stefanie in the meantime you can fix this in the code yourself if you are daring :stuck_out_tongue_winking_eye:
If you are on a Pi:

  1. open a terminal window
  2. enter nano $HOME/.node-red/node_modules/node-red-contrib-counter/counter.js
  3. use the down arrow to scroll down until you find the code above.
  4. make the change and press ctrl-x the y then the enter key
  5. restart NR and giveit a whirl

NOTE: I updated this code to the correct fix, my original fix only worked it the msg.reset was 0 but it can be any number.


#21

The flow posted sets msg.reset to 1. Which also is not correct.


#22

I set it to 1 as an example only.


#23

Haha, I certainly will when I‘m back home Wednesday :innocent:


#24

@Colin you're right, the if statement needs to be

if( msg.hasOwnProperty("reset") &&  typeof msg.reset === "number" ) {

@Stefanie - use this code instead


#25

Sorry, I had no access to the NR for the last 2 days. Back home now and modified to the code you suggested.
That did the trick. Works perfect now, resets to the number I want :slight_smile:

Next problem already knocking on my door: the sense hat matrix display stops working after a couple of hours. Until then it displays nicely red and/or green just like AIS message flow coming in. When the output stops, there is no way with NR to get it back to work...unless I reboot the machine.
The sense hat itself seems to be still responsive. I can read the sensors and even get output to the LED matrix using a python script. That make me guessing something wrong with the Pi Sense HAT output node or memory usage.