I am new to Signal-K and Node-Red, so please excuse me if this is obvious to more experienced users. I have a Victron Cerbo running Signal-K and Node-Red. I have ultrasonic fluid transducers that provide highly varying level readings. I want to smooth the data and send out a level of the data over the past 30 seconds using a different instance. So here's what I've done:
Subscribe to tanks.freshWater.1.currentLevel (which outputs every 2.5 seconds)
Feed that into a smooth function which outputs every 12 results (every 30 seconds)
Feed the output of the smooth into a function that contains:
If you feed the output of your function into a debug node do you see what you expect?
Is that the complete function you have posted? If so then level is undefined and that should show with a red line under it to tell you there is a problem
Sorry, I thought that I had copied the entire function code. Here's the missing line at the top:
var level = msg.payload;
I do feed it into a debug node, and the output of the debug node is precisely as expected.
Once again, I suspect that my TANK_TYPE is in error, but that may be completely wrong. How do I find out what valid TANK_TYPE values are? Alternately, does signalk-send-nmea2000 return an error that I can view?
To answer my own questions, here are the issues that I was dealing with. I ended up resolving this by reading the PGN 127505 SignalK code.
I thought that the Instance field was 8 bits. It's not. It's 4 bits, so the instance has to be between 0 & 15. I was using 102 and it was returning 0.
The Type field is an enumerated field, and the list of valid entries in the SignalK specification doesn't match what the code uses. The actual values are "Fuel", 'Water", "Gray water", "Live well", "Oil", and "Black water". If what you supply doesn't match, it returns 0, which is "Water".
So all along it was outputting values for Water with an instance of 0, which matched what the actual sensor was sending.