I'm working on my 2nd flow only for learning how things working. Still my java script knowledge is close to zero..working hard on it, but not easy @myAge
Still proud I made it that far after investigating, reading hundreds of documents, watching videos etc. I'm not going to tell you that it took me about a week to get there
What I'm trying to achieve in this flow is to (1) listen a UDP stream, which amongst other things sends a constant AIS (ships Automatic Identification System) NMEA data stream. Then (2) split it up for Channel A and Channel B messages by looking for a specific string inside the message. (3) Display LEDs of the Sense Hat matrix for as kind of an dynamic visual indicator that messages coming in. Red for Channel A, green for Channel B. And finally (4) count the number of messages coming through and (5) show the number of messages received for every minute.
(1) is working
(2) is working, but maybe can be optimised?
(3) is working, but for sure can be optimised (4 function nodes feels a bit too much) and has a big disadvantage: there can be up to 10 messages per second. Switching LEDs on and off takes time and sometimes leads to displaying a constant LED light for a second or longer. If technically possible I would like to limit the timeframe for a LED to show to max. 50-100ms.
(4) working to some extent. I cannot get the counter to reset after a minute and I don't know how to show the total message count for each minute on the chart. Below you find an example image of how I think the chart should look like. It's all about showing message count per minute (which obviously requires reset of the counter) in a chart, not about the beauty.
The single purpose of the flow is to learn and is of no other avail.
Any help much appreciated.
Here is the flow:
[{"id":"52ea2419.bf152c","type":"function","z":"6a37a171.1f5858","name":"matrix red on","func":"var newMsg = {payload: \"4,0,red,4,1,red,4,2,red,4,3,red,5,0,red,5,1,red,5,2,red,5,3,red,6,0,red,6,1,red,6,2,red,6,3,red,7,0,red,7,1,red,7,2,red,7,3,red\"};\nreturn newMsg;","outputs":1,"noerr":0,"x":450,"y":160,"wires":[["c01f39a.795c1c8","ed4f63bd.5d86e"]]},{"id":"bd2090d2.44a8a8","type":"switch","z":"6a37a171.1f5858","name":"channel A","property":"payload","propertyType":"msg","rules":[{"t":"cont","v":"!AIVDM,1,1,,A,","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":240,"y":180,"wires":[["52ea2419.bf152c"],["44434248.39b55c"]]},{"id":"44434248.39b55c","type":"function","z":"6a37a171.1f5858","name":"matrix red off","func":"var newMsg = {payload: \"4,0,off,4,1,off,4,2,off,3,off,5,0,off,5,1,off,5,2,off,5,3,off,6,0,off,6,1,off,6,2,off,6,3,off,7,0,off,7,1,off,7,2,off,7,3,off\"};\nreturn newMsg;","outputs":1,"noerr":0,"x":450,"y":200,"wires":[["c01f39a.795c1c8"]]},{"id":"c01f39a.795c1c8","type":"rpi-sensehat out","z":"6a37a171.1f5858","name":"","x":790,"y":260,"wires":[]},{"id":"2fb29b0d.c63ebc","type":"function","z":"6a37a171.1f5858","name":"matrix green on","func":"var newMsg = {payload: \"0,4,green,0,5,green,0,6,green,0,7,green,1,4,green,1,5,green,1,6,green,1,7,green,2,4,green,2,5,green,2,6,green,2,7,green,3,4,green,3,5,green,3,6,green,3,7,green\"};\nreturn newMsg;","outputs":1,"noerr":0,"x":460,"y":320,"wires":[["c01f39a.795c1c8","ed4f63bd.5d86e"]]},{"id":"9579c0b4.73eb4","type":"switch","z":"6a37a171.1f5858","name":"channel B","property":"payload","propertyType":"msg","rules":[{"t":"cont","v":"!AIVDM,1,1,,B,","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":240,"y":340,"wires":[["2fb29b0d.c63ebc"],["ec89eb67.627b28"]]},{"id":"ec89eb67.627b28","type":"function","z":"6a37a171.1f5858","name":"matrix green off","func":"var newMsg = {payload: \"0,4,off,0,5,off,0,6,off,0,7,off,1,4,off,1,5,off,1,6,off,1,7,off,2,4,off,2,5,off,2,6,off,2,7,off,3,4,off,3,5,off,3,6,off,3,7,off\"};\nreturn newMsg;","outputs":1,"noerr":0,"x":460,"y":360,"wires":[["c01f39a.795c1c8"]]},{"id":"5f4df95c.c75ea8","type":"udp in","z":"6a37a171.1f5858","name":"","iface":"","port":"10110","ipv":"udp4","multicast":"false","group":"","datatype":"utf8","x":80,"y":260,"wires":[["bd2090d2.44a8a8","9579c0b4.73eb4"]]},{"id":"ed4f63bd.5d86e","type":"counter","z":"6a37a171.1f5858","name":"","init":"0","step":"1","lower":null,"upper":null,"mode":"increment","outputs":2,"x":680,"y":400,"wires":[["4ff86015.b464d8"],[]]},{"id":"4ff86015.b464d8","type":"ui_chart","z":"6a37a171.1f5858","name":"","group":"e49d7e43.d049e8","order":0,"width":"0","height":"0","label":"","chartType":"line","legend":"false","xformat":"auto","interpolate":"linear","nodata":"","dot":false,"ymin":"0","ymax":"","removeOlder":"1","removeOlderPoints":"","removeOlderUnit":"86400","cutout":0,"useOneColor":false,"colors":["#1F77B4","#AEC7E8","#FF7F0E","#2CA02C","#98DF8A","#D62728","#FF9896","#9467BD","#C5B0D5"],"useOldStyle":false,"outputs":1,"x":850,"y":400,"wires":[[]]},{"id":"854da129.5e8158","type":"comment","z":"6a37a171.1f5858","name":"listen for Channel A and B messages","info":"","x":190,"y":140,"wires":[]},{"id":"d9ab82be.da8888","type":"comment","z":"6a37a171.1f5858","name":"switch LED matrix on/off depending on Channel","info":"","x":540,"y":120,"wires":[]},{"id":"fea1f3d0.9b9d1","type":"comment","z":"6a37a171.1f5858","name":"Total AIS Messages","info":"","x":760,"y":360,"wires":[]},{"id":"e49d7e43.d049e8","type":"ui_group","z":"","name":"AIS Message Count","tab":"f1a698b4.d47f4","order":1,"disp":true,"width":"6","collapse":false},{"id":"f1a698b4.d47f4","type":"ui_tab","z":"","name":"AIS","icon":"dashboard","order":6,"disabled":false,"hidden":false}]
And the nice to have chart image: