2019-09-03, 07:13 AM
(2019-09-03, 12:14 AM)mikedeflieslife Wrote: I have no experience of using Node Red, is there a template to follow to do what I need?
This solution was published by sbender from the Signal K Team on the signalk-dev forum and it is really good. If the prefered gps is working it filters every other gps. If prefered gps is offline it feallback to other gps.
I think about adding this to the openplotter gui tools.
(https://app.slack.com/client/T02ENM6QA/C...225.072600)
It prefers N2K src=150. (It uses a subflow. If you didn't work with nodered subflow google it to be able to edit the prefered gps)
Code:
[{"id":"1a05e1f9.8eca1e","type":"subflow","name":"Prefer N2k GPS","info":"","category":"","in":[{"x":40,"y":40,"wires":[{"id":"d6944a31.d96088"}]}],"out":[{"x":380,"y":40,"wires":[{"id":"d6944a31.d96088","port":0}]}]},{"id":"d6944a31.d96088","type":"function","z":"1a05e1f9.8eca1e","name":"prefer Antenna","func":"\nconst timeout = 5\nconst prefered = '150'\nlet lastSeen = context.get('lastSeen')\n\n//node.error(`${JSON.stringify(msg.source)}`)\n\nif ( msg.source.src === prefered )\n{\n node.send(msg)\n context.set('lastSeen', Date.now())\n //node.error('go it')\n} else if ( !lastSeen ) {\n node.send(msg)\n //node.error('no last')\n} else if ( Date.now() - lastSeen > (timeout *1000)) {\n node.send(msg)\n //node.error('timeout')\n}\n\n","outputs":1,"noerr":0,"x":220,"y":40,"wires":[[]]},{"id":"f8b48a68.917e28","type":"tab","label":"Input Filters","disabled":false,"info":""},{"id":"e61d660a.610a38","type":"signalk-input-handler","z":"f8b48a68.917e28","name":"navigation.position","context":"vessels.self","path":"navigation.position","source":"","x":130,"y":140,"wires":[["a638f26c.ad395"]]},{"id":"9397e0dc.6e543","type":"signalk-input-handler-next","z":"f8b48a68.917e28","name":"","x":780,"y":140,"wires":[]},{"id":"12c2f5e6.84575a","type":"signalk-input-handler","z":"f8b48a68.917e28","name":"navigation.datetime","context":"vessels.self","path":"navigation.datetime","source":"","x":130,"y":80,"wires":[["a638f26c.ad395"]]},{"id":"64f51379.986e4c","type":"signalk-input-handler","z":"f8b48a68.917e28","name":"navigation.speedOverGround","context":"vessels.self","path":"navigation.speedOverGround","source":"","x":160,"y":200,"wires":[["a638f26c.ad395"]]},{"id":"a638f26c.ad395","type":"subflow:1a05e1f9.8eca1e","z":"f8b48a68.917e28","name":"","x":500,"y":140,"wires":[["9397e0dc.6e543"]]},{"id":"25454890.bf3828","type":"signalk-input-handler","z":"f8b48a68.917e28","name":"navigation.courseOverGroundTrue","context":"vessels.self","path":"navigation.courseOverGroundTrue","source":"","x":180,"y":260,"wires":[["a638f26c.ad395"]]}]