When data comes in from both SignalK and gpsd how do I proritize SignalK?

In my boat I get the position both from SignalK and from gpsd, and the SignalK data from the plotter is much more accurate than the cheap USB GPS mouse I have. The main function of that is so that I can see wher the boat is when the main power is off. I format the data the way I want it and send it to Home Assistant, which is the front end for the system. How do I go about only sending the SignalK data as long as that comes in, but switch to the gpsd data when there is no data from SignalK?

I would use a trigger node as a watchdog. As long as the SignalK value is updated regularly, the watchdog will not fire any message. If the watchdog triggers a message, you know that the SignalK value failed and you can switch to the gpsd value

[{"id":"9fa5a3f33a1ca488","type":"inject","z":"99bbfbdd.2d4768","name":"SignalK","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"SignalK","payload":"","payloadType":"date","x":170,"y":1440,"wires":[["bcd797625e319a6d","c11613e6467c19c4","fec823665031f34f"]]},{"id":"ad934b4cde759923","type":"inject","z":"99bbfbdd.2d4768","name":"gpsd","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"gpsd","payload":"","payloadType":"date","x":170,"y":1500,"wires":[["fec823665031f34f"]]},{"id":"bcd797625e319a6d","type":"trigger","z":"99bbfbdd.2d4768","name":"","op1":"","op2":"true","op1type":"nul","op2type":"bool","duration":"10","extend":true,"overrideDelay":false,"units":"s","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":470,"y":1380,"wires":[["396694a79a5cc639"]]},{"id":"d34115d7062f1dc2","type":"debug","z":"99bbfbdd.2d4768","name":"debug 13","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":640,"y":1480,"wires":[]},{"id":"396694a79a5cc639","type":"change","z":"99bbfbdd.2d4768","name":"gpssource -> gpsd","rules":[{"t":"set","p":"gpssource","pt":"flow","to":"gpsd","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":670,"y":1380,"wires":[[]]},{"id":"c11613e6467c19c4","type":"change","z":"99bbfbdd.2d4768","name":"gpssource -> SignalK","rules":[{"t":"set","p":"gpssource","pt":"flow","to":"SignalK","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":680,"y":1440,"wires":[[]]},{"id":"fec823665031f34f","type":"switch","z":"99bbfbdd.2d4768","name":"","property":"topic","propertyType":"msg","rules":[{"t":"eq","v":"gpssource","vt":"flow"}],"checkall":"true","repair":false,"outputs":1,"x":450,"y":1480,"wires":[["d34115d7062f1dc2"]]}]
2 Likes

Thank you! I have put in the code, and it works on manual trigger, so that should work on the GPS trigger to. I don't understand how it works, but that doesn't matter. :grin:

Yes it does matter. How can you maintain a system if you don't understand how it works? Ask about the bits you don't understand (after looking at the help text for the node that you don't understand). To help you work it out you can add debug nodes to see what is going on.

I respetcfully disagree, I don't have to understand what every bit do. I'll ask if I need to change something and don't know how. My system is full of bits and pieces in Lua, Python, YAML and HTML that are more advanced than my brain can understand, but they have all been doing their job. Some of them for more than 20 years (Girder LUA coding from around 2000).

I suppose it depends on whether you are just putting together a simple system for a task and are happy for volunteers here to spend their time telling you how to do it, or if you want to learn about the tool so the next time you need to make a change you are less likely to have to ask for help.

I understand that I have stepped on a toe here, but 90 % of the stuff I have I both understand and have done myself, it's the few remaining precents that I don't get, and when I have tried an hour or two without getting anywhere I ask somebody who uses maybe two minutes to put together what I'm wondering about.

In the example I assume that SignalK sends a new position every x seconds (x < 10s).
Every time the position from SignalK is received, the Change node named "gpssource -> SignalK" sets the flow variable "gpssource" to the value "SignalK".

If there is 10s no new message from SignalK received, the Trigger node sends a message to the subsequent Change node "gpssource -> gpsd". This node sets the flow variable named "gpssource" to the value "gpsd".

In the Switch variable the Topic from the received message (either "SignalK" or "gpsd") will be compared to the current value of the variable "gpssource". Only if it matches, the value will forwarded.

Example:

00m:00s 
Message from SignalK is received --> "gpssource" is set to "SignalK" --> the message is forwarded to the Debug node

00m:01s
Message from gpsd is received --> the message is not  forwarded to the Debug node, as gpssource is set to "SignalK" and not to "gpsd"

00m:10s
SignalK does not send any message for 10s --> "gpssource" is set to "gpsd"

00m:11s
Message from gpsd is received --> the message is forwarded to the Debug node, as "gpssource" is now "gpsd"

00m:12s 
Message from SignalK is received --> "gpssource" is set to "SignalK" --> the message is forwarded to the Debug node

00m:13s
Message from gpsd is received --> the message is not  forwarded to the Debug node, as gpssource is set to "SignalK" and not to "gpsd"

and so on...

This is not perfect, but maybe you get an idea how to solve your problem :wink:

1 Like

Thanks for the explanation! :slight_smile: It already has, it's working perfectly in my system! :+1:

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