This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm whether you accept or reject these cookies being set.

A cookie will be stored in your browser regardless of choice to prevent you being asked this question again. You will be able to change your cookie settings at any time using the link in the footer.

  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Allow NMEA 0183 file input/output
#1
I wonder if it would be possible to include "file" as a type of input or output on the KPLEX tab. I have been able to edit the kplex.conf file directly to include this type, and it shows up on the list of NMEA devices, but if I double click on it and then close, OP eliminates it from the list.

I'm trying to implement a way to convert an incoming non-checksummed NMEA string to something with a checksum. First step for me is to implement either a file or a named pipe as an output from kplex. Since it appears that it isn't persistent, I can't go much farther on that path using Openplotter.

Allowing this might also provide a means of doing NMEA logging.
  Reply
#2
(05-30-2017, 05:12 PM)abarrow Wrote: I wonder if it would be possible to include "file" as a type of input or output on the KPLEX tab. I have been able to edit the kplex.conf file directly to include this type, and it shows up on the list of NMEA devices, but if I double click on it and then close, OP eliminates it from the list.

I'm trying to implement a way to convert an incoming non-checksummed NMEA string to something with a checksum. First step for me is to implement either a file or a named pipe as an output from kplex. Since it appears that it isn't persistent, I can't go much farther on that path using Openplotter.

Allowing this might also provide a means of doing NMEA logging.

Another one which would be a small flow for node-red, I actually have a old wind sensor  which I fed through an arduino to calculate a correct checksum. 
If only I could figure out how to send NMEA sentences from node-red to kplex..............
  Reply
#3
(05-30-2017, 05:18 PM)PaddyB Wrote: Another one which would be a small flow for node-red, I actually have a old wind sensor  which I fed through an arduino to calculate a correct checksum. 
If only I could figure out how to send NMEA sentences from node-red to kplex..............

I don't suppose you could share your Arduino code? At least I wouldn't have to start from scratch!
  Reply
#4
(05-30-2017, 05:48 PM)abarrow Wrote: I don't suppose you could share your Arduino code? At least I wouldn't have to start from scratch!

Here are the 2 arduino functions which did the work..


Quote:String parseNmea(String nmeaBad)
{
  //Serial.print(nmeaBad);
  nmeaGood=nmeaBad.substring(1, nmeaBad.indexOf("*"));     //cut of the leading "$" and the bad checksum

int  CheckSum=(checkSum(nmeaGood));                //create a good checksum
  nmeaGood="$"+nmeaGood+ "*" +  String(CheckSum, HEX) + "\r\n";     // make the good nmea string

//  Serial.println(nmeaGood); 
return nmeaGood;
}


