Example of PGN generation from Signalk paths #45
tonybentley
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
There are cases where signalk plugins will not be able to provide exact NMEA 2000 PGNs to display on Raymarine, Garmin, B&G, or other proprietary chartplotters. We can programmatically generate PGNs using Node-Red and Signalk's global application context.
The use case is for using the
environment.inside.temperature
path, which comes from a Shelly H&T IoT wifi sensor, and send the values to a Raymarine Axiom+ chartplotter via a NMEA2000 datasource connection with Signalk.The interval to send values will be different for each display, but in this example I will choose every 5 seconds using the Inject node that is provided by Node-Red.
Now that we have an interval to send updates from, we can use the function node to programmatically generate the PGN format.
Each function node represents a path from Signalk. For example, the first function node will be
environment.inside.temperature
+environment.inside.humidity
and the second will beenvironment.outside.temperature
+environment.outside.humidity
. Both of these environmental parameters use the 130311 PGN for displaying on a chartplotter.To generate the PGN object, we will use the extensive reference document that Kees Verruijt has developed for canboat. It is the library Signalk uses for NMEA 2000 parsing and creation of PGNs.
I will choose the PGN 130311 reference to define the proper keys and values for the PGN object.
For the inside temperature and humidity sources, there are lookup tables. I will choose the value that represents inside, which is 0 for humidity and 2 for temperature.
Next we will use the Signalk app global scope to access the path for each value:
And finally build the object for serializing into a NMEA 2000 PGN:
Finally, to serialize the object we will need to use the Signalk node
signalk-send-nmea2000
. Enter the valuenmea2000JsonOut
for the NMEA 2000 JSON Event andnmea2000Out
for the NMEA 2000 Event in the node configuration, which will ensure the PGN is sent to the NMEA 2000 bus.You can inspect the log entry using the Signalk Server Log page. I recommend removing all fields from the Debug input field so you can see each log entry coming from Node-Red. You should see the log coming from
node.log()
to log custom messages or turn on the switch undersignalk-server:events:nmea2000JsonOut
to see the PGN in JSON format.Once you have all three nodes, you will connect them and deploy to see it working.
In the screenshot above, I have one node for inside, and another for outside.
Happy coding!
Beta Was this translation helpful? Give feedback.
All reactions