antipole2 / JavaScript_pi

JavaScript plugin for OpenCPN
GNU General Public License v3.0
2 stars 4 forks source link

Receiving Signal K #73

Open antipole2 opened 11 months ago

antipole2 commented 11 months ago

It is desirable that the JavaScript plugin can be used to work with Signal K. Given the close relationship of both Signal K and JavaScript with JSON, this should be relatively easy to do and to use.

I do not have a Signal K set up and am away from my boat for the winter. So I am hoping SKS will work with me to establish this capability.

Receiving Signal K messages This should be possible with the existing JavaScript plugin release by using OCPN messaging. In future, it would be preferable to use the new streams interface but I think that is not yet complete in OCPN.

The following script should (not tested) receive three Signal K messages, parse them into a Javascript structure and then pretty -print them. Please someone copy the output to me.

// Listen out for SignalK messages and display
count = 3;  // number of messages to listen for
OCPNonMessageName(received, "OCPN_CORE_SIGNALK");

function received(message){
    signalK = JSON.parse(message);
    print(JSON.stringify(signalK, null, "\t"), "\n\n");     // pretty-print message
    if (--count > 0) OCPNonMessageName(received, "OCPN_CORE_SIGNALK");
    }
Rasbats commented 10 months ago

Running openplotter on RPi using feed from OpenCPN/ShipDriver. Local network with another instance of OpenCPN on Windows. This app using JScript_pi:

{
    "context": "vessels.urn:mrn:signalk:uuid:80eb056e-1b7a-4302-9c1a-96c05ba0e4d8",
    "updates": [
        {
            "source": {
                "talker": "II",
                "label": "opencpn",
                "sentence": "GLL",
                "type": "NMEA0183"
            },
            "$source": "opencpn.II",
            "timestamp": "2023-11-13T13:39:36.000Z",
            "values": [
                {
                    "path": "navigation.position",
                    "value": {
                        "latitude": 49.71504957,
                        "longitude": -3.5839755
                    }
                }
            ]
        }
    ]
}{
    "context": "vessels.urn:mrn:signalk:uuid:80eb056e-1b7a-4302-9c1a-96c05ba0e4d8",
    "updates": [
        {
            "source": {
                "talker": "II",
                "label": "opencpn",
                "sentence": "VTG",
                "type": "NMEA0183"
            },
            "$source": "opencpn.II",
            "timestamp": "2023-11-13T12:51:05.808Z",
            "values": [
                {
                    "path": "navigation.courseOverGroundMagnetic",
                    "value": null
                },
                {
                    "path": "navigation.courseOverGroundTrue",
                    "value": 1.221730477
                },
                {
                    "path": "navigation.speedOverGround",
                    "value": 0
                }
            ]
        }
    ]
}{
    "context": "vessels.urn:mrn:signalk:uuid:80eb056e-1b7a-4302-9c1a-96c05ba0e4d8",
    "updates": [
        {
            "source": {
                "talker": "II",
                "label": "opencpn",
                "sentence": "VHW",
                "type": "NMEA0183"
            },
            "$source": "opencpn.II",
            "timestamp": "2023-11-13T12:51:05.814Z",
            "values": [
                {
                    "path": "navigation.headingTrue",
                    "value": 1.221730477
                },
                {
                    "path": "navigation.speedThroughWater",
                    "value": 5.658890322
                }
            ]
        }
    ]
}result: undefined
antipole2 commented 10 months ago

In the next update to the User Guide JavaScript_plugin_user_guide- SK.pdf