Closed micwik closed 4 years ago
Thanks for reporting this. Can you provide debug or logged data from SignalK log (Enable Debug and maybe also Logging)? It could give a hint what vessel and what parameter is undefined.
I have seen that some AIS transponders do not send all parameters correctly or some parts are missing and therefore parsing operation has been halted with that error. Therefore it would be great if you could provide info, which variable is causing the error at this time. I haven't seen that problem for a long time, but that doesn't mean anything.
Below is the link to parsing part of the code and as you can see if some strings are undefined then value is set to null, except callSign, which was causing troubles earlier. Some variable might need to be other than null if undefined to get rid of this error. https://github.com/KEGustafsson/signalk-vessels-to-ais/blob/master/index.js#L129
What was your quickfix to code? Was it to GG-AisEncode.js code?
I tried some logging and added to following code (pointed by You):
try { var ais = jsonContent[jsonKey].sensors.ais.class.value;} catch (error) {ais = null;}; console.log ('Parse name=%s', name); // Added log-line
Log: Aug 06 23:58:37 Parse name=undefined Aug 06 23:58:37 Parse name=undefined Aug 06 23:58:37 Parse name=STENSKAR Aug 06 23:58:37 2020-08-06T21:58:37.285Z signalk-vessels-to-ais class A 3 Aug 06 23:58:37 2020-08-06T21:58:37.292Z signalk-vessels-to-ais !AIVDM,1,1,,A,33v4@@00000l@RJQCrpW74ap0000,0*35 Aug 06 23:58:37 PutStr string= start=70 len=42 Aug 06 23:58:37 PutStr string=STENSKAR start=112 len=120 Aug 06 23:58:37 PutStr string=0 start=302 len=120
The last one is causing the problem.
I repeat Quickfix in GG-AisEncode.js:
// console.log ('PutStr string=%s start=%d len=%d', string, start, len);
if (string === undefined) return; // nothing garantie that will have a valid string if (string == 0) return; // Quickfix to avoid error string=string.toUpperCase();
// Michael W
Thanks! Now I got it. I need to figure out a good logic to check that name is valid (can be changed to upper case), not a number before passing it to forward. I cannot do changes to GG-AisEncode.js like your quickfix, but there are alternative ways. I just need to figure out a good one.
If you have programming skills and willingness to do a PR, then I welcome all help.
Can you try index.js from https://github.com/KEGustafsson/signalk-vessels-to-ais/tree/upperCase? Following variable (name, navStat, commonName.value and aisShipType.value.name) are changed from null to "" if not present. Can you test if this fix is working for you? Just copy index.js over the old one and remove your quickfix. Thanks!
Hi!
I was just about to try Your code. I'm currently traveling at the sweden west coast and has been able to reproduce the error at every harbour we wisited so far. But now (in Hunnebostrand) I don't get the error, so I can't check if your new code give the expected correction. I will look for the error every day and check Your code as soon as possible.
Best Regards Michael W
Now I am in a new harbour (Fjällbacka) and got the error, so I tried Your code. Sorry to say, it doesn't seem to remove the error. I have kept my quick-fix, but I can see in the log that the error (string=0) is still present.
Aug 10 23:03:59 2020-08-10T21:03:59.268Z signalk-vessels-to-ais !AIVDM,1,1,,A,H3uAtT4U0000000000000000;110,023 Aug 10 23:03:59 2020-08-10T21:03:59.269Z signalk-vessels-to-ais class A 3 Aug 10 23:03:59 2020-08-10T21:03:59.270Z signalk-vessels-to-ais !AIVDM,1,1,,A,33uI;i00000kWptQQn=`ciAp0000,048
Aug 10 23:03:59 PutStr string= start=70 len=42 Aug 10 23:03:59 PutStr string=RESCUE LEIF JOHANSON start=112 len=120 Aug 10 23:03:59 PutStr string=0 start=302 len=120 Aug 10 23:03:59 2020-08-10T21:03:59.274Z signalk-vessels-to-ais !AIVDM,1,1,,A,53uI;i40000000000018E<=DF0hDTJ0`tP4q<tpk00<2200000000000000000000000000,059 Aug 10 23:03:59 2020-08-10T21:03:59.275Z signalk-vessels-to-ais class A 4 Aug 10 23:03:59 2020-08-10T21:03:59.276Z signalk-vessels-to-ais !AIVDM,1,1,,A,33uOkNP0000kWv6QQnT@001p0000,02E Aug 10 23:03:59 PutStr string= start=70 len=42 Aug 10 23:03:59 PutStr string=RESCUE BERITH start=112 len=120 Aug 10 23:03:59 PutStr string=0 start=302 len=120
As seen in the log, the error here comes in 2 different log positions. This behaviour of 2 errors has repeated it self in this session for at least a couple of updates (which is 1 minute apart).
I was just thinking if the error is due to a false unexpected call of the function where the error apears.
Best Regards Michael W
Ok. I was not sure if this could be the cure. It seems not. Can you send me a screen capture what SignalK vessels are showing for these problematics vessels. I think I need to implement somehow your quickfix to code if some AIS tranponders are sendind erratic data that parser cannot handle.
I havn't forgot it ... I've put some debugging into the calling of the failing routine. As I'm on a trip it's sometimes hard to find the time for this debugging and also the problem has not been present on the last 2 harbours so I haven't seen the result of my debug code. I keep looking for more information to pass to You.
Now I got some result :-) I added debug to this code in GG-AisEncode.js:
console.log ('Call PutStr 1c'); this.PutStr(msg.destination,302,120);
I got the error in following log (look for "string=0"): log1.txt
Hi Michael,
Now I had time to dig in to this issue. Please try if this fix is now curing the issue. Here are the changes to index.js code: https://github.com/KEGustafsson/signalk-vessels-to-ais/commit/5c560bd62dec95fc92dacfa4aadb30a128b54dc1
I added test if string is integer, then value is replaced with "". If I force listed variables to have numeric value, then I get the error. After this fix I don't get error anymore.
@micwik Hi Michael, Have you had a change to test latest fix?
Hi,
I finally have some "smoking gun" evidence that Your fix works. This logging was done earlier today.
Before the fix:
Sep 19 13:50:46 Call PutStr 1a Sep 19 13:50:46 PutStr string= start=70 len=42 Sep 19 13:50:46 Call PutStr 1b Sep 19 13:50:46 PutStr string=LYRON start=112 len=120 Sep 19 13:50:46 Call PutStr 1c Sep 19 13:50:46 PutStr string=0 start=302 len=120
After the fix:
Sep 19 13:55:56 Call PutStr 1a Sep 19 13:55:56 PutStr string= start=70 len=42 Sep 19 13:55:56 Call PutStr 1b Sep 19 13:55:56 PutStr string=LYRON start=112 len=120 Sep 19 13:55:56 Call PutStr 1c Sep 19 13:55:56 PutStr string= start=302 len=120
So I believe this is my last comment on this issue. Good work.
Best regards Michael W
Thanks Michael! I'll merge the fix to master and push update to npm.
Hi!
I got following error at a certain receiving situation: TypeError:` string.toUpperCase is not a function at AisEncode.PutStr This resulted in that a majority of the ships never got reported and the error line was ending up in the server log.
In this file: .signalk/node_modules/signalk-vessels-to-ais/node_modules/ggencoder/lib/GG-AisEncode.js
I traced the problem to line about 261. The variable string contained the value 0 (numeric) for some reason. I made a quickfix that bails out for the 0 value. This seemes to solve the problem, but I don't have a real deep understanding of the code.
// console.log ('PutStr string=%s start=%d len=%d', string, start, len); if (string === undefined) return; // nothing garantie that will have a valid string if (string == 0) return; // Quickfix to avoid error string=string.toUpperCase();
Best regards Michael Wiklund