Skybolt - I am dipping my feet in the plugin wa...

I am dipping my feet in the plugin waters. Coming from Microsoft things are quite different in the linux world. Anyway, I have followed the documentation and and have a shell created and registered and although it does nothing right now it is running. My question is how do you get any sort of debug log going and where is it located?
43 Replies
Skybolt
SkyboltOP3w ago
I am running from a terminal and start SK like this: DEBUG=signalk-maretron-vmm6 signalk-server
Scott Bender
Scott Bender3w ago
Use app.debug(), and turn on the debug setting in the plugin options
Skybolt
SkyboltOP3w ago
Also I have app.debug statements in the index.js code. but nothing is in hte terminal.
Scott Bender
Scott Bender3w ago
Those will show in the “Server Log” in the admin console And show in the system log file. (That location depends on what Linux distribution/version) you are using.
Skybolt
SkyboltOP3w ago
Yeah, nothing showing up anywhere it seems. I have this at the top - const debug = require('debug')('app'); and then app.debug("xxx"); but nothing.
Scott Bender
Scott Bender3w ago
No. Use app.debug You don’t need that require
Skybolt
SkyboltOP3w ago
I am running on r-pi bookworm I tried that before I put that there. but let me try again. When you say admin log, thats the server log under server?
Scott Bender
Scott Bender3w ago
Yes And sounds like you are running the server by hand?
Skybolt
SkyboltOP3w ago
I have tried it different ways. Only from the terminal because the log gets dumped there. A little easier at this point. I disabled the services to run SK.
Scott Bender
Scott Bender3w ago
Then your debug logs will show in the terminal Make sure you turn on debug in the Plugin Options You don’t need the DEBUG in your command line
Skybolt
SkyboltOP3w ago
Right, that's what I thought and why I am running from the terminal at this point. Still nothing there. But at least I now know it is supposed to show up there. Thanks.
Skybolt
SkyboltOP3w ago
No description
Scott Bender
Scott Bender3w ago
Sounds like your debug statement is not getting executed
Skybolt
SkyboltOP3w ago
Yeah looks that way. That's why I had to ask these q's.
Scott Bender
Scott Bender3w ago
I can take a look at you code if you want...
Skybolt
SkyboltOP3w ago
Let me get it a bit further along and I definetly will take you up on that. Thanks again Scott! BTW, I am over in the Kent Narrows. Small world.
Scott Bender
Scott Bender3w ago
Oh cool. I am on the Magothy
Skybolt
SkyboltOP3w ago
Nice area we live in huh? 😀
Scott Bender
Scott Bender3w ago
indeed!
Skybolt
SkyboltOP3w ago
Love it here on the bay. Have a great day, I'll be back.
Scott Bender
Scott Bender3w ago
you too!
Skybolt
SkyboltOP3w ago
Question on eventing on a specific PGN? I am using subscribe/subscriptionmanager in start from the documentation. But is there anyway of subscribing to an actual path so that when that path's value changes I catch it? Right now it it is hit or miss it seems.
Scott Bender
Scott Bender3w ago
That’s exactly what subscriptionmanager does What’s your subscription look like?
Skybolt
SkyboltOP3w ago
I probably need to narrow it down to only the bank and switch I am looking at. Ok need to switch from this chrome book. Ok trying again. This is the first part of the start: let localSubscription = { context: 'vessels.self', subscribe: [{ path: electrical.switches.bank.*, period: 1000 }]}
Scott Bender
Scott Bender3w ago
Looks good
Skybolt
SkyboltOP3w ago
This is the subscription manager: app.subscriptionmanager.subscribe( localSubscription, unsubscribes, (subscriptionError) => { app.error('Error:' + subscriptionError) }, (delta) => { delta.updates.forEach((update) => { if (update.values) { update.values.forEach((value) => { const path = value.path; const key = ${path}.${update.$source};
if (path.endsWith('state')) { //app.debug(Switch Path: ${path});
//electrical.switches.bank.14.12.state let switchPGN = path.split('.'); let instance = Number(switchPGN[3]); let switchNum = Number(switchPGN[4]); let sval = value.value; if (instance == 14 && switchNum==1 ) app.debug(Switch Value: ${instance}.${switchNum} = ${sval}); } ` that app.debug doesn't pick up allof th eswitch changes.
Scott Bender
Scott Bender3w ago
I could see you missing switches if they are happened more than once a second You can set that period to 1ms in that case
Skybolt
SkyboltOP3w ago
I am trying to write a plugin that will work with the Maretron VMM switch series. But it doesn't follow N2K standards. It uses PGN127501 and uses the status in pairs. Meanng switch 1 uses status bits 1 and 2. Status switch 2 uses 3 and 4. they are set in the off state as bit 1 = 0 and bit 2 =1 then when on they flip, bit 1=1 and bit 2 = 0. So you think I need to set the period to 500ms?
Scott Bender
Scott Bender3w ago
you can do 1ms
Skybolt
SkyboltOP3w ago
wow, ok. I was afraid of looking the thread. locking*
Scott Bender
Scott Bender3w ago
Updates will only come as fast as they sent Did you look at the n2k-switching plugin?
Skybolt
SkyboltOP3w ago
ok, good to know. Thanks. I am a beginner with signalk programming. But not programming.
Scott Bender
Scott Bender3w ago
There’s some Maretron support there I think that may already be doing what you are trying to do?
Skybolt
SkyboltOP3w ago
Yes, but only for the actual relay devices
Scott Bender
Scott Bender3w ago
ok
Skybolt
SkyboltOP3w ago
It seems only 126208 is used by the plug in's. And this switch manipulates only 127501 with 2 bits, status 1 and 2 and so on.
Scott Bender
Scott Bender3w ago
Now that I think of it, I assume that is sending out periodic updates, you really should not be missing anything if they follow the spec… oops, the spec does not say how often it should be sent.
Skybolt
SkyboltOP3w ago
It does send out periodic updates, about once a second. But 127501 only. It uses 127501 to toggle the switch as well, in a very non standard way. Non of their products use 127502, except the MConnect, it can toggle standard N2K switching. I worked with them to add that.
Skybolt
SkyboltOP3w ago
Is there a way to register a plugin without the manual npm link statement's so it will survive an update reboot?
Scott Bender
Scott Bender3w ago
do “npm pack” That will give you a .tar.gz Then in ~/.signalk npm install /path/to/my.tar.gz Once you do that, you can npm link again and it will survive updates Make sure you leave that .tar.gz where you installed it from
Skybolt
SkyboltOP3w ago
Perfect! Thank you. This was tested on an R-Pi 5, the boat has a 4 so need to make sure the period isn't too fast for the subscribe. Thank you again Scott!
Scott Bender
Scott Bender3w ago
If this was something like gps location, then the period would probably be overkill. But in this case, your data is not updating that fast. So if you set the period to 100ms but the data updates every second, you will only get updates every second.
Skybolt
SkyboltOP3w ago
I thought the same and 100ms was my first move. Didn't catch everything so I tried 50ms, Then landed on 25ms. 50ms may be alright. I still need to try this in a real N2K network. I spent the weekend changing oil and winterizing. Hopefully can try this out later in the week. The VMM6 does update every second, but it will also update on any change. So pressing switches quickly, as you might while the boat is running, things can get lost.

Did you find this page helpful?