//---create a nmea checksum
char checkSum(String theseChars) {
  char check = 0;
  // iterate over the string, XOR each byte with the total sum:
  for (int c = 0; c < theseChars.length(); c++) {
    check = char(check ^ theseChars.charAt©);
  } 
  // return the result
  return check;
I was actually just having a look at node-red function but couldn't get it to work, javascript makes my head hurt :Smile
Still failing at sending an nmea sentence to kplex from node red as well. Oh well. :Smile
  Reply
#5
Thanks!
  Reply
#6
(05-30-2017, 07:09 PM)abarrow Wrote: Thanks!

OK, getting somewhere Cool

To strip the "$" off the front of the message and the "*" and chcksum from the end try a function like:-



Code:
var nmeaFull=msg.payload;

var nmeaStripped=nmeaFull.substring(1, nmeaFull.indexOf("*"));     //cut of the leading "$" and the bad checksum
msg.payload = nmeaStripped;
return msg;



Then to calculate a new checksum try a function like :-
Seems to work OK checking against http://www.hhhh.org/wiml/proj/nmeaxor.html


Code:
var nmea = msg.payload;
var checksum = 0; 

for(var i = 0; i < nmea.length; i++) { 
  checksum = checksum ^ nmea.charCodeAt(i); 
}
checksum = checksum.toString(16);    //convert to hex
nmea = '$' + nmea + '*' + checksum;  //make the full nmea sentence again

message = 'Full message =' + nmea + '\r\n' + 'Checksum = ' + checksum;
msg.payload = message;

return msg;




And the node-red code :-


Code:
[
    {
        "id": "a91ed12.b0a903",
        "type": "inject",
        "z": "d26052b1.ec666",
        "name": "",
        "topic": "",
        "payload": "$WIMDA,30,I,1.02,B,10.1,C,,C,,,,C,158.69,T,,M,3.89 ,N,2,M*37",
        "payloadType": "str",
        "repeat": "",
        "crontab": "",
        "once": false,
        "x": 150,
        "y": 720,
        "wires": [
            [
                "51fc3a3c.0d9534"
            ]
        ]
    },
    {
        "id": "51fc3a3c.0d9534",
        "type": "function",
        "z": "d26052b1.ec666",
        "name": "Strip front and back",
        "func": "var nmeaFull=msg.payload;\n\nvar nmeaStripped=nmeaFull.substring(1, nmeaFull.indexOf(\"*\"));     //cut of the leading \"$\" and the bad checksum\nmsg.payload = nmeaStripped;\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "x": 340,
        "y": 720,
        "wires": [
            [
                "6a1166f7.40d818",
                "f4310649.47dad8"
            ]
        ]
    },
    {
        "id": "6a1166f7.40d818",
        "type": "debug",
        "z": "d26052b1.ec666",
        "name": "",
        "active": true,
        "console": "false",
        "complete": "false",
        "x": 570,
        "y": 600,
        "wires": []
    },
    {
        "id": "f4310649.47dad8",
        "type": "function",
        "z": "d26052b1.ec666",
        "name": "calc checksum",
        "func": "var nmea = msg.payload;\nvar checksum = 0; \n\nfor(var i = 0; i < nmea.length; i++) { \n  checksum = checksum ^ nmea.charCodeAt(i); \n}\nchecksum = checksum.toString(16);    //convert to hex\nnmea = '$' + nmea + '*' + checksum;  //make the full nmea sentence again\n\nmessage = 'Full message =' + nmea + '\\r\\n' + 'Checksum = ' + checksum;\nmsg.payload = message;\n\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "x": 560,
        "y": 720,
        "wires": [
            [
                "6a1166f7.40d818"
            ]
        ]
    }
]



That was fun over morning coffee :Smile  Sooooooo,,, how on earth do we get that into kplex!!! 

PS - I'm not a programmer but tend use CNP (cut and paste from google Wink ) so - if any of you clever people want to point out beter ways of any tips or tricks please, please take a moment to spread the wisdom, these forums are a great place to learn, thanks Cool

YAY!!! At last, so simple - Doh!   All that was missing was a line feed. This works from node red showing up in the nmea diagnostic. Note, I had to manually edit the kplex file to create a UDP input with no address:


Code:
[udp]
name=nodered
direction=in
optional=yes
port=10108

And the node-red function needs a carriage return/ line feed added like :-

msg.payload = msg.payload+"\r\n"
But it works at last! Cool 

[Image: CpJFsbO.png]
  Reply
#7
Hello

good Solution to input/patch the NMEA Data.


But another Thing about KPLEX Config:
Why do we allways get these system_a and system_b ports with default. 
Both were INPUTS and get DATA from the same UDP-in Port 10110. 
In my Opinion one is obsolete.
  Reply
#8
(05-31-2017, 06:50 AM)holgerw Wrote: Hello

good Solution to input/patch the NMEA Data.


But another Thing about KPLEX Config:
Why do we allways get these system_a and system_b ports with default. 
Both were INPUTS and get DATA from the same UDP-in Port 10110. 
In my Opinion one is obsolete.

Not sure and don't know enough to consider going near  the delete button.....

One last thing, when node red was outputting to address = "localhost" , the address in openplotter nmea tab seemed to ned to be blank to accept the data, I've changed node red to send to address "10.10.10.1" , with openplotter set to look there it seems to work OK. 

[Image: ESNd2Dn.png]


And another tip - if you want to quickly see whats coming in a port you can use this in a terminal..

netcat -ul 10108
(port 10108)


And a quick node-red flow which creates a new NMEA message which opencpn dashboard recognises and will automatically ut into the logbook konni. Note - you need to have an input on 10.10.10.1:10108 in the nmea tab for this to work. Ta

Code:
[
   {
       "id": "a40d315e.6d623",
       "type": "udp in",
       "z": "dcf0a43.0c79158",
       "name": "",
       "iface": "",
       "port": "10110",
       "ipv": "udp4",
       "multicast": "false",
       "group": "",
       "datatype": "utf8",
       "x": 220,
       "y": 520,
       "wires": [
           [
                "983684db.178fa8",
                "4bdefe26.a6557"
            ]
       ]
   },
   {
       "id": "8f7e9341.ce0e1",
       "type": "debug",
       "z": "dcf0a43.0c79158",
       "name": "",
       "active": false,
       "console": "false",
       "complete": "false",
       "x": 1090,
       "y": 500,
       "wires": []
   },
   {
       "id": "4bdefe26.a6557",
       "type": "debug",
       "z": "dcf0a43.0c79158",
       "name": "",
       "active": false,
       "console": "false",
       "complete": "false",
       "x": 390,
       "y": 600,
       "wires": []
   },
   {
       "id": "983684db.178fa8",
       "type": "switch",
       "z": "dcf0a43.0c79158",
       "name": "Filter just pressure",
       "property": "payload",
       "propertyType": "msg",
       "rules": [
            {
                "t": "regex",
                "v": "OCMDA*",
                "vt": "str",
                "case": true
            }
        ],
       "checkall": "true",
       "outputs": 1,
       "x": 430,
       "y": 520,
       "wires": [
           [
                "85be98e1.ebdaf8"
            ]
       ]
   },
   {
       "id": "85be98e1.ebdaf8",
       "type": "function",
       "z": "dcf0a43.0c79158",
       "name": "Strip '$OC\"",
       "func": "var nmeaFull=msg.payload;\n\nvar nmea=nmeaFull.substring(6 );     //\nnmea = '$WIMDA'  +  nmea;\n\n\nmsg.payload = nmea;\nreturn msg;",
       "outputs": 1,
       "noerr": 0,
       "x": 610,
       "y": 520,
       "wires": [
           [
                "15037269.71db2e"
            ]
       ]
   },
   {
       "id": "f276f15e.2e3c6",
       "type": "udp out",
       "z": "dcf0a43.0c79158",
       "name": "",
       "addr": "10.10.10.1",
       "iface": "",
       "port": "10108",
       "ipv": "udp4",
       "outport": "",
       "base64": false,
       "multicast": "false",
       "x": 1120,
       "y": 560,
       "wires": []
   },
   {
       "id": "5d7d539b.4836dc",
       "type": "function",
       "z": "dcf0a43.0c79158",
       "name": "calc checksum",
       "func": "var nmea = msg.payload;\nvar checksum = 0; \n\nfor(var i = 0; i < nmea.length; i++) { \n  checksum = checksum ^ nmea.charCodeAt(i); \n}\nchecksum = checksum.toString(16);    //convert to hex\nnmea = '$' + nmea + '*' + checksum;  //make the full nmea sentence again\n\nmessage = 'Full message =' + nmea + '\\r\\n' + 'Checksum = ' + checksum ;\n\nmsg.payload = nmea;\nmsg.payload = msg.payload+\"\\r\\n\"\n\n\nreturn msg;",
       "outputs": 1,
       "noerr": 0,
       "x": 840,
       "y": 600,
       "wires": [
           [
                "8f7e9341.ce0e1",
                "f276f15e.2e3c6"
            ]
       ]
   },
   {
       "id": "15037269.71db2e",
       "type": "function",
       "z": "dcf0a43.0c79158",
       "name": "Strip front and back",
       "func": "var nmeaFull=msg.payload;\n\nvar nmeaStripped=nmeaFull.substring(1, nmeaFull.indexOf(\"*\"));     //cut of the leading \"$\" and the bad checksum\nmsg.payload = nmeaStripped;\nreturn msg;",
       "outputs": 1,
       "noerr": 0,
       "x": 820,
       "y": 500,
       "wires": [
           [
                "5d7d539b.4836dc"
            ]
       ]
   }
]
  Reply
#9
abarrow: edit your new settings in kplex.conf after the line "###Manual settings" and they will be persistent. If not, it is a bug.

holgerw: we need 2 UDP 10110 inputs because some tools send data to "localhost" an others send data to "127.0.0.1". Do not ask me why but kplex does not get both sources into the same place and we need 2 inputs. I think it is not fault of kplex but how raspbian manages this. This was added a few time ago and maybe this has been solved. Would need to try.
  Reply
#10
(05-31-2017, 11:58 AM)Sailoog Wrote: holgerw: we need 2 UDP 10110 inputs because some tools send data to "localhost" an others send data to "127.0.0.1". This was added a few time ago and maybe this has been solved. Would need to try.

This issure is gone: cat /etc/hosts 
127.0.0.1 localhost
::1 localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

keep on with your great development! HoW
  Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)