SK
Signal K6mo ago
lari

lari - @Scott Bender : In regards to signalk-n2...

@Scott Bender : In regards to signalk-n2k-switching-emulator plugin, am I able to control n2k switch with a PUT request against the signalk path, such as this (that comes via PGN 127501)? "electrical.switches.bank.1.1.state" I'm asking because KIP doesn't seem to get a valid response, but instead: "Toggle Widget Switch Panel Label: Did not receive change confirmation"
64 Replies
lari
lariOP6mo ago
ah okay so the response for put request is "PENDING"...
Scott Bender
Scott Bender6mo ago
You don’t mean the emulator plugin, right? n2k-switching? Do you have the latest KIP? I think there was a fix related to this.
lari
lariOP6mo ago
I do think I have the latest KIP maybe it's about my n2k device, lemme verify that first in node-red 😛
Scott Bender
Scott Bender6mo ago
Which n2k adapter are you using? And make sure your Data Connection is using canboatjs, not canboat
lari
lariOP6mo ago
I'm using canboatjs and receiving data just fine
Scott Bender
Scott Bender6mo ago
n2k adaptor?
lari
lariOP6mo ago
If I remember correctly, it's the one from Waveshare 2 channel, isolated so must be with mcp2515 controller
Scott Bender
Scott Bender6mo ago
Ok. That should work fine. (It’s what I use) You’re not using the emulator plugin, right?
lari
lariOP6mo ago
I'm trying to use the emulator, yes
Scott Bender
Scott Bender6mo ago
I don’t think you want that
lari
lariOP6mo ago
because without it, KIP informed that the path does not support PUT
Scott Bender
Scott Bender6mo ago
You need signalk-n2k-switching
lari
lariOP6mo ago
then I thought that maybe because it's a n2k-based path, it might not support put at all
Scott Bender
Scott Bender6mo ago
The emulator emulates an n2k switching devices. But you have real n2k switching hardware, right?
lari
lariOP6mo ago
actually I was wrong about the plugin
lari
lariOP6mo ago
No description
lari
lariOP6mo ago
yea so I've got a custom (rather experimental) n2k device listening to 127501 https://github.com/plektra/vega-n2k-node1/blob/main/src/main.cpp#L215-L232
Scott Bender
Scott Bender6mo ago
After the plugin sends the request to switch, It waits to see a message from n2k device showing the new state
lari
lariOP6mo ago
yea, seems that it's not receiving anything which could reflect the fact of a defect in my n2k device 😛
Scott Bender
Scott Bender6mo ago
It’s just looking at the path in sk, so you can check by looking in data browser.
lari
lariOP6mo ago
sure it's sending data just fine
Scott Bender
Scott Bender6mo ago
But when you switch on, does the state change to 1 there?
lari
lariOP6mo ago
nope 😛
Scott Bender
Scott Bender6mo ago
You code looks good at a high level, you send out the status after switching.
lari
lariOP6mo ago
is there a way to track the individual request
Scott Bender
Scott Bender6mo ago
You can get some more info by turning on debug for the that plugin. You can also turn on debug for signalk-server:put
lari
lariOP6mo ago
Sep 06 13:17:04 2024-09-06T13:17:04.377Z signalk-n2k-switching setting electrical.switches.bank.1.1.state to 1
Sep 06 13:17:04 2024-09-06T13:17:04.403Z signalk-n2k-switching sending {"pgn":127502,"dst":255,"Switch Bank Instance":1,"Instance":1,"Switch1":"Off"}
Sep 06 13:17:04 PUT /signalk/v1/api/vessels/self/electrical.switches.bank.1.1.state 202 46.846 ms - 245
Sep 06 13:17:05 2024-09-06T13:17:05.407Z signalk-n2k-switching checking electrical.switches.bank.1.1.state {"meta":{},"value":0,"$source":"1.1","timestamp":"2024-09-06T13:17:04.576Z","pgn":127501} should be 0
Sep 06 13:17:05 2024-09-06T13:17:05.409Z signalk-n2k-switching SUCCESS
Sep 06 13:17:04 2024-09-06T13:17:04.377Z signalk-n2k-switching setting electrical.switches.bank.1.1.state to 1
Sep 06 13:17:04 2024-09-06T13:17:04.403Z signalk-n2k-switching sending {"pgn":127502,"dst":255,"Switch Bank Instance":1,"Instance":1,"Switch1":"Off"}
Sep 06 13:17:04 PUT /signalk/v1/api/vessels/self/electrical.switches.bank.1.1.state 202 46.846 ms - 245
Sep 06 13:17:05 2024-09-06T13:17:05.407Z signalk-n2k-switching checking electrical.switches.bank.1.1.state {"meta":{},"value":0,"$source":"1.1","timestamp":"2024-09-06T13:17:04.576Z","pgn":127501} should be 0
Sep 06 13:17:05 2024-09-06T13:17:05.409Z signalk-n2k-switching SUCCESS
Scott Bender
Scott Bender6mo ago
Yeah, so your device is not sending out an update showing the switch off wait That looks like it worked The path does show that it is off And SUCCESS
lari
lariOP6mo ago
but I'm trying to turn 0 -> 1
Scott Bender
Scott Bender6mo ago
Hmm. But you can see it’s sending “Off” So why is KIP sending off? Let me double check with KIP here…
lari
lariOP6mo ago
well actually I was calling sk api directly with curl in this case sending PUT with .... -d '{"value": "1"}' "http://vuosaari:8080/signalk/v1/api/vessels/self/electrical.switches.bank.1.1.state"
Scott Bender
Scott Bender6mo ago
Oh. Don’t put the 1 in quotes
lari
lariOP6mo ago
doesn't help without
Scott Bender
Scott Bender6mo ago
Let’s see the debug log without it
lari
lariOP6mo ago
Sep 06 13:26:21 2024-09-06T13:26:21.514Z signalk-n2k-switching setting electrical.switches.bank.1.1.state to 1
Sep 06 13:26:21 2024-09-06T13:26:21.541Z signalk-n2k-switching sending {"pgn":127502,"dst":255,"Switch Bank Instance":1,"Instance":1,"Switch1":"On"}
Sep 06 13:26:21 PUT /signalk/v1/api/vessels/self/electrical.switches.bank.1.1.state 202 49.773 ms - 245
Sep 06 13:26:22 2024-09-06T13:26:22.545Z signalk-n2k-switching checking electrical.switches.bank.1.1.state {"meta":{},"value":0,"$source":"1.1","timestamp":"2024-09-06T13:26:19.581Z","pgn":127501} should be 1
Sep 06 13:26:23 2024-09-06T13:26:23.545Z signalk-n2k-switching checking electrical.switches.bank.1.1.state {"meta":{},"value":0,"$source":"1.1","timestamp":"2024-09-06T13:26:22.688Z","pgn":127501} should be 1
Sep 06 13:26:24 2024-09-06T13:26:24.545Z signalk-n2k-switching checking electrical.switches.bank.1.1.state {"meta":{},"value":0,"$source":"1.1","timestamp":"2024-09-06T13:26:22.688Z","pgn":127501} should be 1
Sep 06 13:26:25 2024-09-06T13:26:25.546Z signalk-n2k-switching checking electrical.switches.bank.1.1.state {"meta":{},"value":0,"$source":"1.1","timestamp":"2024-09-06T13:26:25.188Z","pgn":127501} should be 1
Sep 06 13:26:26 2024-09-06T13:26:26.547Z signalk-n2k-switching checking electrical.switches.bank.1.1.state {"meta":{},"value":0,"$source":"1.1","timestamp":"2024-09-06T13:26:25.188Z","pgn":127501} should be 1
Sep 06 13:26:27 2024-09-06T13:26:27.547Z signalk-n2k-switching checking electrical.switches.bank.1.1.state {"meta":{},"value":0,"$source":"1.1","timestamp":"2024-09-06T13:26:25.188Z","pgn":127501} should be 1
Sep 06 13:26:28 2024-09-06T13:26:28.548Z signalk-n2k-switching checking electrical.switches.bank.1.1.state {"meta":{},"value":0,"$source":"1.1","timestamp":"2024-09-06T13:26:27.688Z","pgn":127501} should be 1
Sep 06 13:26:21 2024-09-06T13:26:21.514Z signalk-n2k-switching setting electrical.switches.bank.1.1.state to 1
Sep 06 13:26:21 2024-09-06T13:26:21.541Z signalk-n2k-switching sending {"pgn":127502,"dst":255,"Switch Bank Instance":1,"Instance":1,"Switch1":"On"}
Sep 06 13:26:21 PUT /signalk/v1/api/vessels/self/electrical.switches.bank.1.1.state 202 49.773 ms - 245
Sep 06 13:26:22 2024-09-06T13:26:22.545Z signalk-n2k-switching checking electrical.switches.bank.1.1.state {"meta":{},"value":0,"$source":"1.1","timestamp":"2024-09-06T13:26:19.581Z","pgn":127501} should be 1
Sep 06 13:26:23 2024-09-06T13:26:23.545Z signalk-n2k-switching checking electrical.switches.bank.1.1.state {"meta":{},"value":0,"$source":"1.1","timestamp":"2024-09-06T13:26:22.688Z","pgn":127501} should be 1
Sep 06 13:26:24 2024-09-06T13:26:24.545Z signalk-n2k-switching checking electrical.switches.bank.1.1.state {"meta":{},"value":0,"$source":"1.1","timestamp":"2024-09-06T13:26:22.688Z","pgn":127501} should be 1
Sep 06 13:26:25 2024-09-06T13:26:25.546Z signalk-n2k-switching checking electrical.switches.bank.1.1.state {"meta":{},"value":0,"$source":"1.1","timestamp":"2024-09-06T13:26:25.188Z","pgn":127501} should be 1
Sep 06 13:26:26 2024-09-06T13:26:26.547Z signalk-n2k-switching checking electrical.switches.bank.1.1.state {"meta":{},"value":0,"$source":"1.1","timestamp":"2024-09-06T13:26:25.188Z","pgn":127501} should be 1
Sep 06 13:26:27 2024-09-06T13:26:27.547Z signalk-n2k-switching checking electrical.switches.bank.1.1.state {"meta":{},"value":0,"$source":"1.1","timestamp":"2024-09-06T13:26:25.188Z","pgn":127501} should be 1
Sep 06 13:26:28 2024-09-06T13:26:28.548Z signalk-n2k-switching checking electrical.switches.bank.1.1.state {"meta":{},"value":0,"$source":"1.1","timestamp":"2024-09-06T13:26:27.688Z","pgn":127501} should be 1
ok have to give some attention to the baby, BBL and thanks so far
Scott Bender
Scott Bender6mo ago
Ok, so no update was sent by the device to confirm that it is on. Oh. You’re not listening for the correct pgn on the device. 127502 Looks like you are listening for 127501
lari
lariOP6mo ago
oh hmm 127502 for receiving, right?
Scott Bender
Scott Bender6mo ago
Yes
lari
lariOP6mo ago
ok cool, let's see if my OTA still works after years 🙂 topic for another thread btw, but running KIP in same browser session with Signal-K server admin console seems to mess up the session if I'm trying to stay logged in with admin user in sk-server and another user in KIP signalk-server seems to think I'm logged in as kip user in the admin console too
Scott Bender
Scott Bender6mo ago
Yes, they use the same auth info. It’s a COOKIE.
lari
lariOP6mo ago
sure
Scott Bender
Scott Bender6mo ago
There may be a way to deal with it in Kip, but I doubt it. You might want to ask on #kip
lari
lariOP6mo ago
what was the format of the payload for sending nmea2000 messages in node-red? Mind sharing an example as I've lost my notes... :/
Scott Bender
Scott Bender6mo ago
It’s the canboat json format You trying to send 127502? I can give you an example
lari
lariOP6mo ago
well I've got a pgn for triggering a reboot on the node/device for OTA update an empty message to 61200 should be fine
Scott Bender
Scott Bender6mo ago
there's no support for 61200 in canboat this might work:
lari
lariOP6mo ago
oh hmm, it's been a few years and can't remember how did I send the message then other than from node-red using the embedded stuff maybe from command line then
Scott Bender
Scott Bender6mo ago
2018-05-03T19:00:00.526Z,7,61200,4,255,8,ff,ff,ff,ff,ff,ff,ff,ff where 255 is the device src/id
lari
lariOP6mo ago
umm stupid question, but can I use canboatjs to send that over to the bus? never actually sent raw messages
Scott Bender
Scott Bender6mo ago
Use can use node-red, or if you have the 2.9.0+ of the server, you can send it in the Data Fidler
lari
lariOP6mo ago
ah nice njah, probably misconfigured wifi credentials on the device EEPROM, as OTA update doesn't work anymore ;_; well anyways I think I know what to do next, so thanks a lot Scott!
Scott Bender
Scott Bender6mo ago
Welcome
lari
lariOP6mo ago
I can't find anywhere an example of a node-red canboat json formatted payload for sending nmea2000 sentences, any tips?
Scott Bender
Scott Bender6mo ago
You can send a string like I pasted above or for known pgns
{
"pgn": 127502,
"dst": 123,
"Instance": 1,
"Switch1": "On"
}
{
"pgn": 127502,
"dst": 123,
"Instance": 1,
"Switch1": "On"
}
Scott Bender
Scott Bender6mo ago
GitHub
canboatjs/test/pgns at master · canboat/canboatjs
Native javascript NMEA 2000 decoder and encoder. Contribute to canboat/canboatjs development by creating an account on GitHub.
lari
lariOP6mo ago
cool thanks
Scott Bender
Scott Bender6mo ago
lari
lariOP6mo ago
yea ofc the pgn needs to be configured in canboat in order to use the json format
Scott Bender
Scott Bender6mo ago
yep the string format can be used otherwise 2018-05-03T19:00:00.526Z,7,61200,4,255,8,ff,ff,ff,ff,ff,ff,ff,ff
lari
lariOP6mo ago
been a while, but I think I added some custom code for that earlier for my custom pgn but can't find it anywhere anymore FYI I was able to change the switch state from Off to On using 127501 due to my bug in the node config (listening to 127501 for changes) so it's somewhat working I'm just not able to update the code on the esp32 OTA right now so need to go on site to fix it
Scott Bender
Scott Bender6mo ago
You could implement a put in node-red with a different path. Then that would work in Kip.
lari
lariOP6mo ago
not worth it I guess Highly leaning towards setting up any new custom devices with n2k but instead with wifi + signalk communication I mean NOT setting up n2k devices
Scott Bender
Scott Bender6mo ago
I would do the same
lari
lariOP6mo ago
my only worry has been wifi so I just need to get over it the thought has been strong about having everything in copper in order to provide stability

Did you find this page helpful?